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