diff --git a/src/data_entry_panel.py b/src/data_entry_panel.py index e47153f..294b3ca 100644 --- a/src/data_entry_panel.py +++ b/src/data_entry_panel.py @@ -30,8 +30,8 @@ class DataEntryPanel(Gtk.VBox): Gtk.VBox.__init__(self, spacing=2) + # Create label:entry pairs and store them in a dictionary self.sources = {} - field_names = parent.logbook.SELECTED_FIELD_NAMES_TYPES.keys() for i in range(0, len(field_names)): hbox_temp = Gtk.HBox(spacing=2) @@ -40,27 +40,27 @@ class DataEntryPanel(Gtk.VBox): hbox_temp.pack_start(self.sources[field_names[i]], True, True, 0) self.pack_start(hbox_temp, False, False, 0) - self.store = Gtk.Button("Store Data") - self.store.connect("clicked", parent.edit_record_callback) - self.pack_start(self.store, expand=False, fill=True, padding=2) + self.update = Gtk.Button("Update Record") + self.update.connect("clicked", parent.update_record_callback) + self.pack_start(self.update, expand=False, fill=True, padding=2) hbox_parent.pack_start(self, False, False, 0) return def enable(self): - # Activates all text boxes and the "Store data" button + # Activates all text boxes and the update button keys = self.sources.keys() for i in range(0, len(keys)): self.sources[keys[i]].set_property("editable", True) self.sources[keys[i]].set_can_focus(True) - self.store.set_sensitive(True) + self.update.set_sensitive(True) def disable(self): - # Deactivates all text boxes and the "Store data" button + # Deactivates all text boxes and the update button keys = self.sources.keys() for i in range(0, len(keys)): self.sources[keys[i]].set_property("editable", False) self.sources[keys[i]].set_can_focus(False) - self.store.set_sensitive(False) + self.update.set_sensitive(False) diff --git a/src/logbook.py b/src/logbook.py index db2c1f8..81b1607 100644 --- a/src/logbook.py +++ b/src/logbook.py @@ -132,6 +132,9 @@ class Logbook(Gtk.ListStore): self.remove(iter) self.check_consistency() return + + def get_number_of_records(self): + return len(self.records) def check_consistency(self): # Make sure all the record indices are consecutive and diff --git a/src/pyqso.py b/src/pyqso.py index 16e42f8..b12f9f7 100644 --- a/src/pyqso.py +++ b/src/pyqso.py @@ -44,7 +44,7 @@ class PyQSO(Gtk.Window): vbox_outer = Gtk.VBox() self.add(vbox_outer) - # Create a new Logbook so we can add/remove/edit Record objects + # Create a Logbook so we can add/remove/edit Record objects self.logbook = Logbook() # Set up menu bar and populate it @@ -90,6 +90,12 @@ class PyQSO(Gtk.Window): def add_record_callback(self, widget): self.logbook.add_record() + self.data_entry_panel.enable() + + # The current row is now the new Record's row. + selection = self.treeview.get_selection() + selection.select_path(self.logbook.get_number_of_records()-1) + return def delete_record_callback(self, widget): @@ -112,9 +118,13 @@ class PyQSO(Gtk.Window): self.logbook.delete_record(iter, index) dialog.destroy() + + if(self.logbook.get_number_of_records() == 0): + self.data_entry_panel.disable() + return - def edit_record_callback(self, widget): + def update_record_callback(self, widget): #TODO: Validate user input!