1
by David Planella
Initial project creation with Quickly! |
1 |
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
|
2 |
### BEGIN LICENSE
|
|
86.1.9
by David Planella
Checkpoint commit for testing purposes |
3 |
# Copyright (C) 2012 David Planella <david.planella@ubuntu.com>
|
4 |
# This program is free software: you can redistribute it and/or modify it
|
|
5 |
# under the terms of the GNU General Public License version 3, as published
|
|
6 |
# by the Free Software Foundation.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful, but
|
|
9 |
# WITHOUT ANY WARRANTY; without even the implied warranties of
|
|
10 |
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
|
|
11 |
# PURPOSE. See the GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License along
|
|
14 |
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
1
by David Planella
Initial project creation with Quickly! |
15 |
### END LICENSE
|
16 |
||
86.1.5
by David Planella
Pre-upgrade checkpoint |
17 |
### DO NOT EDIT THIS FILE ###
|
18 |
||
19 |
from gi.repository import Gio, Gtk # pylint: disable=E0611 |
|
1
by David Planella
Initial project creation with Quickly! |
20 |
import logging |
21 |
logger = logging.getLogger('qreator_lib') |
|
22 |
||
86.1.5
by David Planella
Pre-upgrade checkpoint |
23 |
from . helpers import get_builder, show_uri, get_help_uri |
1
by David Planella
Initial project creation with Quickly! |
24 |
|
25 |
# This class is meant to be subclassed by QreatorWindow. It provides
|
|
26 |
# common functions and some boilerplate.
|
|
27 |
class Window(Gtk.Window): |
|
28 |
__gtype_name__ = "Window" |
|
29 |
||
30 |
# To construct a new instance of this method, the following notable
|
|
31 |
# methods are called in this order:
|
|
32 |
# __new__(cls)
|
|
33 |
# __init__(self)
|
|
34 |
# finish_initializing(self, builder)
|
|
35 |
# __init__(self)
|
|
36 |
#
|
|
37 |
# For this reason, it's recommended you leave __init__ empty and put
|
|
38 |
# your initialization code in finish_initializing
|
|
39 |
||
40 |
def __new__(cls): |
|
41 |
"""Special static method that's automatically called by Python when
|
|
42 |
constructing a new instance of this class.
|
|
43 |
|
|
44 |
Returns a fully instantiated BaseQreatorWindow object.
|
|
45 |
"""
|
|
46 |
builder = get_builder('QreatorWindow') |
|
47 |
new_object = builder.get_object("qreator_window") |
|
48 |
new_object.finish_initializing(builder) |
|
49 |
return new_object |
|
50 |
||
51 |
def finish_initializing(self, builder): |
|
52 |
"""Called while initializing this instance in __new__
|
|
53 |
||
54 |
finish_initializing should be called after parsing the UI definition
|
|
55 |
and creating a QreatorWindow object with it in order to finish
|
|
56 |
initializing the start of the new QreatorWindow instance.
|
|
57 |
"""
|
|
58 |
# Get a reference to the builder and set up the signals.
|
|
59 |
self.builder = builder |
|
60 |
self.ui = builder.get_ui(self, True) |
|
61 |
self.PreferencesDialog = None # class |
|
62 |
self.preferences_dialog = None # instance |
|
63 |
self.AboutDialog = None # class |
|
64 |
||
86.1.5
by David Planella
Pre-upgrade checkpoint |
65 |
self.settings = Gio.Settings("net.launchpad.qreator") |
66 |
self.settings.connect('changed', self.on_preferences_changed) |
|
1
by David Planella
Initial project creation with Quickly! |
67 |
|
68 |
# Optional application indicator support
|
|
69 |
# Run 'quickly add indicator' to get started.
|
|
70 |
# More information:
|
|
71 |
# http://owaislone.org/quickly-add-indicator/
|
|
72 |
# https://wiki.ubuntu.com/DesktopExperienceTeam/ApplicationIndicators
|
|
73 |
try: |
|
74 |
from qreator import indicator |
|
75 |
# self is passed so methods of this class can be called from indicator.py
|
|
76 |
# Comment this next line out to disable appindicator
|
|
77 |
self.indicator = indicator.new_application_indicator(self) |
|
78 |
except ImportError: |
|
79 |
pass
|
|
80 |
||
86.1.5
by David Planella
Pre-upgrade checkpoint |
81 |
def on_mnu_contents_activate(self, widget, data=None): |
82 |
show_uri(self, "ghelp:%s" % get_help_uri()) |
|
83 |
||
84 |
def on_mnu_about_activate(self, widget, data=None): |
|
85 |
"""Display the about box for qreator."""
|
|
86 |
if self.AboutDialog is not None: |
|
87 |
about = self.AboutDialog() # pylint: disable=E1102 |
|
88 |
response = about.run() |
|
89 |
about.destroy() |
|
90 |
||
91 |
def on_mnu_preferences_activate(self, widget, data=None): |
|
92 |
"""Display the preferences window for qreator."""
|
|
93 |
||
94 |
""" From the PyGTK Reference manual
|
|
95 |
Say for example the preferences dialog is currently open,
|
|
96 |
and the user chooses Preferences from the menu a second time;
|
|
97 |
use the present() method to move the already-open dialog
|
|
98 |
where the user can see it."""
|
|
99 |
if self.preferences_dialog is not None: |
|
100 |
logger.debug('show existing preferences_dialog') |
|
101 |
self.preferences_dialog.present() |
|
102 |
elif self.PreferencesDialog is not None: |
|
103 |
logger.debug('create new preferences_dialog') |
|
104 |
self.preferences_dialog = self.PreferencesDialog() # pylint: disable=E1102 |
|
105 |
self.preferences_dialog.connect('destroy', self.on_preferences_dialog_destroyed) |
|
106 |
self.preferences_dialog.show() |
|
107 |
# destroy command moved into dialog to allow for a help button
|
|
108 |
||
1
by David Planella
Initial project creation with Quickly! |
109 |
def on_mnu_close_activate(self, widget, data=None): |
110 |
"""Signal handler for closing the QreatorWindow."""
|
|
111 |
self.destroy() |
|
112 |
||
113 |
def on_destroy(self, widget, data=None): |
|
114 |
"""Called when the QreatorWindow is closed."""
|
|
115 |
# Clean up code for saving application state should be added here.
|
|
116 |
Gtk.main_quit() |
|
117 |
||
86.1.5
by David Planella
Pre-upgrade checkpoint |
118 |
def on_preferences_changed(self, settings, key, data=None): |
119 |
logger.debug('preference changed: %s = %s' % (key, str(settings.get_value(key)))) |
|
120 |
||
121 |
def on_preferences_dialog_destroyed(self, widget, data=None): |
|
122 |
'''only affects gui
|
|
123 |
|
|
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 |
|
129 |