1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
# This file is in the public domain
6
from gi.repository import Gio, Gtk # pylint: disable=E0611
8
logger = logging.getLogger('rdghacksignbot_lib')
10
from . helpers import get_builder, show_uri, get_help_uri
12
# This class is meant to be subclassed by RdghacksignbotWindow. It provides
13
# common functions and some boilerplate.
14
class Window(Gtk.Window):
15
__gtype_name__ = "Window"
17
# To construct a new instance of this method, the following notable
18
# methods are called in this order:
21
# finish_initializing(self, builder)
24
# For this reason, it's recommended you leave __init__ empty and put
25
# your initialization code in finish_initializing
28
"""Special static method that's automatically called by Python when
29
constructing a new instance of this class.
31
Returns a fully instantiated BaseRdghacksignbotWindow object.
33
builder = get_builder('RdghacksignbotWindow')
34
new_object = builder.get_object("rdghacksignbot_window")
35
new_object.finish_initializing(builder)
38
def finish_initializing(self, builder):
39
"""Called while initializing this instance in __new__
41
finish_initializing should be called after parsing the UI definition
42
and creating a RdghacksignbotWindow object with it in order to finish
43
initializing the start of the new RdghacksignbotWindow instance.
45
# Get a reference to the builder and set up the signals.
46
self.builder = builder
47
self.ui = builder.get_ui(self, True)
48
self.PreferencesDialog = None # class
49
self.preferences_dialog = None # instance
50
self.AboutDialog = None # class
52
self.settings = Gio.Settings("net.launchpad.rdghacksignbot")
53
self.settings.connect('changed', self.on_preferences_changed)
55
# Optional Launchpad integration
56
# This shouldn't crash if not found as it is simply used for bug reporting.
57
# See https://wiki.ubuntu.com/UbuntuDevelopment/Internationalisation/Coding
58
# for more information about Launchpad integration.
60
from gi.repository import LaunchpadIntegration # pylint: disable=E0611
61
LaunchpadIntegration.add_items(self.ui.helpMenu, 1, True, True)
62
LaunchpadIntegration.set_sourcepackagename('rdghacksignbot')
66
# Optional application indicator support
67
# Run 'quickly add indicator' to get started.
69
# http://owaislone.org/quickly-add-indicator/
70
# https://wiki.ubuntu.com/DesktopExperienceTeam/ApplicationIndicators
72
from rdghacksignbot import indicator
73
# self is passed so methods of this class can be called from indicator.py
74
# Comment this next line out to disable appindicator
75
self.indicator = indicator.new_application_indicator(self)
79
def on_mnu_contents_activate(self, widget, data=None):
80
show_uri(self, "ghelp:%s" % get_help_uri())
82
def on_mnu_about_activate(self, widget, data=None):
83
"""Display the about box for rdghacksignbot."""
84
if self.AboutDialog is not None:
85
about = self.AboutDialog() # pylint: disable=E1102
86
response = about.run()
89
def on_mnu_preferences_activate(self, widget, data=None):
90
"""Display the preferences window for rdghacksignbot."""
92
""" From the PyGTK Reference manual
93
Say for example the preferences dialog is currently open,
94
and the user chooses Preferences from the menu a second time;
95
use the present() method to move the already-open dialog
96
where the user can see it."""
97
if self.preferences_dialog is not None:
98
logger.debug('show existing preferences_dialog')
99
self.preferences_dialog.present()
100
elif self.PreferencesDialog is not None:
101
logger.debug('create new preferences_dialog')
102
self.preferences_dialog = self.PreferencesDialog() # pylint: disable=E1102
103
self.preferences_dialog.connect('destroy', self.on_preferences_dialog_destroyed)
104
self.preferences_dialog.show()
105
# destroy command moved into dialog to allow for a help button
107
def on_mnu_close_activate(self, widget, data=None):
108
"""Signal handler for closing the RdghacksignbotWindow."""
111
def on_destroy(self, widget, data=None):
112
"""Called when the RdghacksignbotWindow is closed."""
113
# Clean up code for saving application state should be added here.
116
def on_preferences_changed(self, settings, key, data=None):
117
logger.debug('preference changed: %s = %s' % (key, str(settings.get_value(key))))
119
def on_preferences_dialog_destroyed(self, widget, data=None):
122
logically there is no difference between the user closing,
123
minimising or ignoring the preferences dialog'''
124
logger.debug('on_preferences_dialog_destroyed')
125
# to determine whether to create or present preferences_dialog
126
self.preferences_dialog = None