save demag_orient.txt
        (only the columns that appear on the grid frame)
545586
def on_m_save_file(self,event):

        '''
        
        '''
        fout = open(os.path.join(self.WD, "demag_orient.txt"), 'w')
        STR = "tab\tdemag_orient\n"
        fout.write(STR)
        headers = [header[0] for header in self.headers]
        STR = "\t".join(headers) + "\n"
        fout.write(STR)
        for sample in self.samples_list:
            STR = ""
            for header in headers:
                sample_index = self.samples_list.index(sample)
                i = headers.index(header)
                value = self.grid.GetCellValue(sample_index, i)
                STR = STR + value + "\t"
            fout.write(STR[:-1] + "\n")
        if event != None:
            dlg1 = wx.MessageDialog(None,caption="Message:", message="data saved in file demag_orient.txt" ,style=wx.OK|wx.ICON_INFORMATION)
            dlg1.ShowModal()
            dlg1.Destroy()
241556
function header(columns, opt, repeat, nodisplay){
  var headers = Object.keys(columns);
  var widths = headers.map(head => columns[head]);
  var topl = opt.title ? p[1][0] : p[0][0];
  var topr = opt.title ? p[1][2] : p[0][2];
  var topc = repeat ? p[1][1] : p[0][1];
  log(topl + widths.map(col => p.h + strN(col, p.h) + p.h).join(topc) + topr);
  if (!nodisplay) {
    log(p.v + ' ' + headers.map((txt, i) => fixed(txt, widths[i])).join(' ' + p.v + ' ') + ' ' + p.v);
    log(p[1][0] + widths.map(col => p.h + strN(col, p.h) + p.h).join(p[1][1]) + p[1][2]);
  }
}
604169
def _make_grid_of_axes(self,
                           bounding_rect=cfg.bounding_rect_default,
                           num_rows=cfg.num_rows_per_view_default,
                           num_cols=cfg.num_cols_grid_default,
                           axis_pad=cfg.axis_pad_default,
                           commn_annot=None,
                           **axis_kwargs):
        """"""

        axes_in_grid = list()
        extents = self._compute_cell_extents_grid(bounding_rect=bounding_rect,
                                                  num_cols=num_cols,
                                                  num_rows=num_rows, axis_pad=axis_pad)
        for cell_ext in extents:
            ax_cell = self.fig.add_axes(cell_ext, frameon=False, visible=False,
                                        **axis_kwargs)
            if commn_annot is not None:
                ax_cell.set_title(commn_annot)
            ax_cell.set_axis_off()
            axes_in_grid.append(ax_cell)

        return axes_in_grid
307737
def save_frames(obj, filename, fmt=None, backend=None, options=None):
    
    backend = Store.current_backend if backend is None else backend
    renderer = Store.renderers[backend]
    fmt = renderer.params('fig').objects[0] if fmt is None else fmt
    plot = renderer.get_plot(obj)
    for i in range(len(plot)):
        plot.update(i)
        renderer.save(plot, '%s_%s' % (filename, i), fmt=fmt, options=options)
466989
def __write_filter_dic(wk_sheet, column):
    '''
    
    '''
    row1_val = wk_sheet['{0}1'.format(column)].value
    row2_val = wk_sheet['{0}2'.format(column)].value
    row3_val = wk_sheet['{0}3'.format(column)].value
    row4_val = wk_sheet['{0}4'.format(column)].value

    if row1_val and row1_val.strip() != '':
        row2_val = row2_val.strip()

        slug_name = row1_val.strip()
        c_name = row2_val.strip()

        tags1 = [x.strip() for x in row3_val.split(',')]
        tags_dic = {}

        #  if only one tag,
        if len(tags1) == 1:
            xx_1 = row2_val.split(':')  # 'text'  # HTML text input control.

            if xx_1[0].lower() in INPUT_ARR:
                xx_1[0] = xx_1[0].lower()
            else:
                xx_1[0] = 'text'

            if len(xx_1) == 2:
                ctr_type, unit = xx_1
            else:
                ctr_type = xx_1[0]
                unit = ''
            tags_dic[1] = unit

        else:
            ctr_type = 'select'  # HTML selectiom control.
            for index, tag_val in enumerate(tags1):
                # the index of tags_dic starts from 1.
                tags_dic[index + 1] = tag_val.strip()

        outkey = 'html_{0}'.format(slug_name)
        outval = {
            'en': slug_name,
            'zh': c_name,
            'dic': tags_dic,
            'type': ctr_type,
            'display': row4_val,
        }
        return (outkey, outval)
    else:
        return (None, None)
1212135
def _get_mvar(cls, df, column, windows):
        
        window = cls.get_only_one_positive_int(windows)
        column_name = '{}_{}_mvar'.format(column, window)
        df[column_name] = df[column].rolling(
            min_periods=1, window=window, center=False).var()
310416
def _saveModel(self):
        
        delimiter = self._delimiterBox.currentSelected()
        header = self._headerCheckBox.isChecked() # column labels
        if self._filename is None:
            filename = self._filenameLineEdit.text()
        else:
            filename = self._filename
        ext = os.path.splitext(filename)[1].lower()
        index = False # row labels

        encodingIndex = self._encodingComboBox.currentIndex()
        encoding = self._encodingComboBox.itemText(encodingIndex)
        encoding = _calculateEncodingKey(encoding.lower())

        try:
            dataFrame = self._model.dataFrame()
        except AttributeError as err:
            raise AttributeError('No data loaded to export.')
        else:
            print("Identifying export type for {}".format(filename))
            try:
                if ext in ['.txt','.csv']:
                    dataFrame.to_csv(filename, encoding=encoding, header=header, index=index, sep=delimiter)
                elif ext == '.tsv':
                    sep = '\t'
                    dataFrame.to_csv(filename, encoding=encoding, header=header, index=index, sep=delimiter)
                elif ext in ['.xlsx','.xls']:
                    dataFrame.to_excel(filename, encoding=encoding, header=header, index=index, sep=delimiter)
            except IOError as err:
                raise IOError('No filename given')
            except UnicodeError as err:
                raise UnicodeError('Could not encode all data. Choose a different encoding')
            except Exception:
                raise
            self.signalExportFilenames.emit(self._model._filePath, filename)
527246
def strip_columns(tab):
    """"""
    for colname in tab.colnames:
        if tab[colname].dtype.kind in ['S', 'U']:
            tab[colname] = np.core.defchararray.strip(tab[colname])
1343720
def __view_to_selected_graphics(self, data_and_metadata: DataAndMetadata.DataAndMetadata) -> None:
        """"""
        all_graphics = self.__graphics
        graphics = [graphic for graphic_index, graphic in enumerate(all_graphics) if self.__graphic_selection.contains(graphic_index)]
        intervals = list()
        for graphic in graphics:
            if isinstance(graphic, Graphics.IntervalGraphic):
                intervals.append(graphic.interval)
        self.__view_to_intervals(data_and_metadata, intervals)
1124247
function collectHeaderSpans(oColumn, index, aCols) {
			var colSpan = TableUtils.Column.getHeaderSpan(oColumn, iRow),
				iColIndex;

			if (nSpan < 1) {
				if (colSpan > 1) {
					// In case when a user makes some of the underlying columns invisible, adjust colspan
					iColIndex = oColumn.getIndex();
					colSpan = aCols.slice(index + 1, index + colSpan).reduce(function(span, column){
						return column.getIndex() - iColIndex < colSpan ? span + 1 : span;
					}, 1);
				}

				oColumn._nSpan = nSpan = colSpan;
				iLastVisibleCol = index;
			} else {
				//Render column header but this is invisible because of the previous span
				oColumn._nSpan = 0;
			}
			nSpan--;
		}
1166904
def OnInsertCols(self, event):
        """"""

        bbox = self.grid.selection.get_bbox()

        if bbox is None or bbox[1][1] is None:
            # Insert rows at cursor
            ins_point = self.grid.actions.cursor[1] - 1
            no_cols = 1
        else:
            # Insert at right edge of bounding box
            ins_point = bbox[0][1] - 1
            no_cols = self._get_no_rowscols(bbox)[1]

        with undo.group(_("Insert columns")):
            self.grid.actions.insert_cols(ins_point, no_cols)

        self.grid.GetTable().ResetView()

        # Update the default sized cell sizes
        self.grid.actions.zoom()

        event.Skip()
389069
def convert_sed_cols(tab):
    """"""
    # Update Column names
    for colname in list(tab.columns.keys()):

        newname = colname.lower()
        newname = newname.replace('dfde', 'dnde')

        if tab.columns[colname].name == newname:
            continue

        tab.columns[colname].name = newname

    return tab
147832
function getGridOffsets(directions, grid, opt) {

        var step = opt.step;

        util.toArray(opt.directions).forEach(function(direction) {

            direction.gridOffsetX = (direction.offsetX / step) * grid.x;
            direction.gridOffsetY = (direction.offsetY / step) * grid.y;
        });
    }
847995
def show_grid_from_file(self, fname):
        
        with open(fname, "r") as f:
            for y, row in enumerate(f):
                for x, val in enumerate(row):
                    self.draw_cell(y, x, val)
1153564
def on_btn_orientation(self, event):
        
        wait = wx.BusyInfo('Compiling required data, please wait...')
        wx.SafeYield()
        #dw, dh = wx.DisplaySize()
        size = wx.DisplaySize()
        size = (size[0]-0.1 * size[0], size[1]-0.1 * size[1])
        if self.data_model_num == 3:
            frame = pmag_gui_dialogs.OrientFrameGrid3(self, -1, 'demag_orient.txt',
                                                        self.WD, self.contribution,
                                                        size)
        else:
            frame = pmag_gui_dialogs.OrientFrameGrid(self, -1, 'demag_orient.txt',
                                                        self.WD, self.er_magic, size)
        frame.Show(True)
        frame.Centre()
        self.Hide()
        del wait
1049980
def to_column_format(self, high_density_vertical=True):
        
        im = self._im.transpose(Image.ROTATE_270).transpose(Image.FLIP_LEFT_RIGHT)
        line_height = 24 if high_density_vertical else 8
        width_pixels, height_pixels = im.size
        top = 0
        left = 0
        while left < width_pixels:
            box = (left, top, left + line_height, top + height_pixels)
            im_slice = im.transform((line_height, height_pixels), Image.EXTENT, box)
            im_bytes = im_slice.tobytes()
            yield(im_bytes)
            left += line_height
1191323
function (columns) {
        var i, j, k,
            totalCol = 0,
            flag = [];

        for (i = 0; i < columns[0].length; i++) {
            totalCol += columns[0][i].colspan || 1;
        }

        for (i = 0; i < columns.length; i++) {
            flag[i] = [];
            for (j = 0; j < totalCol; j++) {
                flag[i][j] = false;
            }
        }

        for (i = 0; i < columns.length; i++) {
            for (j = 0; j < columns[i].length; j++) {
                var r = columns[i][j],
                    rowspan = r.rowspan || 1,
                    colspan = r.colspan || 1,
                    index = $.inArray(false, flag[i]);

                if (colspan === 1) {
                    r.fieldIndex = index;
                    // when field is undefined, use index instead
                    if (typeof r.field === 'undefined') {
                        r.field = index;
                    }
                }

                for (k = 0; k < rowspan; k++) {
                    flag[i + k][index] = true;
                }
                for (k = 0; k < colspan; k++) {
                    flag[i][index + k] = true;
                }
            }
        }
    }