source: src/mlx/gui/common.py@ 124:6633722f7f86

Last change on this file since 124:6633722f7f86 was 124:6633722f7f86, checked in by István Váradi <ivaradi@…>, 13 years ago

The buttons are now explicitly defined for message dialogs to avoid language problems

File size: 4.9 KB
Line 
1# Common things for the GUI
2
3import mlx.const as _const
4
5import os
6
7appIndicator = False
8
9if os.name=="nt" or "FORCE_PYGTK" in os.environ:
10 print "Using PyGTK"
11 pygobject = False
12 import pygtk
13 import gtk.gdk as gdk
14 import gtk
15 import gobject
16 import pango
17 try:
18 import appindicator
19 appIndicator = True
20 except Exception, e:
21 pass
22
23 MESSAGETYPE_ERROR = gtk.MESSAGE_ERROR
24 MESSAGETYPE_QUESTION = gtk.MESSAGE_QUESTION
25 MESSAGETYPE_INFO = gtk.MESSAGE_INFO
26 RESPONSETYPE_OK = gtk.RESPONSE_OK
27 RESPONSETYPE_YES = gtk.RESPONSE_YES
28 RESPONSETYPE_NO = gtk.RESPONSE_NO
29 RESPONSETYPE_ACCEPT = gtk.RESPONSE_ACCEPT
30 RESPONSETYPE_REJECT = gtk.RESPONSE_REJECT
31 ACCEL_VISIBLE = gtk.ACCEL_VISIBLE
32 CONTROL_MASK = gdk.CONTROL_MASK
33 DIALOG_MODAL = gtk.DIALOG_MODAL
34
35 def text2unicode(text):
36 """Convert the given text, returned by a Gtk widget, to Unicode."""
37 return unicode(text)
38else:
39 print "Using PyGObject"
40 pygobject = True
41 from gi.repository import Gdk as gdk
42 from gi.repository import Gtk as gtk
43 from gi.repository import GObject as gobject
44 from gi.repository import AppIndicator3 as appindicator
45 from gi.repository import Pango as pango
46 appIndicator = True
47
48 MESSAGETYPE_ERROR = gtk.MessageType.ERROR
49 MESSAGETYPE_QUESTION = gtk.MessageType.QUESTION
50 MESSAGETYPE_INFO = gtk.MessageType.INFO
51 RESPONSETYPE_OK = gtk.ResponseType.OK
52 RESPONSETYPE_YES = gtk.ResponseType.YES
53 RESPONSETYPE_NO = gtk.ResponseType.NO
54 RESPONSETYPE_ACCEPT = gtk.ResponseType.ACCEPT
55 RESPONSETYPE_REJECT = gtk.ResponseType.REJECT
56 ACCEL_VISIBLE = gtk.AccelFlags.VISIBLE
57 CONTROL_MASK = gdk.ModifierType.CONTROL_MASK
58 DIALOG_MODAL = gtk.DialogFlags.MODAL
59
60 import codecs
61 _utf8Decoder = codecs.getdecoder("utf-8")
62
63 def text2unicode(str):
64 """Convert the given text, returned by a Gtk widget, to Unicode."""
65 return _utf8Decoder(str)[0]
66
67import cairo
68
69#------------------------------------------------------------------------------
70
71class FlightStatusHandler(object):
72 """Base class for objects that handle the flight status in some way."""
73 def __init__(self):
74 self._stage = None
75 self._rating = 100
76 self._noGoReason = None
77
78 def resetFlightStatus(self):
79 """Reset the flight status."""
80 self._stage = None
81 self._rating = 100
82 self._noGoReason = None
83 self._updateFlightStatus()
84
85 def setStage(self, stage):
86 """Set the stage of the flight."""
87 if stage!=self._stage:
88 self._stage = stage
89 self._updateFlightStatus()
90
91 def setRating(self, rating):
92 """Set the rating to the given value."""
93 if rating!=self._rating:
94 self._rating = rating
95 if self._noGoReason is None:
96 self._updateFlightStatus()
97
98 def setNoGo(self, reason):
99 """Set a No-Go condition with the given reason."""
100 if self._noGoReason is None:
101 self._noGoReason = reason
102 self._updateFlightStatus()
103
104#------------------------------------------------------------------------------
105
106class IntegerEntry(gtk.Entry):
107 """An entry that allows only either an empty value, or an integer."""
108 def __init__(self, defaultValue = None):
109 """Construct the entry."""
110 gtk.Entry.__init__(self)
111
112 self.set_alignment(1.0)
113
114 self._defaultValue = defaultValue
115 self._currentInteger = defaultValue
116 self._selfSetting = False
117 self._set_text()
118
119 self.connect("changed", self._handle_changed)
120
121 def get_int(self):
122 """Get the integer."""
123 return self._currentInteger
124
125 def set_int(self, value):
126 """Set the integer."""
127 if value!=self._currentInteger:
128 self._currentInteger = value
129 self.emit("integer-changed", self._currentInteger)
130 self._set_text()
131
132 def _handle_changed(self, widget):
133 """Handle the changed signal."""
134 if self._selfSetting:
135 return
136 text = self.get_text()
137 if text=="":
138 self.set_int(self._defaultValue)
139 else:
140 try:
141 self.set_int(int(text))
142 except:
143 self._set_text()
144
145 def _set_text(self):
146 """Set the text value from the current integer."""
147 self._selfSetting = True
148 self.set_text("" if self._currentInteger is None
149 else str(self._currentInteger))
150 self._selfSetting = False
151
152#------------------------------------------------------------------------------
153
154gobject.signal_new("integer-changed", IntegerEntry, gobject.SIGNAL_RUN_FIRST,
155 None, (object,))
156
157#------------------------------------------------------------------------------
158
159WINDOW_TITLE_BASE = "MAVA Logger X " + _const.VERSION
160
161#------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.