source: src/mlx/gui/common.py@ 224:6269b46d6740

Last change on this file since 224:6269b46d6740 was 221:2126271cea84, checked in by István Váradi <ivaradi@…>, 12 years ago

Implemented the PIREP viewer tabs for the comments and the log

File size: 7.8 KB
Line 
1# Common things for the GUI
2
3import mlx.const as _const
4from mlx.i18n import xstr
5
6import os
7
8appIndicator = False
9
10if os.name=="nt" or "FORCE_PYGTK" in os.environ:
11 print "Using PyGTK"
12 pygobject = False
13 import pygtk
14 import gtk.gdk as gdk
15 import gtk
16 import gobject
17 import pango
18 try:
19 import appindicator
20 appIndicator = True
21 except Exception, e:
22 pass
23
24 MESSAGETYPE_ERROR = gtk.MESSAGE_ERROR
25 MESSAGETYPE_QUESTION = gtk.MESSAGE_QUESTION
26 MESSAGETYPE_INFO = gtk.MESSAGE_INFO
27
28 RESPONSETYPE_OK = gtk.RESPONSE_OK
29 RESPONSETYPE_YES = gtk.RESPONSE_YES
30 RESPONSETYPE_NO = gtk.RESPONSE_NO
31 RESPONSETYPE_ACCEPT = gtk.RESPONSE_ACCEPT
32 RESPONSETYPE_REJECT = gtk.RESPONSE_REJECT
33 RESPONSETYPE_CANCEL = gtk.RESPONSE_CANCEL
34
35 ACCEL_VISIBLE = gtk.ACCEL_VISIBLE
36 CONTROL_MASK = gdk.CONTROL_MASK
37 DIALOG_MODAL = gtk.DIALOG_MODAL
38 WRAP_WORD = gtk.WRAP_WORD
39 JUSTIFY_CENTER = gtk.JUSTIFY_CENTER
40
41 CONTROL_MASK = gdk.CONTROL_MASK
42 SHIFT_MASK = gdk.SHIFT_MASK
43 BUTTON1_MASK = gdk.BUTTON1_MASK
44
45 SCROLL_UP = gdk.SCROLL_UP
46 SCROLL_DOWN = gdk.SCROLL_DOWN
47
48 SPIN_USER_DEFINED = gtk.SPIN_USER_DEFINED
49
50 FILE_CHOOSER_ACTION_SELECT_FOLDER = gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER
51 FILE_CHOOSER_ACTION_OPEN = gtk.FILE_CHOOSER_ACTION_OPEN
52 FILE_CHOOSER_ACTION_SAVE = gtk.FILE_CHOOSER_ACTION_SAVE
53
54 SELECTION_MULTIPLE = gtk.SELECTION_MULTIPLE
55
56 SHADOW_IN = gtk.SHADOW_IN
57
58 POLICY_AUTOMATIC = gtk.POLICY_AUTOMATIC
59
60 def text2unicode(text):
61 """Convert the given text, returned by a Gtk widget, to Unicode."""
62 return unicode(text)
63else:
64 print "Using PyGObject"
65 pygobject = True
66 from gi.repository import Gdk as gdk
67 from gi.repository import Gtk as gtk
68 from gi.repository import GObject as gobject
69 from gi.repository import AppIndicator3 as appindicator
70 from gi.repository import Pango as pango
71 appIndicator = True
72
73 MESSAGETYPE_ERROR = gtk.MessageType.ERROR
74 MESSAGETYPE_QUESTION = gtk.MessageType.QUESTION
75 MESSAGETYPE_INFO = gtk.MessageType.INFO
76 RESPONSETYPE_OK = gtk.ResponseType.OK
77 RESPONSETYPE_YES = gtk.ResponseType.YES
78 RESPONSETYPE_NO = gtk.ResponseType.NO
79 RESPONSETYPE_ACCEPT = gtk.ResponseType.ACCEPT
80 RESPONSETYPE_REJECT = gtk.ResponseType.REJECT
81 RESPONSETYPE_CANCEL = gtk.ResponseType.CANCEL
82 ACCEL_VISIBLE = gtk.AccelFlags.VISIBLE
83 CONTROL_MASK = gdk.ModifierType.CONTROL_MASK
84 DIALOG_MODAL = gtk.DialogFlags.MODAL
85 WRAP_WORD = gtk.WrapMode.WORD
86 JUSTIFY_CENTER = gtk.Justification.CENTER
87
88 CONTROL_MASK = gdk.ModifierType.CONTROL_MASK
89 SHIFT_MASK = gdk.ModifierType.SHIFT_MASK
90 BUTTON1_MASK = gdk.ModifierType.BUTTON1_MASK
91
92 SCROLL_UP = gdk.ScrollDirection.UP
93 SCROLL_DOWN = gdk.ScrollDirection.DOWN
94
95 SPIN_USER_DEFINED = gtk.SpinType.USER_DEFINED
96
97 FILE_CHOOSER_ACTION_SELECT_FOLDER = gtk.FileChooserAction.SELECT_FOLDER
98 FILE_CHOOSER_ACTION_OPEN = gtk.FileChooserAction.OPEN
99 FILE_CHOOSER_ACTION_SAVE = gtk.FileChooserAction.SAVE
100
101 SELECTION_MULTIPLE = gtk.SelectionMode.MULTIPLE
102
103 SHADOW_IN = gtk.ShadowType.IN
104
105 POLICY_AUTOMATIC = gtk.PolicyType.AUTOMATIC
106
107 import codecs
108 _utf8Decoder = codecs.getdecoder("utf-8")
109
110 def text2unicode(str):
111 """Convert the given text, returned by a Gtk widget, to Unicode."""
112 return _utf8Decoder(str)[0]
113
114import cairo
115
116#------------------------------------------------------------------------------
117
118class FlightStatusHandler(object):
119 """Base class for objects that handle the flight status in some way."""
120 def __init__(self):
121 self._stage = None
122 self._rating = 100
123 self._noGoReason = None
124
125 def resetFlightStatus(self):
126 """Reset the flight status."""
127 self._stage = None
128 self._rating = 100
129 self._noGoReason = None
130 self._updateFlightStatus()
131
132 def setStage(self, stage):
133 """Set the stage of the flight."""
134 if stage!=self._stage:
135 self._stage = stage
136 self._updateFlightStatus()
137
138 def setRating(self, rating):
139 """Set the rating to the given value."""
140 if rating!=self._rating:
141 self._rating = rating
142 if self._noGoReason is None:
143 self._updateFlightStatus()
144
145 def setNoGo(self, reason):
146 """Set a No-Go condition with the given reason."""
147 if self._noGoReason is None:
148 self._noGoReason = reason
149 self._updateFlightStatus()
150
151#------------------------------------------------------------------------------
152
153class IntegerEntry(gtk.Entry):
154 """An entry that allows only either an empty value, or an integer."""
155 def __init__(self, defaultValue = None):
156 """Construct the entry."""
157 gtk.Entry.__init__(self)
158
159 self.set_alignment(1.0)
160
161 self._defaultValue = defaultValue
162 self._currentInteger = defaultValue
163 self._selfSetting = False
164 self._set_text()
165
166 self.connect("changed", self._handle_changed)
167
168 def get_int(self):
169 """Get the integer."""
170 return self._currentInteger
171
172 def set_int(self, value):
173 """Set the integer."""
174 if value!=self._currentInteger:
175 self._currentInteger = value
176 self.emit("integer-changed", self._currentInteger)
177 self._set_text()
178
179 def _handle_changed(self, widget):
180 """Handle the changed signal."""
181 if self._selfSetting:
182 return
183 text = self.get_text()
184 if text=="":
185 self.set_int(self._defaultValue)
186 else:
187 try:
188 self.set_int(int(text))
189 except:
190 self._set_text()
191
192 def _set_text(self):
193 """Set the text value from the current integer."""
194 self._selfSetting = True
195 self.set_text("" if self._currentInteger is None
196 else str(self._currentInteger))
197 self._selfSetting = False
198
199#------------------------------------------------------------------------------
200
201gobject.signal_new("integer-changed", IntegerEntry, gobject.SIGNAL_RUN_FIRST,
202 None, (object,))
203
204#------------------------------------------------------------------------------
205
206WINDOW_TITLE_BASE = "MAVA Logger X " + _const.VERSION
207
208#------------------------------------------------------------------------------
209
210# A mapping of aircraft types to their screen names
211aircraftNames = { _const.AIRCRAFT_B736 : xstr("aircraft_b736"),
212 _const.AIRCRAFT_B737 : xstr("aircraft_b737"),
213 _const.AIRCRAFT_B738 : xstr("aircraft_b738"),
214 _const.AIRCRAFT_B738C : xstr("aircraft_b738c"),
215 _const.AIRCRAFT_B733 : xstr("aircraft_b733"),
216 _const.AIRCRAFT_B734 : xstr("aircraft_b734"),
217 _const.AIRCRAFT_B735 : xstr("aircraft_b735"),
218 _const.AIRCRAFT_DH8D : xstr("aircraft_dh8d"),
219 _const.AIRCRAFT_B762 : xstr("aircraft_b762"),
220 _const.AIRCRAFT_B763 : xstr("aircraft_b763"),
221 _const.AIRCRAFT_CRJ2 : xstr("aircraft_crj2"),
222 _const.AIRCRAFT_F70 : xstr("aircraft_f70"),
223 _const.AIRCRAFT_DC3 : xstr("aircraft_dc3"),
224 _const.AIRCRAFT_T134 : xstr("aircraft_t134"),
225 _const.AIRCRAFT_T154 : xstr("aircraft_t154"),
226 _const.AIRCRAFT_YK40 : xstr("aircraft_yk40") }
227
228#------------------------------------------------------------------------------
229
230def formatFlightLogLine(timeStr, line):
231 """Format the given flight log line."""
232 """Format the given line for flight logging."""
233 if timeStr is not None:
234 line = timeStr + ": " + line
235 return line + "\n"
236
237#------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.