def load_table(name, external=False, sep=','): ''' This function loads a csv file to into a Qtable ''' # Here we're just finding the delimiters in case someone # wants tab separation or whatever other crazy formats # someone might try to stuff through here. Note: Autodetecting # the delimiter with sniffer does not work very well for online # csv files, at least how I tried it. So I guess we can write this: # TODO: figure out how to make csv.sniffer work well with online files # so we can autodetect the delimiters. # Probably not the best way of doing this... extension = name.split(".")[-1] if extension != 'csv': print("The file " + name + " needs to be a .csv file to load properly") return # The tables made by the QtableWidget have a little bit of a different # format that caouses the index to be topsy-turvy as compared to regular # csv files, this flag prevents us from accidentally using data as an index try: if not external: df = pd.read_csv(name, index_col=0, sep=sep) if external: df = pd.read_csv(name, sep=sep) except FileNotFoundError: print("Cannot find the file " + name + ", please check that the path is correct.") return return qgrid.QgridWidget(df=df, show_toolbar=True)
def show_df(df=None): if not isinstance(df, DataFrame): return None grid_options = { 'fullWidthRows': True, 'syncColumnCellResize': True, 'forceFitColumns': False, 'defaultColumnWidth': 150, 'rowHeight': 28, 'enableColumnReorder': False, 'enableTextSelectionOnCells': True, 'editable': True, 'autoEdit': True, 'explicitInitialization': True, 'maxVisibleRows': 15, 'minVisibleRows': 8, 'sortable': True, 'filterable': True, 'highlightSelectedCell': False, 'highlightSelectedRow': True } qgrid_widget = qgrid.QgridWidget(df=df, grid_options=grid_options, show_toolbar=True) return qgrid_widget
def ask_parts(registry, qgrid_plasmids): print( textwrap.dedent(""" Use the selector to choose which parts to use in each plasmid. Parts are sorted by YTK type. When finished, run the next cell. """)) # Extract user plasmids IDs and names df_plasmids = qgrid_plasmids.get_changed_df() names = {row["id"]: row["name"] for _, row in df_plasmids.iterrows()} # Input parts dataframe types = { re.search("YTKPart(.*)", cls.__name__).group(1): cls for cls in ytk.YTKPart.__subclasses__() } # Create a small selected with part ID and name # for each possible part parts = {} for colname, part_type in types.items(): categories = { "{} - {}".format(p.entity.record.id, p.entity.record.description) for p in registry.values() if isinstance(p.entity, part_type) } parts[colname] = pandas.Categorical([""] * len(names), categories=[""] + sorted(categories)) # Create the dataframe df_parts = pandas.DataFrame(parts) df_parts["id"] = df_plasmids["id"] df_parts["name"] = df_plasmids["name"] qgrid_parts = qgrid.QgridWidget(df=df_parts, show_toolbar=False) display(qgrid_parts) return qgrid_parts
def ask_plasmids(): print( textwrap.dedent(""" Fill the table with as many plasmids as desired, using the "Add Row" button to add more rows. When finished, run the next cell. """)) df_plasmids = pandas.DataFrame({"id": ["psXXX"], "name": ["plasmid_name"]}) qgrid_plasmids = qgrid.QgridWidget(df=df_plasmids, show_toolbar=True) display(qgrid_plasmids) return qgrid_plasmids
def _inputScreen(self): self.dfInput = pd.DataFrame({ 'Notional Amount': [self.notional_amount], 'Term in Months': [self.term_in_tenor], 'APR': [self.annual_percentage_rate], 'Repayment Day': [self.repayment_day], 'Effective Date': [self.effective_date] }) self.dfInputQG = qgrid.QgridWidget(df=self.dfInput, show_toolbar=False) tab_content = ['Loan Details'] children = [self.dfInputQG] tab = widgets.Tab() tab.children = children for i in range(len(children)): tab.set_title(i, str(tab_content[i])) self.input = tab
def table_for_figure(df, fig): df_stacked = df.stack() df_stacked = pd.DataFrame({ 'values': df_stacked, 'checked': [False for i in range(len(df_stacked))] }) df_stacked = df_stacked[['values', 'checked']] qgrid_widget = qgrid.QgridWidget(df=df_stacked, show_toolbar=True) pos = [] def onclick(event): x = int(round(event.xdata)) y = int(round(event.ydata)) pos.append([x, y]) qgrid_widget.df = sort_by_x_y(df_stacked, x, y) fig.canvas.mpl_connect('button_press_event', onclick) return qgrid_widget
def interactive_df_open(self, itype='all', numeric=False, verbosity=0): toolbar = True if itype is 'all': toolbar = False elif itype is 'formations': toolbar = False elif itype is 'faults': toolbar = False elif itype is 'faults_relations': toolbar = False if not toolbar: warnings.warn('for this itype Add Row does not work. If needed try using interfaces or orientations' 'instead') df_ = self.get_data(itype=itype, verbosity=verbosity) self.qgrid_widget = qgrid.QgridWidget(df=df_, show_toolbar=toolbar) return self.qgrid_widget
def getcorrections(toadjust, to_correct='to_correct', corrected='corrected'): cc = pd.DataFrame(toadjust) cc.columns = ['to_correct'] cc['corrected'] = '' qgrid_widget = qgrid.QgridWidget(df=cc) return qgrid_widget