kopia lustrzana https://github.com/ctjacobs/pyqso
Added a list of ADIF field names, in the order we would like them to be displayed in the logbook.
rodzic
7304f04c6f
commit
e5448f452c
|
@ -27,8 +27,10 @@ from record import *
|
|||
# All the possible field names and their associated data types
|
||||
# from the ADIF specification (version 3.0.2)
|
||||
AVAILABLE_FIELD_NAMES_TYPES = {"CALL": "S",
|
||||
"FREQ": "N",
|
||||
"DATE": "D"}
|
||||
"DATE": "D",
|
||||
"TIME": "T",
|
||||
"FREQ": "N",
|
||||
"MODE":"C"}
|
||||
|
||||
# A: AwardList
|
||||
# B: Boolean
|
||||
|
|
|
@ -29,13 +29,17 @@ class Logbook(Gtk.ListStore):
|
|||
def __init__(self):
|
||||
|
||||
# FIXME: Allow the user to select the field names. By default, let's select them all.
|
||||
self.SELECTED_FIELD_NAMES_TYPES = AVAILABLE_FIELD_NAMES_TYPES
|
||||
|
||||
self.SELECTED_FIELD_NAMES_TYPES = AVAILABLE_FIELD_NAMES_TYPES
|
||||
self.SELECTED_FIELD_NAMES_ORDERED = ["CALL", "DATE", "TIME", "FREQ", "MODE"]
|
||||
self.SELECTED_FIELD_NAMES_FRIENDLY = {"CALL":"Callsign",
|
||||
"DATE":"Date",
|
||||
"TIME":"Time",
|
||||
"FREQ":"Frequency",
|
||||
"MODE":"Mode"}
|
||||
|
||||
# The ListStore constructor needs to know the data types of the columns.
|
||||
# The index is always an integer. We will assume the ADIF fields are strings.
|
||||
data_types = [int]
|
||||
for key in self.SELECTED_FIELD_NAMES_TYPES.keys():
|
||||
data_types.append(str)
|
||||
data_types = [int] + [str]*len(self.SELECTED_FIELD_NAMES_ORDERED)
|
||||
|
||||
# Call the constructor of the super class (Gtk.ListStore)
|
||||
Gtk.ListStore.__init__(self, *data_types)
|
||||
|
@ -107,7 +111,7 @@ class Logbook(Gtk.ListStore):
|
|||
# using data from the fields_and_data dictionary.
|
||||
|
||||
logbook_entry = [len(self.records)] # Add the next available record index
|
||||
field_names = self.SELECTED_FIELD_NAMES_TYPES.keys()
|
||||
field_names = self.SELECTED_FIELD_NAMES_ORDERED
|
||||
for i in range(0, len(field_names)):
|
||||
logbook_entry.append(fields_and_data[field_names[i]])
|
||||
self.append(logbook_entry)
|
||||
|
@ -152,7 +156,7 @@ class Logbook(Gtk.ListStore):
|
|||
logbook_entry = [] # Create a new logbook entry
|
||||
# First append the unique index given to the record.
|
||||
logbook_entry.append(i)
|
||||
for field in self.SELECTED_FIELD_NAMES_TYPES.keys():
|
||||
for field in self.SELECTED_FIELD_NAMES_ORDERED:
|
||||
logbook_entry.append(self.records[i].get_data(field))
|
||||
self.append(logbook_entry)
|
||||
|
||||
|
|
10
src/pyqso.py
10
src/pyqso.py
|
@ -68,16 +68,16 @@ 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()
|
||||
column = Gtk.TreeViewColumn("INDEX", renderer, text=0)
|
||||
column = Gtk.TreeViewColumn("Index", renderer, text=0)
|
||||
column.set_resizable(True)
|
||||
column.set_min_width(50)
|
||||
self.treeview.append_column(column)
|
||||
|
||||
# Set up column names for each selected field
|
||||
field_names = self.logbook.SELECTED_FIELD_NAMES_TYPES.keys()
|
||||
field_names = self.logbook.SELECTED_FIELD_NAMES_ORDERED
|
||||
for i in range(0, len(field_names)):
|
||||
renderer = Gtk.CellRendererText()
|
||||
column = Gtk.TreeViewColumn(field_names[i], renderer, text=i+1)
|
||||
column = Gtk.TreeViewColumn(self.logbook.SELECTED_FIELD_NAMES_FRIENDLY[field_names[i]], renderer, text=i+1)
|
||||
column.set_resizable(True)
|
||||
column.set_min_width(50)
|
||||
self.treeview.append_column(column)
|
||||
|
@ -97,7 +97,7 @@ class PyQSO(Gtk.Window):
|
|||
response = dialog.run()
|
||||
if(response == Gtk.ResponseType.OK):
|
||||
fields_and_data = {}
|
||||
field_names = self.logbook.SELECTED_FIELD_NAMES_TYPES.keys()
|
||||
field_names = self.logbook.SELECTED_FIELD_NAMES_ORDERED
|
||||
for i in range(0, len(field_names)):
|
||||
#TODO: Validate user input!
|
||||
fields_and_data[field_names[i]] = dialog.get_data(field_names[i])
|
||||
|
@ -149,7 +149,7 @@ class PyQSO(Gtk.Window):
|
|||
response = dialog.run()
|
||||
if(response == Gtk.ResponseType.OK):
|
||||
fields_and_data = {}
|
||||
field_names = self.logbook.SELECTED_FIELD_NAMES_TYPES.keys()
|
||||
field_names = self.logbook.SELECTED_FIELD_NAMES_ORDERED
|
||||
for i in range(0, len(field_names)):
|
||||
#TODO: Validate user input!
|
||||
fields_and_data[field_names[i]] = dialog.get_data(field_names[i])
|
||||
|
|
|
@ -22,6 +22,7 @@ from gi.repository import Gtk, GObject
|
|||
import logging
|
||||
|
||||
from adif import AVAILABLE_FIELD_NAMES_TYPES
|
||||
from callsign_lookup import *
|
||||
|
||||
class RecordDialog(Gtk.Dialog):
|
||||
|
||||
|
@ -38,24 +39,61 @@ class RecordDialog(Gtk.Dialog):
|
|||
label = Gtk.Label("QSO Data")
|
||||
frame.set_label_widget(label)
|
||||
self.vbox.add(frame)
|
||||
vbox_inner = Gtk.VBox(spacing=2)
|
||||
|
||||
# Create label:entry pairs and store them in a dictionary
|
||||
self.sources = {}
|
||||
field_names = parent.logbook.SELECTED_FIELD_NAMES_TYPES.keys()
|
||||
vbox_inner = Gtk.VBox(spacing=2)
|
||||
for i in range(0, len(field_names)):
|
||||
vbox_temp = Gtk.VBox(spacing=0)
|
||||
label = Gtk.Label(field_names[i])
|
||||
label.set_alignment(0, 0.5)
|
||||
vbox_temp.pack_start(label, False, False, 0)
|
||||
self.sources[field_names[i]] = Gtk.Entry()
|
||||
|
||||
if(index is not None):
|
||||
record = parent.logbook.get_record(index)
|
||||
# CALL
|
||||
hbox_temp = Gtk.HBox(spacing=0)
|
||||
label = Gtk.Label(parent.logbook.SELECTED_FIELD_NAMES_FRIENDLY["CALL"])
|
||||
label.set_alignment(0, 0.5)
|
||||
hbox_temp.pack_start(label, False, False, 6)
|
||||
self.sources["CALL"] = Gtk.Entry()
|
||||
hbox_temp.pack_start(self.sources["CALL"], True, True, 6)
|
||||
lookup = Gtk.Button("Lookup") # Looks up the callsign on qrz.com for more details.
|
||||
lookup.connect("clicked", self.lookup_callback)
|
||||
hbox_temp.pack_start(lookup, True, True, 6)
|
||||
vbox_inner.pack_start(hbox_temp, False, False, 6)
|
||||
|
||||
# DATE
|
||||
hbox_temp = Gtk.HBox(spacing=0)
|
||||
label = Gtk.Label(parent.logbook.SELECTED_FIELD_NAMES_FRIENDLY["DATE"])
|
||||
label.set_alignment(0, 0.5)
|
||||
hbox_temp.pack_start(label, False, False, 6)
|
||||
self.sources["DATE"] = Gtk.Entry()
|
||||
hbox_temp.pack_start(self.sources["DATE"], True, True, 6)
|
||||
|
||||
# TIME
|
||||
label = Gtk.Label(parent.logbook.SELECTED_FIELD_NAMES_FRIENDLY["TIME"])
|
||||
label.set_alignment(0, 0.5)
|
||||
hbox_temp.pack_start(label, False, False, 6)
|
||||
self.sources["TIME"] = Gtk.Entry()
|
||||
hbox_temp.pack_start(self.sources["TIME"], True, True, 6)
|
||||
vbox_inner.pack_start(hbox_temp, False, False, 6)
|
||||
|
||||
# FREQ
|
||||
hbox_temp = Gtk.HBox(spacing=0)
|
||||
label = Gtk.Label(parent.logbook.SELECTED_FIELD_NAMES_FRIENDLY["FREQ"])
|
||||
label.set_alignment(0, 0.5)
|
||||
hbox_temp.pack_start(label, False, False, 6)
|
||||
self.sources["FREQ"] = Gtk.Entry()
|
||||
hbox_temp.pack_start(self.sources["FREQ"], True, True, 6)
|
||||
|
||||
# MODE
|
||||
label = Gtk.Label(parent.logbook.SELECTED_FIELD_NAMES_FRIENDLY["MODE"])
|
||||
label.set_alignment(0, 0.5)
|
||||
hbox_temp.pack_start(label, False, False, 6)
|
||||
self.sources["MODE"] = Gtk.Entry()
|
||||
hbox_temp.pack_start(self.sources["MODE"], True, True, 6)
|
||||
vbox_inner.pack_start(hbox_temp, False, False, 6)
|
||||
|
||||
if(index is not None):
|
||||
record = parent.logbook.get_record(index)
|
||||
field_names = parent.logbook.SELECTED_FIELD_NAMES_ORDERED
|
||||
for i in range(0, len(field_names)):
|
||||
self.sources[field_names[i]].set_text(record.get_data(field_names[i]))
|
||||
|
||||
vbox_temp.pack_start(self.sources[field_names[i]], True, True, 0)
|
||||
vbox_inner.pack_start(vbox_temp, False, False, 0)
|
||||
frame.add(vbox_inner)
|
||||
|
||||
self.show_all()
|
||||
|
@ -65,3 +103,6 @@ class RecordDialog(Gtk.Dialog):
|
|||
def get_data(self, field_name):
|
||||
return self.sources[field_name].get_text()
|
||||
|
||||
def lookup_callback(self, widget):
|
||||
print "hello!"
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue