1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
# This file is in the public domain
8
logger = logging.getLogger('mythremote_lib')
10
from . helpers import get_builder, show_uri, get_help_uri
11
from . preferences import preferences
13
# This class is meant to be subclassed by MythremoteWindow. It provides
14
# common functions and some boilerplate.
15
class Window(gtk.Window):
16
__gtype_name__ = "Window"
18
# To construct a new instance of this method, the following notable
19
# methods are called in this order:
22
# finish_initializing(self, builder)
25
# For this reason, it's recommended you leave __init__ empty and put
26
# your initialization code in finish_initializing
29
"""Special static method that's automatically called by Python when
30
constructing a new instance of this class.
32
Returns a fully instantiated BaseMythremoteWindow object.
34
builder = get_builder('MythremoteWindow')
35
new_object = builder.get_object("mythremote_window")
36
new_object.finish_initializing(builder)
39
def finish_initializing(self, builder):
40
"""Called while initializing this instance in __new__
42
finish_initializing should be called after parsing the UI definition
43
and creating a MythremoteWindow object with it in order to finish
44
initializing the start of the new MythremoteWindow instance.
46
# Get a reference to the builder and set up the signals.
47
self.builder = builder
48
self.ui = builder.get_ui(self, True)
49
self.PreferencesDialog = None # class
50
self.preferences_dialog = None # instance
51
self.AboutDialog = None # class
53
preferences.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
import LaunchpadIntegration
61
LaunchpadIntegration.add_items(self.ui.helpMenu, 1, True, True)
62
LaunchpadIntegration.set_sourcepackagename('mythremote')
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 mythremote 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 mythremote."""
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 mythremote."""
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 MythremoteWindow."""
111
def on_destroy(self, widget, data=None):
112
"""Called when the MythremoteWindow is closed."""
113
# Clean up code for saving application state should be added here.
116
def on_preferences_changed(self, widget, data=None):
117
logger.debug('main window received preferences changed')
119
logger.debug('preference changed: %s = %s' % (key, preferences[key]))
121
def on_preferences_dialog_destroyed(self, widget, data=None):
124
logically there is no difference between the user closing,
125
minimising or ignoring the preferences dialog'''
126
logger.debug('on_preferences_dialog_destroyed')
127
# to determine whether to create or present preferences_dialog
128
self.preferences_dialog = None