2013-03-24 15:14:10 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2015-03-06 23:31:46 +00:00
|
|
|
# Copyright (C) 2013 Christian T. Jacobs.
|
2013-03-24 15:14:10 +00:00
|
|
|
|
|
|
|
# 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/>.
|
|
|
|
|
2015-09-30 08:56:56 +00:00
|
|
|
from gi.repository import Gtk
|
2013-03-24 15:14:10 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
class Toolbar(Gtk.HBox):
|
2015-10-03 16:51:25 +00:00
|
|
|
""" The toolbar underneath the menu bar. """
|
|
|
|
|
2013-03-27 20:29:43 +00:00
|
|
|
def __init__(self, parent):
|
2015-10-03 16:51:25 +00:00
|
|
|
""" Set up the various buttons in the toolbar, and connect to their corresponding functions. """
|
|
|
|
|
2013-09-14 21:19:33 +00:00
|
|
|
logging.debug("Setting up the toolbar...")
|
|
|
|
|
2013-03-24 15:14:10 +00:00
|
|
|
Gtk.HBox.__init__(self, spacing=2)
|
|
|
|
|
2013-04-26 09:10:05 +00:00
|
|
|
self.buttons = {}
|
|
|
|
|
2015-02-07 21:22:16 +00:00
|
|
|
# Create logbook
|
|
|
|
icon = Gtk.Image()
|
|
|
|
icon.set_from_stock(Gtk.STOCK_NEW, Gtk.IconSize.BUTTON)
|
|
|
|
button = Gtk.Button()
|
|
|
|
button.add(icon)
|
|
|
|
button.set_tooltip_text('Create a New Logbook')
|
|
|
|
button.connect("clicked", parent.logbook.new)
|
|
|
|
self.pack_start(button, False, False, 0)
|
|
|
|
self.buttons["NEW_LOGBOOK"] = button
|
|
|
|
|
|
|
|
# Open logbook
|
2013-04-21 14:52:06 +00:00
|
|
|
icon = Gtk.Image()
|
2013-09-14 18:27:45 +00:00
|
|
|
icon.set_from_stock(Gtk.STOCK_OPEN, Gtk.IconSize.BUTTON)
|
2013-04-21 14:52:06 +00:00
|
|
|
button = Gtk.Button()
|
|
|
|
button.add(icon)
|
2015-02-07 21:22:16 +00:00
|
|
|
button.set_tooltip_text('Open an Existing Logbook')
|
2013-09-14 18:27:45 +00:00
|
|
|
button.connect("clicked", parent.logbook.open)
|
2013-04-21 14:52:06 +00:00
|
|
|
self.pack_start(button, False, False, 0)
|
2013-09-14 18:27:45 +00:00
|
|
|
self.buttons["OPEN_LOGBOOK"] = button
|
2013-04-21 14:52:06 +00:00
|
|
|
|
2013-09-14 18:27:45 +00:00
|
|
|
# Close logbook
|
2013-04-21 14:52:06 +00:00
|
|
|
icon = Gtk.Image()
|
2013-09-14 18:27:45 +00:00
|
|
|
icon.set_from_stock(Gtk.STOCK_CLOSE, Gtk.IconSize.BUTTON)
|
2013-04-21 14:52:06 +00:00
|
|
|
button = Gtk.Button()
|
|
|
|
button.add(icon)
|
2013-09-14 18:27:45 +00:00
|
|
|
button.set_tooltip_text('Close Logbook')
|
|
|
|
button.connect("clicked", parent.logbook.close)
|
2013-04-21 14:52:06 +00:00
|
|
|
self.pack_start(button, False, False, 0)
|
2013-09-14 18:27:45 +00:00
|
|
|
self.buttons["CLOSE_LOGBOOK"] = button
|
2013-04-21 14:52:06 +00:00
|
|
|
|
2013-04-26 22:53:23 +00:00
|
|
|
self.pack_start(Gtk.SeparatorToolItem(), False, False, 0)
|
2013-04-21 14:52:06 +00:00
|
|
|
|
2013-03-24 15:14:10 +00:00
|
|
|
# Add record
|
|
|
|
icon = Gtk.Image()
|
|
|
|
icon.set_from_stock(Gtk.STOCK_ADD, Gtk.IconSize.BUTTON)
|
|
|
|
button = Gtk.Button()
|
|
|
|
button.add(icon)
|
2013-09-15 14:02:39 +00:00
|
|
|
button.set_tooltip_text('Add Record')
|
2013-04-16 22:53:24 +00:00
|
|
|
button.connect("clicked", parent.logbook.add_record_callback)
|
2013-03-24 15:14:10 +00:00
|
|
|
self.pack_start(button, False, False, 0)
|
2013-04-26 09:10:05 +00:00
|
|
|
self.buttons["ADD_RECORD"] = button
|
2013-03-24 15:14:10 +00:00
|
|
|
|
|
|
|
# Edit record
|
|
|
|
icon = Gtk.Image()
|
|
|
|
icon.set_from_stock(Gtk.STOCK_EDIT, Gtk.IconSize.BUTTON)
|
|
|
|
button = Gtk.Button()
|
|
|
|
button.add(icon)
|
2013-09-15 14:02:39 +00:00
|
|
|
button.set_tooltip_text('Edit Record')
|
2013-04-16 22:53:24 +00:00
|
|
|
button.connect("clicked", parent.logbook.edit_record_callback, None, None)
|
2013-03-24 15:14:10 +00:00
|
|
|
self.pack_start(button, False, False, 0)
|
2013-04-26 09:10:05 +00:00
|
|
|
self.buttons["EDIT_RECORD"] = button
|
2013-03-24 15:14:10 +00:00
|
|
|
|
2013-03-24 18:24:40 +00:00
|
|
|
# Delete record
|
2013-03-24 15:14:10 +00:00
|
|
|
icon = Gtk.Image()
|
2013-04-15 01:37:02 +00:00
|
|
|
icon.set_from_stock(Gtk.STOCK_DELETE, Gtk.IconSize.BUTTON)
|
2013-03-24 15:14:10 +00:00
|
|
|
button = Gtk.Button()
|
|
|
|
button.add(icon)
|
2013-09-15 14:02:39 +00:00
|
|
|
button.set_tooltip_text('Delete Record')
|
2013-04-16 22:53:24 +00:00
|
|
|
button.connect("clicked", parent.logbook.delete_record_callback)
|
2013-03-24 15:14:10 +00:00
|
|
|
self.pack_start(button, False, False, 0)
|
2013-04-26 09:10:05 +00:00
|
|
|
self.buttons["DELETE_RECORD"] = button
|
2013-03-24 15:14:10 +00:00
|
|
|
|
2013-04-26 22:53:23 +00:00
|
|
|
self.pack_start(Gtk.SeparatorToolItem(), False, False, 0)
|
2013-03-30 03:25:33 +00:00
|
|
|
|
2013-05-19 15:51:47 +00:00
|
|
|
# Filter log
|
2013-09-14 19:15:12 +00:00
|
|
|
label = Gtk.Label("Filter by callsign: ")
|
2013-05-19 15:51:47 +00:00
|
|
|
self.pack_start(label, False, False, 0)
|
|
|
|
self.filter_source = Gtk.Entry()
|
2013-05-19 15:58:10 +00:00
|
|
|
self.filter_source.set_width_chars(11)
|
2013-09-14 19:15:12 +00:00
|
|
|
self.filter_source.connect_after("changed", parent.logbook.filter_logs)
|
2013-05-19 15:51:47 +00:00
|
|
|
self.pack_start(self.filter_source, False, False, 0)
|
2013-04-26 09:10:05 +00:00
|
|
|
|
2013-09-14 18:27:45 +00:00
|
|
|
self.set_logbook_button_sensitive(True)
|
2013-04-26 09:10:05 +00:00
|
|
|
self.set_record_buttons_sensitive(False)
|
|
|
|
|
2013-05-19 15:58:10 +00:00
|
|
|
self.filter_source.set_sensitive(False)
|
|
|
|
|
2013-09-14 19:15:12 +00:00
|
|
|
logging.debug("Toolbar ready!")
|
2013-03-30 03:25:33 +00:00
|
|
|
|
2013-03-24 15:14:10 +00:00
|
|
|
return
|
2013-04-26 09:10:05 +00:00
|
|
|
|
2013-09-14 18:27:45 +00:00
|
|
|
def set_logbook_button_sensitive(self, sensitive):
|
2015-10-03 16:51:25 +00:00
|
|
|
""" Enable/disable logbook-related toolbar items.
|
|
|
|
|
|
|
|
:arg bool sensitive: If True, enable the 'new logbook' and 'open logbook' toolbar items. If False, disable them.
|
|
|
|
"""
|
|
|
|
logging.debug("Setting logbook-related toolbar item sensitivity to: %s..." % sensitive)
|
2015-02-07 21:22:16 +00:00
|
|
|
self.buttons["NEW_LOGBOOK"].set_sensitive(sensitive)
|
2013-09-14 18:27:45 +00:00
|
|
|
self.buttons["OPEN_LOGBOOK"].set_sensitive(sensitive)
|
|
|
|
self.buttons["CLOSE_LOGBOOK"].set_sensitive(not sensitive)
|
2015-10-03 16:51:25 +00:00
|
|
|
logging.debug("Set logbook-related toolbar item sensitivity to: %s." % sensitive)
|
2013-09-14 19:15:12 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
def set_record_buttons_sensitive(self, sensitive):
|
2015-10-03 16:51:25 +00:00
|
|
|
""" Enable/disable record-related toolbar items.
|
|
|
|
|
|
|
|
:arg bool sensitive: If True, enable all the record-related toolbar items. If False, disable them all.
|
|
|
|
"""
|
|
|
|
logging.debug("Setting record-related toolbar item sensitivity to: %s..." % sensitive)
|
2013-09-14 19:15:12 +00:00
|
|
|
for button_name in ["ADD_RECORD", "EDIT_RECORD", "DELETE_RECORD"]:
|
|
|
|
self.buttons[button_name].set_sensitive(sensitive)
|
2015-10-03 16:51:25 +00:00
|
|
|
logging.debug("Set record-related toolbar item sensitivity to: %s." % sensitive)
|
2013-04-26 09:10:05 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
|
2013-09-14 19:15:12 +00:00
|
|
|
|