def __init__(self, table_name, attributes, model_structure): # Non-widget data self.set_attributes = {} self.model_structure = model_structure self.current_action = actions.table['None'] self.table_name = table_name glade_window.GladeWindow.__init__(self, 'NewEntryWindow.glade') # Handle the window itself self.window = self.connect_widget_by_name('wdwNewEntry', 'destroy', lambda x: gtk.main_quit()) self.window.set_title('Add New ' + table_name) self.window.set_resizable(False) # Create the master Vertical Box self.master_vbox = gtk.VBox() references = self.model_structure.get_table_by_name(self.table_name).references for attribute in attributes: hbox, label, entry = gtk.HBox(), gtk.Label(), gtk.Entry() label.set_text(data_formatters.camel_to_readable(attribute.name) + ':') for widget in [label, entry]: hbox.add(widget) if attribute.acceptable_values != None: cmb = gtk.combo_box_new_text() for value in attribute.acceptable_values: cmb.append_text(str(value)) self.set_attributes[attribute] = attribute.acceptable_values[0] cmb.set_active(0) cmb.set_visible(True) hbox.add(cmb) cmb.connect('changed', self.selects_different_value, attribute) hbox.remove(entry) elif attribute.name in references: btn_browse = gtk.Button('Browse') btn_clear = gtk.Button('Clear') btn_browse.connect('clicked', self.browse_for_id, attribute.name, entry) btn_clear.connect('clicked', self.clear_id, attribute.name, entry) entry.set_editable(False) hbox.add(btn_browse) hbox.add(btn_clear) else: hbox.add(label) hbox.add(entry) self.set_attributes[attribute] = '' entry.connect('changed', self.attribute_changed, attribute) self.master_vbox.add(hbox) self.last_hbox = gtk.HBox() self.btn_save = self.connect_new_button('Save', self.save_data) self.btn_cancel = self.connect_new_button('Cancel', lambda x: gtk.main_quit()) self.last_hbox.add(self.btn_save) self.last_hbox.add(self.btn_cancel) self.master_vbox.add(self.last_hbox) self.window.add(self.master_vbox) self.window.show_all()
def add_table_data(self, table_data): """ Adds all necessary table data to the window. Ought to be used before displaying. """ # Create a table to later pack with entries self.table = gtk.Table() # Loop through the headers and add them to the first row of the table for index in range(table_data.number_of_attributes): button = gtk.Button(str(data_formatters.camel_to_readable(str(table_data.header[index])))) button.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('yellow')) self.table.attach(button, index, index + 1, 0, 1) for t in range(table_data.number_of_tuples): temp_list = [] for a in range(table_data.number_of_attributes): button = gtk.Button(str(table_data.data[t][a])) temp_list.append(str(table_data.data[t][a])) self.table.attach(button, a, a + 1, t + 1, t + 2) button.connect('clicked', self.change_highlighted, t) self.text_view.append(', '.join(temp_list)) self.scw_table_case.add_with_viewport(self.table)
def test_data_formatters_performs_as_expected_for_a_given_set_of_data(self): self.assertEqual(data_formatters.camel_to_readable('TableName'), 'Table Name') self.assertEqual(data_formatters.camel_to_readable('TableNameOrId', False), 'Table Name Or Id') self.assertEqual(data_formatters.camel_to_readable('TableNameOrId', True), 'Table Name Or') self.assertEqual(data_formatters.camel_to_readable('Foo'), 'Foo')