class createTable(tk.Frame): def __init__(self, master=None): tk.Frame.__init__(self, master) self.place(x=0, y=100, relwidth=1, relheight=1) # self.grid() self.F = tk.Frame(self) self.F.grid(sticky=tk.N + tk.S + tk.W) # self.F.place(x=10,y=10) self.createWidgets() def createWidgets(self): self.table = TableCanvas(self.F, rows=0, cols=0, width=350, height=150, editable=False, cellwidth=175) self.table.createTableFrame() data = database.get_data_file(username1) print data if len(data) != 0: for i in range(len(data)): for j in range(2): if j == 0: data_1 = data[i][j] if j == 1: data_2 = data[i][j] keyname = "rec" + str(i) self.table.addRow( keyname, **{ 'Name of File': data_2, 'Date of created': data_1 }) self.table.redrawTable() else: keyname = "1" data_2 = "no file in storage" self.table.addRow( keyname, **{ 'Name of File': data_2, 'Date of created': data_2 }) self.table.redrawTable()
model = table.model model.importDict(data) #can import from a dictionary to populate model table.redrawTable() #by column name raw_input('Sort table by column name') table.sortTable(columnName='label') #by column index raw_input('Sort table by column index') table.sortTable(columnIndex=1) raw_input('Add automatic key row') #add with automatic key table.addRow() raw_input('Add row with new key name') #add with named key, other keyword arguments are interpreted as column values keyname = 'rec5' table.addRow(keyname, label='abc') raw_input('Add column') colname = 'new column' table.addColumn(colname) raw_input('Remove row') #delete rows table.deleteRow() raw_input('Put value in (2,3) cell...')
class TelemetryPanel(observer.Observer): ''' This panel is a table of currently observed telemetry channels. ''' def __init__(self, parent, top, opt): ''' Constructor ''' self.__parent = parent self.__top = top self.__opt = opt config = ConfigManager.ConfigManager.getInstance() # Period to delay between table refreshes self.__update_period = config.get('performance', 'telem_table_update_period') # # Status updater singleton # self.__status_update = status_updater.StatusUpdater.getInstance() # # Instance the channel loader here and get all channel names # self.__channel_loader = channel_loader.ChannelLoader.getInstance() self.__channel_names_list = self.__channel_loader.getNameDict().values( ) self.__channel_names_dict = self.__channel_loader.getNameDict() num_channels = len(self.__channel_loader.getNameDict()) # # Container Frame f = Tkinter.Frame(parent) f.pack(side=Tkinter.TOP, anchor=Tkinter.N, fill=Tkinter.BOTH, expand=1) # # Create a model and connect it to a table on a canvas # self.__model = TableModel() self.__table = TableCanvas(f, model=self.__model, width=1200, height=800) # Set font font = config.get('tables', 'font') font_size = config.get('tables', 'font_size') self.__table.thefont = (font, font_size) self.__table.rowheight = int(font_size) + 5 self.__table.createTableFrame() self.__table.redrawTable() # Mouse movement causes flyover text. This is not needed. # Unbind the appropriate event handler self.__table.unbind('<Motion>') # # Init. the table with a standard set of column headers # data = {'1': {'Channel': None}} self.__model.importDict( data) # can import from a dictionary to populate model self.__table.addColumn('Id') self.__table.addColumn('Time') self.__table.addColumn('Value') for i in range(2, num_channels + 1): self.__table.addRow("%s" % i) self.__table.align = 'w' self.__table.redrawTable() self.__table.maxcellwidth = 500 # Remove Row and cell highlight color self.__table.rowselectedcolor = None self.__table.selectedcolor = None # Rebind <B1-Motion> event to catch exception from column resize error self.__table.tablecolheader.unbind('<B1-Motion') self.__table.tablecolheader.bind('<B1-Motion>', self.__handle_column_motion) self.__table.tablecolheader.unbind('<ButtonRelease-1>') self.__table.tablecolheader.bind('<ButtonRelease-1>', self.__handle_column_release) # Make table read only self.__table.editable = False # # Pop-up Channel Telemetry Filter Selection and Active Filter Status. # f2 = Tkinter.LabelFrame(f, text="Channel Telemetry Filtering:", padx=5, pady=5) f2.grid(row=2, column=0, columnspan=4, sticky=Tkinter.W + Tkinter.E) # b1 = Tkinter.Button(f2, text="Select Channels", command=self.__select) b1.pack(side=Tkinter.LEFT) # Hex value toggle self.__print_hex = Tkinter.IntVar() self.__print_hex.set(0) self.__hex_cb = Tkinter.Checkbutton(f2, text="Show Hex", variable=self.__print_hex, pady=5) self.__hex_cb.pack(side=Tkinter.RIGHT) # self.__e1 = Pmw.ScrolledField(f2, labelpos=Tkinter.W, labelmargin=0, text="None") self.__e1.pack(side=Tkinter.LEFT, expand=1, fill=Tkinter.X) self.__e1.component('entry').config(width=60) self.__e1.component('label').config(text='Active Filter Selected:') # # This is a channel id key to row value dictionary # built up over runtime to update table. # self.__row_dict = dict() self.__row_max = 1 # # List of active channels to display self.__channel_names_list.sort() self.__channels_active_list = self.__channel_names_list self.__inactive_channels = [] def __handle_column_motion(self, event): """ Used to rebind the table's ColumnHeader <B1-Motion> event. """ try: self.__table.tablecolheader.handle_mouse_drag(event) except ValueError, e: pass