source: src/mlx/gui/common.py@ 144:3c7d3b02a0be

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

Further enhanced the fuel widget.

File size: 5.5 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 WRAP_WORD = gtk.WRAP_WORD
35 JUSTIFY_CENTER = gtk.JUSTIFY_CENTER
36
37 CONTROL_MASK = gdk.CONTROL_MASK
38 SHIFT_MASK = gdk.SHIFT_MASK
39 BUTTON1_MASK = gdk.BUTTON1_MASK
40
41 SCROLL_UP = gdk.SCROLL_UP
42 SCROLL_DOWN = gdk.SCROLL_DOWN
43
44 SPIN_USER_DEFINED = gtk.SPIN_USER_DEFINED
45
46 def text2unicode(text):
47 """Convert the given text, returned by a Gtk widget, to Unicode."""
48 return unicode(text)
49else:
50 print "Using PyGObject"
51 pygobject = True
52 from gi.repository import Gdk as gdk
53 from gi.repository import Gtk as gtk
54 from gi.repository import GObject as gobject
55 from gi.repository import AppIndicator3 as appindicator
56 from gi.repository import Pango as pango
57 appIndicator = True
58
59 MESSAGETYPE_ERROR = gtk.MessageType.ERROR
60 MESSAGETYPE_QUESTION = gtk.MessageType.QUESTION
61 MESSAGETYPE_INFO = gtk.MessageType.INFO
62 RESPONSETYPE_OK = gtk.ResponseType.OK
63 RESPONSETYPE_YES = gtk.ResponseType.YES
64 RESPONSETYPE_NO = gtk.ResponseType.NO
65 RESPONSETYPE_ACCEPT = gtk.ResponseType.ACCEPT
66 RESPONSETYPE_REJECT = gtk.ResponseType.REJECT
67 ACCEL_VISIBLE = gtk.AccelFlags.VISIBLE
68 CONTROL_MASK = gdk.ModifierType.CONTROL_MASK
69 DIALOG_MODAL = gtk.DialogFlags.MODAL
70 WRAP_WORD = gtk.WrapMode.WORD
71 JUSTIFY_CENTER = gtk.Justification.CENTER
72
73 CONTROL_MASK = gdk.ModifierType.CONTROL_MASK
74 SHIFT_MASK = gdk.ModifierType.SHIFT_MASK
75 BUTTON1_MASK = gdk.ModifierType.BUTTON1_MASK
76
77 SCROLL_UP = gdk.ScrollDirection.UP
78 SCROLL_DOWN = gdk.ScrollDirection.DOWN
79
80 SPIN_USER_DEFINED = gtk.SpinType.USER_DEFINED
81
82 import codecs
83 _utf8Decoder = codecs.getdecoder("utf-8")
84
85 def text2unicode(str):
86 """Convert the given text, returned by a Gtk widget, to Unicode."""
87 return _utf8Decoder(str)[0]
88
89import cairo
90
91#------------------------------------------------------------------------------
92
93class FlightStatusHandler(object):
94 """Base class for objects that handle the flight status in some way."""
95 def __init__(self):
96 self._stage = None
97 self._rating = 100
98 self._noGoReason = None
99
100 def resetFlightStatus(self):
101 """Reset the flight status."""
102 self._stage = None
103 self._rating = 100
104 self._noGoReason = None
105 self._updateFlightStatus()
106
107 def setStage(self, stage):
108 """Set the stage of the flight."""
109 if stage!=self._stage:
110 self._stage = stage
111 self._updateFlightStatus()
112
113 def setRating(self, rating):
114 """Set the rating to the given value."""
115 if rating!=self._rating:
116 self._rating = rating
117 if self._noGoReason is None:
118 self._updateFlightStatus()
119
120 def setNoGo(self, reason):
121 """Set a No-Go condition with the given reason."""
122 if self._noGoReason is None:
123 self._noGoReason = reason
124 self._updateFlightStatus()
125
126#------------------------------------------------------------------------------
127
128class IntegerEntry(gtk.Entry):
129 """An entry that allows only either an empty value, or an integer."""
130 def __init__(self, defaultValue = None):
131 """Construct the entry."""
132 gtk.Entry.__init__(self)
133
134 self.set_alignment(1.0)
135
136 self._defaultValue = defaultValue
137 self._currentInteger = defaultValue
138 self._selfSetting = False
139 self._set_text()
140
141 self.connect("changed", self._handle_changed)
142
143 def get_int(self):
144 """Get the integer."""
145 return self._currentInteger
146
147 def set_int(self, value):
148 """Set the integer."""
149 if value!=self._currentInteger:
150 self._currentInteger = value
151 self.emit("integer-changed", self._currentInteger)
152 self._set_text()
153
154 def _handle_changed(self, widget):
155 """Handle the changed signal."""
156 if self._selfSetting:
157 return
158 text = self.get_text()
159 if text=="":
160 self.set_int(self._defaultValue)
161 else:
162 try:
163 self.set_int(int(text))
164 except:
165 self._set_text()
166
167 def _set_text(self):
168 """Set the text value from the current integer."""
169 self._selfSetting = True
170 self.set_text("" if self._currentInteger is None
171 else str(self._currentInteger))
172 self._selfSetting = False
173
174#------------------------------------------------------------------------------
175
176gobject.signal_new("integer-changed", IntegerEntry, gobject.SIGNAL_RUN_FIRST,
177 None, (object,))
178
179#------------------------------------------------------------------------------
180
181WINDOW_TITLE_BASE = "MAVA Logger X " + _const.VERSION
182
183#------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.