From 6bbb15d4f5484c61a480259cf7b973661b511cfe Mon Sep 17 00:00:00 2001 From: Christian Jacobs Date: Sun, 7 Jan 2018 22:18:16 +0000 Subject: [PATCH] Added a popup menu, and functionality for plotting points on the grey line map. --- bin/pyqso | 4 +++- pyqso/grey_line.py | 29 +++++++++++++++++++++++++++++ pyqso/logbook.py | 43 ++++++++++++++++++++++++++++++++++++------- pyqso/popup.py | 39 +++++++++++++++++++++++++++++++++++++++ pyqso/res/pyqso.glade | 12 ++++++++++++ 5 files changed, 119 insertions(+), 8 deletions(-) create mode 100644 pyqso/popup.py diff --git a/bin/pyqso b/bin/pyqso index 6ea059a..cdd546b 100755 --- a/bin/pyqso +++ b/bin/pyqso @@ -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() diff --git a/pyqso/grey_line.py b/pyqso/grey_line.py index 9dd3d88..ce699df 100644 --- a/pyqso/grey_line.py +++ b/pyqso/grey_line.py @@ -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. diff --git a/pyqso/logbook.py b/pyqso/logbook.py index 8c49763..a7ea10e 100644 --- a/pyqso/logbook.py +++ b/pyqso/logbook.py @@ -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 diff --git a/pyqso/popup.py b/pyqso/popup.py new file mode 100644 index 0000000..91f6819 --- /dev/null +++ b/pyqso/popup.py @@ -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 . + + +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 diff --git a/pyqso/res/pyqso.glade b/pyqso/res/pyqso.glade index d942461..c89ad8c 100644 --- a/pyqso/res/pyqso.glade +++ b/pyqso/res/pyqso.glade @@ -4547,6 +4547,18 @@ Base64-encoded plain text in the configuration file. telnet_connection_ok_button + + True + False + + + True + False + Plot On Map + True + + + True False