2015-10-12 00:23:37 +00:00
|
|
|
#!/usr/bin/env python3
|
2013-03-22 22:16:31 +00:00
|
|
|
|
2017-03-20 13:06:01 +00:00
|
|
|
# Copyright (C) 2012-2017 Christian Thomas Jacobs.
|
2013-03-22 22:16:31 +00:00
|
|
|
|
2015-10-03 16:51:25 +00:00
|
|
|
# This file is part of PyQSO.
|
2013-03-22 22:16:31 +00:00
|
|
|
|
|
|
|
# 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/>.
|
|
|
|
|
2015-09-30 08:56:56 +00:00
|
|
|
from gi.repository import Gtk
|
2017-02-07 14:17:14 +00:00
|
|
|
try:
|
|
|
|
import configparser
|
|
|
|
except ImportError:
|
|
|
|
import ConfigParser as configparser
|
2013-06-30 23:56:32 +00:00
|
|
|
import os.path
|
2013-03-22 22:16:31 +00:00
|
|
|
|
2016-01-27 16:23:09 +00:00
|
|
|
|
2017-02-21 16:45:58 +00:00
|
|
|
class Menu:
|
2013-04-26 09:32:48 +00:00
|
|
|
|
2017-06-30 11:30:20 +00:00
|
|
|
""" The menu bar along the top of the main window. """
|
2016-01-27 16:23:09 +00:00
|
|
|
|
2017-03-31 09:06:11 +00:00
|
|
|
def __init__(self, application):
|
2016-01-27 16:23:09 +00:00
|
|
|
""" Set up all menu items and connect to the various functions.
|
|
|
|
|
2017-03-31 09:06:11 +00:00
|
|
|
:arg application: The PyQSO application containing the main Gtk window, etc.
|
2016-01-27 16:23:09 +00:00
|
|
|
"""
|
|
|
|
|
2017-03-31 09:06:11 +00:00
|
|
|
self.application = application
|
|
|
|
self.builder = self.application.builder
|
2017-02-21 16:45:58 +00:00
|
|
|
|
|
|
|
# Collect Gtk menu items and connect signals.
|
2016-01-27 16:23:09 +00:00
|
|
|
self.items = {}
|
|
|
|
|
2017-02-21 16:45:58 +00:00
|
|
|
# New logbook
|
|
|
|
self.items["NEW_LOGBOOK"] = self.builder.get_object("mitem_new_logbook")
|
2017-03-31 09:06:11 +00:00
|
|
|
self.items["NEW_LOGBOOK"].connect("activate", self.application.logbook.new)
|
2016-01-27 16:23:09 +00:00
|
|
|
|
|
|
|
# Open logbook
|
2017-02-21 16:45:58 +00:00
|
|
|
self.items["OPEN_LOGBOOK"] = self.builder.get_object("mitem_open_logbook")
|
2017-03-31 09:06:11 +00:00
|
|
|
self.items["OPEN_LOGBOOK"].connect("activate", self.application.logbook.open)
|
2016-01-27 16:23:09 +00:00
|
|
|
|
|
|
|
# Close logbook
|
2017-02-21 16:45:58 +00:00
|
|
|
self.items["CLOSE_LOGBOOK"] = self.builder.get_object("mitem_close_logbook")
|
2017-03-31 09:06:11 +00:00
|
|
|
self.items["CLOSE_LOGBOOK"].connect("activate", self.application.logbook.close)
|
2016-01-27 16:23:09 +00:00
|
|
|
|
|
|
|
# New log
|
2017-02-21 16:45:58 +00:00
|
|
|
self.items["NEW_LOG"] = self.builder.get_object("mitem_new_log")
|
2017-03-31 09:06:11 +00:00
|
|
|
self.items["NEW_LOG"].connect("activate", self.application.logbook.new_log)
|
2016-01-27 16:23:09 +00:00
|
|
|
|
|
|
|
# Delete the current log
|
2017-02-21 16:45:58 +00:00
|
|
|
self.items["DELETE_LOG"] = self.builder.get_object("mitem_delete_log")
|
2017-03-31 09:06:11 +00:00
|
|
|
self.items["DELETE_LOG"].connect("activate", self.application.logbook.delete_log)
|
2016-01-27 16:23:09 +00:00
|
|
|
|
|
|
|
# Rename the current log
|
2017-02-21 16:45:58 +00:00
|
|
|
self.items["RENAME_LOG"] = self.builder.get_object("mitem_rename_log")
|
2017-03-31 09:06:11 +00:00
|
|
|
self.items["RENAME_LOG"].connect("activate", self.application.logbook.rename_log)
|
2016-01-27 16:23:09 +00:00
|
|
|
|
|
|
|
# Import log
|
2017-02-21 16:45:58 +00:00
|
|
|
self.items["IMPORT_LOG"] = self.builder.get_object("mitem_import_log")
|
2017-03-31 09:06:11 +00:00
|
|
|
self.items["IMPORT_LOG"].connect("activate", self.application.logbook.import_log)
|
2016-01-27 16:23:09 +00:00
|
|
|
|
2017-04-05 21:42:43 +00:00
|
|
|
# Export the current log as ADIF
|
|
|
|
self.items["EXPORT_LOG_ADIF"] = self.builder.get_object("mitem_export_log_adif")
|
|
|
|
self.items["EXPORT_LOG_ADIF"].connect("activate", self.application.logbook.export_log_adif)
|
|
|
|
|
|
|
|
# Export the current log as Cabrillo
|
|
|
|
self.items["EXPORT_LOG_CABRILLO"] = self.builder.get_object("mitem_export_log_cabrillo")
|
|
|
|
self.items["EXPORT_LOG_CABRILLO"].connect("activate", self.application.logbook.export_log_cabrillo)
|
2016-01-27 16:23:09 +00:00
|
|
|
|
|
|
|
# Print log
|
2017-02-21 16:45:58 +00:00
|
|
|
self.items["PRINT_LOG"] = self.builder.get_object("mitem_print_log")
|
2017-03-31 09:06:11 +00:00
|
|
|
self.items["PRINT_LOG"].connect("activate", self.application.logbook.print_log)
|
2016-01-27 16:23:09 +00:00
|
|
|
|
2017-06-24 21:27:51 +00:00
|
|
|
# Preferences
|
|
|
|
self.items["PREFERENCES"] = self.builder.get_object("mitem_preferences")
|
|
|
|
self.items["PREFERENCES"].connect("activate", self.application.show_preferences)
|
|
|
|
|
2016-01-27 16:23:09 +00:00
|
|
|
# Quit
|
2017-02-21 16:45:58 +00:00
|
|
|
self.items["QUIT"] = self.builder.get_object("mitem_quit")
|
|
|
|
self.items["QUIT"].connect("activate", Gtk.main_quit)
|
|
|
|
|
|
|
|
# Add record
|
|
|
|
self.items["ADD_RECORD"] = self.builder.get_object("mitem_add_record")
|
2017-03-31 09:06:11 +00:00
|
|
|
self.items["ADD_RECORD"].connect("activate", self.application.logbook.add_record_callback)
|
2017-02-21 16:45:58 +00:00
|
|
|
|
|
|
|
# Edit selected record
|
|
|
|
self.items["EDIT_RECORD"] = self.builder.get_object("mitem_edit_record")
|
2017-03-31 09:06:11 +00:00
|
|
|
self.items["EDIT_RECORD"].connect("activate", self.application.logbook.edit_record_callback)
|
2017-02-21 16:45:58 +00:00
|
|
|
|
|
|
|
# Delete selected record
|
|
|
|
self.items["DELETE_RECORD"] = self.builder.get_object("mitem_delete_record")
|
2017-03-31 09:06:11 +00:00
|
|
|
self.items["DELETE_RECORD"].connect("activate", self.application.logbook.delete_record_callback)
|
2017-02-21 16:45:58 +00:00
|
|
|
|
|
|
|
# Remove duplicates
|
|
|
|
self.items["REMOVE_DUPLICATES"] = self.builder.get_object("mitem_remove_duplicates")
|
2017-03-31 09:06:11 +00:00
|
|
|
self.items["REMOVE_DUPLICATES"].connect("activate", self.application.logbook.remove_duplicates_callback)
|
2017-02-21 16:45:58 +00:00
|
|
|
|
2017-06-27 20:13:59 +00:00
|
|
|
# Record count
|
|
|
|
self.items["RECORD_COUNT"] = self.builder.get_object("mitem_record_count")
|
|
|
|
self.items["RECORD_COUNT"].connect("activate", self.application.logbook.record_count_callback)
|
|
|
|
|
2017-02-21 16:45:58 +00:00
|
|
|
# View toolbox
|
|
|
|
self.items["TOOLBOX"] = self.builder.get_object("mitem_toolbox")
|
2016-01-27 16:23:09 +00:00
|
|
|
config = configparser.ConfigParser()
|
|
|
|
have_config = (config.read(os.path.expanduser('~/.config/pyqso/preferences.ini')) != [])
|
|
|
|
(section, option) = ("general", "show_toolbox")
|
|
|
|
if(have_config and config.has_option(section, option)):
|
2017-02-21 16:45:58 +00:00
|
|
|
self.items["TOOLBOX"].set_active(config.get(section, option) == "True")
|
2016-01-27 16:23:09 +00:00
|
|
|
else:
|
2017-02-21 16:45:58 +00:00
|
|
|
self.items["TOOLBOX"].set_active(False) # Don't show the toolbox by default
|
2017-03-31 09:06:11 +00:00
|
|
|
self.items["TOOLBOX"].connect("activate", self.application.toolbox.toggle_visible_callback)
|
2017-02-21 16:45:58 +00:00
|
|
|
|
2016-01-27 16:23:09 +00:00
|
|
|
# About
|
2017-02-21 16:45:58 +00:00
|
|
|
self.items["ABOUT"] = self.builder.get_object("mitem_about")
|
2017-03-31 09:06:11 +00:00
|
|
|
self.items["ABOUT"].connect("activate", self.application.show_about)
|
2016-01-27 16:23:09 +00:00
|
|
|
|
|
|
|
self.set_logbook_item_sensitive(True)
|
|
|
|
self.set_log_items_sensitive(False)
|
|
|
|
self.set_record_items_sensitive(False)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
def set_logbook_item_sensitive(self, sensitive):
|
|
|
|
""" Enable/disable logbook-related menu items.
|
|
|
|
|
|
|
|
:arg bool sensitive: If True, enable the 'new logbook' and 'open logbook' menu items. If False, disable them.
|
|
|
|
"""
|
2017-06-30 11:30:20 +00:00
|
|
|
|
2016-01-27 16:23:09 +00:00
|
|
|
self.items["NEW_LOGBOOK"].set_sensitive(sensitive)
|
|
|
|
self.items["OPEN_LOGBOOK"].set_sensitive(sensitive)
|
|
|
|
self.items["CLOSE_LOGBOOK"].set_sensitive(not sensitive)
|
|
|
|
return
|
|
|
|
|
|
|
|
def set_log_items_sensitive(self, sensitive):
|
|
|
|
""" Enable/disable log-related menu items.
|
|
|
|
|
|
|
|
:arg bool sensitive: If True, enable all the log-related menu items. If False, disable them all.
|
|
|
|
"""
|
2017-06-30 11:30:20 +00:00
|
|
|
|
2017-04-05 21:42:43 +00:00
|
|
|
for item_name in ["NEW_LOG", "DELETE_LOG", "RENAME_LOG", "IMPORT_LOG", "EXPORT_LOG_ADIF", "EXPORT_LOG_CABRILLO", "PRINT_LOG"]:
|
2016-01-27 16:23:09 +00:00
|
|
|
self.items[item_name].set_sensitive(sensitive)
|
|
|
|
return
|
|
|
|
|
|
|
|
def set_record_items_sensitive(self, sensitive):
|
|
|
|
""" Enable/disable record-related menu items.
|
|
|
|
|
|
|
|
:arg bool sensitive: If True, enable all the record-related menu items. If False, disable them all.
|
|
|
|
"""
|
2017-06-30 11:30:20 +00:00
|
|
|
|
2017-06-27 20:13:59 +00:00
|
|
|
for item_name in ["ADD_RECORD", "EDIT_RECORD", "DELETE_RECORD", "REMOVE_DUPLICATES", "RECORD_COUNT"]:
|
2016-01-27 16:23:09 +00:00
|
|
|
self.items[item_name].set_sensitive(sensitive)
|
|
|
|
return
|