Added a popup menu, and functionality for plotting points on the grey line map.

pull/61/head
Christian Jacobs 2018-01-07 22:18:16 +00:00
rodzic ce49d8aae3
commit 6bbb15d4f5
5 zmienionych plików z 119 dodań i 8 usunięć

Wyświetl plik

@ -44,6 +44,7 @@ sys.path.insert(0, pyqso_path)
from pyqso.adif import *
from pyqso.logbook import *
from pyqso.menu import *
from pyqso.popup import *
from pyqso.toolbar import *
from pyqso.toolbox import *
from pyqso.preferences_dialog import *
@ -93,8 +94,9 @@ class PyQSO:
self.logbook = Logbook(self)
self.toolbox = Toolbox(self)
# Set up menu and tool bars. These classes depend on the Logbook and Toolbox class.
# Set up menu and toolbar. These classes depend on the Logbook and Toolbox class.
self.menu = Menu(self)
self.popup = Popup(self)
self.toolbar = Toolbar(self)
self.window.show_all()

Wyświetl plik

@ -40,6 +40,14 @@ except ImportError as e:
have_necessary_modules = False
class Point:
def __init__(self, name, latitude, longitude):
self.name = name
self.latitude = latitude
self.longitude = longitude
return
class GreyLine:
""" A tool for visualising the grey line. """
@ -76,12 +84,27 @@ class GreyLine:
self.builder.get_object("greyline").pack_start(self.canvas, True, True, 0)
self.refresh_event = GObject.timeout_add(1800000, self.draw) # Re-draw the grey line automatically after 30 minutes (if the grey line tool is visible).
self.points = []
self.builder.get_object("greyline").show_all()
logging.debug("Grey line ready!")
return
def add_point(self, name, latitude, longitude):
""" Add a point to the map. """
p = Point(name, latitude, longitude)
self.points.append(p)
self.draw()
return
def remove_point(self, p):
""" Remove a point from the map. """
self.points.remove(p)
self.draw()
return
def draw(self):
""" Draw the world map and the grey line on top of it.
@ -119,6 +142,12 @@ class GreyLine:
m.plot(qth_x, qth_y, "ro")
sub.text(qth_x+0.015*qth_x, qth_y+0.015*qth_y, self.qth_name, color="white", size="medium", weight="bold")
if(self.points):
for p in self.points:
x, y = m(p.longitude, p.latitude)
m.plot(x, y, "yo")
sub.text(x+0.015*x, y+0.015*y, p.name, color="white", size="medium", weight="bold")
return True
else:
return False # Don't try to re-draw the canvas if the necessary modules to do so could not be imported.

Wyświetl plik

@ -388,9 +388,10 @@ class Logbook:
self.treeview.append(Gtk.TreeView(model=self.sorter[index]))
self.treeview[index].set_grid_lines(Gtk.TreeViewGridLines.BOTH)
self.treeview[index].connect("row-activated", self.edit_record_callback)
self.treeview[index].connect("button-release-event", self.on_button_release_event)
self.treeselection.append(self.treeview[index].get_selection())
self.treeselection[index].set_mode(Gtk.SelectionMode.SINGLE)
self.treeselection[index].connect('changed', self.on_selection_changed)
# Allow the Log to be scrolled up/down.
sw = Gtk.ScrolledWindow()
sw.set_shadow_type(Gtk.ShadowType.ETCHED_IN)
@ -1119,13 +1120,39 @@ class Logbook:
logs.append(l)
return logs
def on_selection_changed(self, selection):
if(have_geocoder):
def on_button_release_event(self, treeview, event):
if(event.button == 3):
# Plot the COUNTRY field of the selected QSO on the grey line map, if desired.
(model, iter) = selection.get_selected()
index = model.get_value(iter, 0)
log = self.logs[self.get_log_index()]
country = log.get_record_by_index(index)["COUNTRY"]
self.application.popup.menu.popup(None, None, None, None, event.button, event.time)
self.application.popup.menu.show_all()
return True
def plot_on_map(self, widget=None, path=None):
if(have_geocoder):
# Get the log index.
try:
log_index = self.get_log_index()
if(log_index is None):
raise ValueError("The log index could not be determined. Perhaps the Summary page is selected?")
except ValueError as e:
error(parent=self.application.window, message=e)
return
log = self.logs[log_index]
(sort_model, path) = self.treeselection[log_index].get_selected_rows() # Get the selected row in the log.
try:
sort_iter = sort_model.get_iter(path[0])
filter_iter = self.sorter[log_index].convert_iter_to_child_iter(sort_iter)
# ...and the ListStore model (i.e. the log) is a child of the filter model.
child_iter = self.filter[log_index].convert_iter_to_child_iter(filter_iter)
row_index = log.get_value(child_iter, 0)
except IndexError:
logging.debug("Could not find the selected row's index!")
return
r = log.get_record_by_index(row_index)
country = r["COUNTRY"]
callsign = r["CALL"]
# Get the latitude-longitude coordinates of the country.
if(country):
@ -1138,4 +1165,6 @@ class Logbook:
except Exception:
logging.exception("Unable to lookup QTH coordinates. Check connection to the internets?")
self.application.toolbox.grey_line.add_point(callsign, latitude, longitude)
return

39
pyqso/popup.py 100644
Wyświetl plik

@ -0,0 +1,39 @@
#!/usr/bin/env python3
# Copyright (C) 2018 Christian Thomas Jacobs.
# This file is part of PyQSO.
# PyQSO is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyQSO is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PyQSO. If not, see <http://www.gnu.org/licenses/>.
class Popup:
""" The popup menu that appears when a QSO record is right-clicked. """
def __init__(self, application):
self.application = application
self.builder = self.application.builder
self.menu = self.builder.get_object("popup")
# Collect Gtk menu items and connect signals.
self.items = {}
# Plot selected QSO on the grey line map.
self.items["PLOT_ON_MAP"] = self.builder.get_object("mitem_map")
self.items["PLOT_ON_MAP"].connect("activate", self.application.logbook.plot_on_map)
return

Wyświetl plik

@ -4547,6 +4547,18 @@ Base64-encoded plain text in the configuration file.</property>
<action-widget response="-5">telnet_connection_ok_button</action-widget>
</action-widgets>
</object>
<object class="GtkMenu" id="popup">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkMenuItem" id="mitem_map">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Plot On Map</property>
<property name="use_underline">True</property>
</object>
</child>
</object>
<object class="GtkBox" id="summary_page">
<property name="visible">True</property>
<property name="can_focus">False</property>