kopia lustrzana https://github.com/ctjacobs/pyqso
commit
1e5a657ca7
|
@ -1025,39 +1025,59 @@ class Logbook(Gtk.Notebook):
|
|||
return
|
||||
log = self.logs[log_index]
|
||||
|
||||
dialog = RecordDialog(parent=self.parent, log=log, index=None)
|
||||
all_valid = False # Are all the field entries valid?
|
||||
|
||||
# Keep the dialog open after adding a record?
|
||||
config = configparser.ConfigParser()
|
||||
have_config = (config.read(expanduser('~/.config/pyqso/preferences.ini')) != [])
|
||||
(section, option) = ("general", "keep_open")
|
||||
if(have_config and config.has_option(section, option)):
|
||||
keep_open = config.get("general", "keep_open") == "True"
|
||||
else:
|
||||
keep_open = False
|
||||
adif = ADIF()
|
||||
while(not all_valid):
|
||||
# This while loop gives the user infinite attempts at giving valid data.
|
||||
# The add/edit record window will stay open until the user gives valid data,
|
||||
# or until the Cancel button is clicked.
|
||||
all_valid = True
|
||||
response = dialog.run()
|
||||
if(response == Gtk.ResponseType.OK):
|
||||
fields_and_data = {}
|
||||
field_names = AVAILABLE_FIELD_NAMES_ORDERED
|
||||
for i in range(0, len(field_names)):
|
||||
# Validate user input.
|
||||
fields_and_data[field_names[i]] = dialog.get_data(field_names[i])
|
||||
if(not(adif.is_valid(field_names[i], fields_and_data[field_names[i]], AVAILABLE_FIELD_NAMES_TYPES[field_names[i]]))):
|
||||
# Data is not valid - inform the user.
|
||||
error(parent=self.parent, message="The data in field \"%s\" is not valid!" % field_names[i])
|
||||
all_valid = False
|
||||
break # Don't check the other data until the user has fixed the current one.
|
||||
|
||||
if(all_valid):
|
||||
# All data has been validated, so we can go ahead and add the new record.
|
||||
log.add_record(fields_and_data)
|
||||
self.update_summary()
|
||||
self.parent.toolbox.awards.count()
|
||||
# Select the new Record's row in the treeview.
|
||||
number_of_records = log.get_number_of_records()
|
||||
if(number_of_records is not None):
|
||||
self.treeselection[log_index].select_path(number_of_records)
|
||||
exit = False
|
||||
while not exit:
|
||||
dialog = RecordDialog(parent=self.parent, log=log, index=None)
|
||||
|
||||
all_valid = False # Are all the field entries valid?
|
||||
|
||||
# Shall we exit the while loop (and therefore close the Add Record dialog)?
|
||||
if keep_open:
|
||||
exit = False
|
||||
else:
|
||||
exit = True
|
||||
|
||||
while not all_valid:
|
||||
# This while loop gives the user infinite attempts at giving valid data.
|
||||
# The add/edit record window will stay open until the user gives valid data,
|
||||
# or until the Cancel button is clicked.
|
||||
all_valid = True
|
||||
response = dialog.run()
|
||||
if(response == Gtk.ResponseType.OK):
|
||||
fields_and_data = {}
|
||||
field_names = AVAILABLE_FIELD_NAMES_ORDERED
|
||||
for i in range(0, len(field_names)):
|
||||
# Validate user input.
|
||||
fields_and_data[field_names[i]] = dialog.get_data(field_names[i])
|
||||
if(not(adif.is_valid(field_names[i], fields_and_data[field_names[i]], AVAILABLE_FIELD_NAMES_TYPES[field_names[i]]))):
|
||||
# Data is not valid - inform the user.
|
||||
error(parent=self.parent, message="The data in field \"%s\" is not valid!" % field_names[i])
|
||||
all_valid = False
|
||||
break # Don't check the other data until the user has fixed the current one.
|
||||
|
||||
dialog.destroy()
|
||||
if(all_valid):
|
||||
# All data has been validated, so we can go ahead and add the new record.
|
||||
log.add_record(fields_and_data)
|
||||
self.update_summary()
|
||||
self.parent.toolbox.awards.count()
|
||||
# Select the new Record's row in the treeview.
|
||||
number_of_records = log.get_number_of_records()
|
||||
if(number_of_records is not None):
|
||||
self.treeselection[log_index].select_path(number_of_records)
|
||||
else:
|
||||
exit = True
|
||||
break
|
||||
dialog.destroy()
|
||||
return
|
||||
|
||||
def delete_record_callback(self, widget):
|
||||
|
|
|
@ -125,7 +125,7 @@ class GeneralPage(Gtk.VBox):
|
|||
|
||||
self.sources = {}
|
||||
|
||||
|
||||
# Startup
|
||||
frame = Gtk.Frame()
|
||||
frame.set_label("Startup")
|
||||
|
||||
|
@ -144,7 +144,7 @@ class GeneralPage(Gtk.VBox):
|
|||
|
||||
# Show statistics
|
||||
hbox = Gtk.HBox()
|
||||
self.sources["SHOW_YEARLY_STATISTICS"] = Gtk.CheckButton("Show yearly logbook statistics on the Summary page.")
|
||||
self.sources["SHOW_YEARLY_STATISTICS"] = Gtk.CheckButton("Show yearly logbook statistics on the Summary page")
|
||||
(section, option) = ("general", "show_yearly_statistics")
|
||||
if(have_config and config.has_option(section, option)):
|
||||
self.sources["SHOW_YEARLY_STATISTICS"].set_active(config.get(section, option) == "True")
|
||||
|
@ -154,7 +154,26 @@ class GeneralPage(Gtk.VBox):
|
|||
vbox.pack_start(hbox, False, False, 2)
|
||||
|
||||
frame.add(vbox)
|
||||
self.pack_start(frame, False, False, 2)
|
||||
|
||||
# Dialogs
|
||||
frame = Gtk.Frame()
|
||||
frame.set_label("Dialogs")
|
||||
|
||||
vbox = Gtk.VBox()
|
||||
|
||||
# Keep 'Add Record' dialog open
|
||||
hbox = Gtk.HBox()
|
||||
self.sources["KEEP_OPEN"] = Gtk.CheckButton("Keep the Add Record dialog open")
|
||||
(section, option) = ("general", "keep_open")
|
||||
if(have_config and config.has_option(section, option)):
|
||||
self.sources["KEEP_OPEN"].set_active(config.get(section, option) == "True")
|
||||
else:
|
||||
self.sources["KEEP_OPEN"].set_active(False)
|
||||
hbox.pack_start(self.sources["KEEP_OPEN"], False, False, 2)
|
||||
vbox.pack_start(hbox, False, False, 2)
|
||||
|
||||
frame.add(vbox)
|
||||
self.pack_start(frame, False, False, 2)
|
||||
|
||||
logging.debug("General page of the preferences dialog ready!")
|
||||
|
@ -165,6 +184,7 @@ class GeneralPage(Gtk.VBox):
|
|||
data = {}
|
||||
data["SHOW_TOOLBOX"] = self.sources["SHOW_TOOLBOX"].get_active()
|
||||
data["SHOW_YEARLY_STATISTICS"] = self.sources["SHOW_YEARLY_STATISTICS"].get_active()
|
||||
data["KEEP_OPEN"] = self.sources["KEEP_OPEN"].get_active()
|
||||
return data
|
||||
|
||||
class ViewPage(Gtk.VBox):
|
||||
|
|
Ładowanie…
Reference in New Issue