Enable/disable the data entry panel as required.

pull/17/head
Christian Jacobs 2013-03-23 22:41:06 +00:00
rodzic 742e256f0c
commit 9fa283ce28
3 zmienionych plików z 23 dodań i 10 usunięć

Wyświetl plik

@ -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)

Wyświetl plik

@ -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

Wyświetl plik

@ -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!