kopia lustrzana https://github.com/ctjacobs/pyqso
Move the new/open/save log methods to the Logbook class.
rodzic
6c3f917355
commit
c3a674e373
|
@ -21,40 +21,30 @@
|
|||
from gi.repository import Gtk, GObject
|
||||
import logging
|
||||
|
||||
from adif import AVAILABLE_FIELD_NAMES_TYPES
|
||||
|
||||
class DataEntryPanel(Gtk.VBox):
|
||||
|
||||
def __init__(self, parent, hbox):
|
||||
def __init__(self, parent, hbox_parent):
|
||||
logging.debug("New DataEntryPanel instance created!")
|
||||
|
||||
Gtk.VBox.__init__(self, spacing=2)
|
||||
|
||||
self.source_call = Gtk.Entry()
|
||||
temp_hbox = Gtk.HBox(spacing=2)
|
||||
temp_hbox.pack_start(Gtk.Label("Call: "), False, False, 2)
|
||||
temp_hbox.pack_start(self.source_call, expand=True, fill=True, padding=2)
|
||||
self.pack_start(temp_hbox, False, False, 0)
|
||||
self.sources = {}
|
||||
|
||||
self.source_date = Gtk.Entry()
|
||||
temp_hbox = Gtk.HBox(spacing=2)
|
||||
temp_hbox.pack_start(Gtk.Label("Date: "), False, False, 2)
|
||||
temp_hbox.pack_start(self.source_date, expand=True, fill=True, padding=2)
|
||||
self.pack_start(temp_hbox, False, False, 0)
|
||||
|
||||
self.source_freq = Gtk.Entry()
|
||||
temp_hbox = Gtk.HBox(spacing=6)
|
||||
temp_hbox.pack_start(Gtk.Label("Freq.: "), False, False, 2)
|
||||
temp_hbox.pack_start(self.source_freq, expand=True, fill=True, padding=2)
|
||||
self.pack_start(temp_hbox, False, False, 0)
|
||||
|
||||
self.sources = {"CALL":self.source_call,
|
||||
"DATE":self.source_date,
|
||||
"FREQ":self.source_freq}
|
||||
field_names = parent.logbook.SELECTED_FIELD_NAMES_TYPES.keys()
|
||||
for i in range(0, len(field_names)):
|
||||
hbox_temp = Gtk.HBox(spacing=2)
|
||||
hbox_temp.pack_start(Gtk.Label(field_names[i]), False, False, 0)
|
||||
self.sources[field_names[i]] = Gtk.Entry()
|
||||
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)
|
||||
|
||||
hbox.pack_start(self, False, False, 0)
|
||||
hbox_parent.pack_start(self, False, False, 0)
|
||||
|
||||
return
|
||||
|
||||
|
|
|
@ -47,6 +47,63 @@ class Logbook(Gtk.ListStore):
|
|||
|
||||
logging.debug("New Logbook instance created!")
|
||||
|
||||
|
||||
def new_log(self, widget):
|
||||
self.records = []
|
||||
self.populate()
|
||||
return
|
||||
|
||||
def open_log(self, widget):
|
||||
dialog = Gtk.FileChooserDialog("Open File",
|
||||
None,
|
||||
Gtk.FileChooserAction.OPEN,
|
||||
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
|
||||
Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
|
||||
filter = Gtk.FileFilter()
|
||||
filter.set_name("All ADIF files")
|
||||
filter.add_pattern("*.adi")
|
||||
dialog.add_filter(filter)
|
||||
|
||||
response = dialog.run()
|
||||
if(response == Gtk.ResponseType.OK):
|
||||
path = dialog.get_filename()
|
||||
else:
|
||||
path = None
|
||||
dialog.destroy()
|
||||
|
||||
if(path is None):
|
||||
logging.debug("No file path specified.")
|
||||
return
|
||||
|
||||
adif = ADIF()
|
||||
self.records = adif.read(path)
|
||||
self.populate()
|
||||
|
||||
return
|
||||
|
||||
def save_log(self, widget):
|
||||
dialog = Gtk.FileChooserDialog("Save File",
|
||||
None,
|
||||
Gtk.FileChooserAction.SAVE,
|
||||
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
|
||||
Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
|
||||
|
||||
response = dialog.run()
|
||||
if(response == Gtk.ResponseType.OK):
|
||||
path = dialog.get_filename()
|
||||
else:
|
||||
path = None
|
||||
dialog.destroy()
|
||||
|
||||
if(path is None):
|
||||
logging.debug("No file path specified.")
|
||||
return
|
||||
|
||||
adif = ADIF()
|
||||
adif.write(self.records, path)
|
||||
|
||||
return
|
||||
|
||||
def add_record(self):
|
||||
# Adds a blank record to the end of the logbook,
|
||||
# to be completed by the user.
|
||||
|
|
|
@ -42,21 +42,21 @@ class Menu(Gtk.MenuBar):
|
|||
|
||||
# New ADIF log
|
||||
mitem_new = Gtk.MenuItem("New Log")
|
||||
mitem_new.connect("activate", parent.new_log)
|
||||
mitem_new.connect("activate", parent.logbook.new_log)
|
||||
key, mod = Gtk.accelerator_parse("<Control>N")
|
||||
mitem_new.add_accelerator("activate", agrp, key, mod, Gtk.AccelFlags.VISIBLE)
|
||||
subm_file.append(mitem_new)
|
||||
|
||||
# Open (for opening and reading ADIF files)
|
||||
mitem_open = Gtk.MenuItem("Open Log File...")
|
||||
mitem_open.connect("activate", parent.open_log)
|
||||
mitem_open.connect("activate", parent.logbook.open_log)
|
||||
key, mod = Gtk.accelerator_parse("<Control>O")
|
||||
mitem_open.add_accelerator("activate", agrp, key, mod, Gtk.AccelFlags.VISIBLE)
|
||||
subm_file.append(mitem_open)
|
||||
|
||||
# Save (for writing ADIF files)
|
||||
mitem_save = Gtk.MenuItem("Save Log File...")
|
||||
mitem_save.connect("activate", parent.save_log)
|
||||
mitem_save.connect("activate", parent.logbook.save_log)
|
||||
key, mod = Gtk.accelerator_parse("<Control>S")
|
||||
mitem_save.add_accelerator("activate", agrp, key, mod, Gtk.AccelFlags.VISIBLE)
|
||||
subm_file.append(mitem_save)
|
||||
|
|
65
src/pyqso.py
65
src/pyqso.py
|
@ -45,6 +45,9 @@ class PyQSO(Gtk.Window):
|
|||
vbox_outer = Gtk.VBox()
|
||||
self.add(vbox_outer)
|
||||
|
||||
# Create a new Logbook so we can add/remove/edit Record objects
|
||||
self.logbook = Logbook()
|
||||
|
||||
# Set up menu bar and populate it
|
||||
menu = Menu(self, vbox_outer)
|
||||
|
||||
|
@ -53,8 +56,7 @@ class PyQSO(Gtk.Window):
|
|||
hbox = Gtk.HBox()
|
||||
vbox_outer.pack_start(hbox, True, True, 0)
|
||||
|
||||
# Create a new Logbook so we can add/remove/edit Record objects
|
||||
self.logbook = Logbook()
|
||||
# Render the logbook
|
||||
self.treeview = Gtk.TreeView(self.logbook)
|
||||
self.treeview.set_grid_lines(Gtk.TreeViewGridLines.BOTH)
|
||||
|
||||
|
@ -70,7 +72,6 @@ class PyQSO(Gtk.Window):
|
|||
# The first column of the logbook will always be the unique record index.
|
||||
# Let's append this separately to the field names.
|
||||
renderer = Gtk.CellRendererText()
|
||||
renderer.set_property("editable", False)
|
||||
column = Gtk.TreeViewColumn("INDEX", renderer, text=0)
|
||||
column.set_resizable(True)
|
||||
column.set_min_width(50)
|
||||
|
@ -80,9 +81,7 @@ class PyQSO(Gtk.Window):
|
|||
field_names = self.logbook.SELECTED_FIELD_NAMES_TYPES.keys()
|
||||
for i in range(0, len(field_names)):
|
||||
renderer = Gtk.CellRendererText()
|
||||
renderer.set_property("editable", False)
|
||||
column = Gtk.TreeViewColumn(field_names[i], renderer, text=i+1)
|
||||
|
||||
column.set_resizable(True)
|
||||
column.set_min_width(50)
|
||||
self.treeview.append_column(column)
|
||||
|
@ -91,61 +90,6 @@ class PyQSO(Gtk.Window):
|
|||
|
||||
return
|
||||
|
||||
def new_log(self, widget):
|
||||
self.logbook.records = []
|
||||
self.logbook.populate()
|
||||
return
|
||||
|
||||
def open_log(self, widget):
|
||||
dialog = Gtk.FileChooserDialog("Open File",
|
||||
None,
|
||||
Gtk.FileChooserAction.OPEN,
|
||||
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
|
||||
Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
|
||||
filter = Gtk.FileFilter()
|
||||
filter.set_name("All ADIF files")
|
||||
filter.add_pattern("*.adi")
|
||||
dialog.add_filter(filter)
|
||||
|
||||
response = dialog.run()
|
||||
if(response == Gtk.ResponseType.OK):
|
||||
path = dialog.get_filename()
|
||||
else:
|
||||
path = None
|
||||
dialog.destroy()
|
||||
|
||||
if(path is None):
|
||||
logging.debug("No file path specified.")
|
||||
return
|
||||
|
||||
adif = ADIF()
|
||||
self.logbook.records = adif.read(path)
|
||||
self.logbook.populate()
|
||||
|
||||
return
|
||||
|
||||
def save_log(self, widget):
|
||||
dialog = Gtk.FileChooserDialog("Save File",
|
||||
None,
|
||||
Gtk.FileChooserAction.SAVE,
|
||||
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
|
||||
Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
|
||||
|
||||
response = dialog.run()
|
||||
if(response == Gtk.ResponseType.OK):
|
||||
path = dialog.get_filename()
|
||||
else:
|
||||
path = None
|
||||
dialog.destroy()
|
||||
|
||||
if(path is None):
|
||||
logging.debug("No file path specified.")
|
||||
return
|
||||
|
||||
adif = ADIF()
|
||||
adif.write(self.logbook.records, path)
|
||||
|
||||
return
|
||||
|
||||
def add_record_callback(self, widget):
|
||||
self.logbook.add_record()
|
||||
|
@ -232,3 +176,4 @@ if(__name__ == '__main__'):
|
|||
|
||||
application = PyQSO() # Populate the main window and show it
|
||||
Gtk.main() # Start up the event loop!
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue