2
# Copyright 2010 Martin Owens
4
# This program is free software: you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation, either version 3 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program. If not, see <http://www.gnu.org/licenses/>
18
Sets up some common gtk windows for generic use.
25
from GroundControl.gtkviews import ThreadedWindow, GtkApp, Window, ChildWindow
27
class StatusWindow(ThreadedWindow):
28
"""Display a status bar to the user"""
29
name = 'status_window'
31
def load(self, *args, **kwargs):
32
"""Load our status window"""
33
# hopefully filter out variables
34
self.gapp.load_vars(args, kwargs)
35
self.window.set_title(self.gapp.task_name)
37
self._close_thread = False
38
super(StatusWindow, self).load(*args, **kwargs)
40
def inital_thread(self):
41
"""Pass on the action"""
44
def thread_exited(self):
45
"""What to do when a thread exits"""
49
def update(self, value=None, name=None, transport=None):
50
"""Update gtk after some time"""
51
# Update our progress bar and make sure the widgets still exist
52
if name and self.widget('label'):
53
self.widget('label').set_markup('<b>%s</b>' % name)
54
if value != None and self.widget('progress'):
55
self.widget('progress').set_fraction(value)
56
if self.widget('transport'):
58
self.widget('transport').set_text(transport)
60
self.widget('transport').set_text('')
62
def pop_error(self, error, title=None):
63
"""Popup a Gtk Error message box of some kind"""
64
PopupApp(title=unicode(title), message=unicode(error))
67
class PromptWindow(ChildWindow):
68
"""A simple prompt window"""
71
def load(self, title, label):
72
"""what to do when we load"""
73
self.window.set_title(title)
74
self.widget('label').set_text(label)
77
"""Hold the prompt until answered"""
83
class StatusApp(GtkApp):
84
"""An application for showing any status"""
85
gtkfile = 'common.glade'
86
windows = [ StatusWindow, PromptWindow ]
87
task_name = _("Unknown Action")
89
def do_work(self, *args, **kwargs):
90
"""Replace this method in your own status updates"""
91
raise NotImplimentedError("Replace do_work in your status window")
94
"""Strip out any useful variables for the status window"""
95
# This is a bit of a juggling act, perhaps someone has a better idea
96
# That we can move towards for this.
101
"""Return the status window"""
102
# Get the right window by name, more than one window could be loaded
103
return self._loaded['status_window']
105
def update(self, *args, **kwargs):
106
"""Pass an update call back to the window in a thread friendly way"""
107
# We're going to make sure that updates don't collide
108
kwargs['unique_call'] = True
109
# Now call the threaded caller to do an update
110
self.window.call('update', *args, **kwargs )
112
def pop_error(self, title, error):
113
"""Call window's creation of popup windows"""
114
return self.window.call('pop_error', error, title)
116
class PopupWindow(Window):
117
"""A simple popup warning window"""
120
def load(self, *args, **kwargs):
121
"""Load the title, icon"""
122
self.window.set_title(kwargs.pop('title', _('Message!')))
123
message = kwargs.pop('message')
124
logging.error(message)
125
self.widget('label').set_text(message)
126
super(PopupWindow, self).load(*args, **kwargs)
129
class PopupApp(GtkApp):
130
"""An application for showing any status"""
131
gtkfile = 'common-popup.glade'
132
windows = [ PopupWindow ]