source: src/mlx/gui/common.py@ 178:98121552b435

Last change on this file since 178:98121552b435 was 175:6db038066dec, checked in by István Váradi <ivaradi@…>, 13 years ago

Checklist saving/restoring and editing is implemented

File size: 7.2 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 def text2unicode(text):
57 """Convert the given text, returned by a Gtk widget, to Unicode."""
58 return unicode(text)
59else:
60 print "Using PyGObject"
61 pygobject = True
62 from gi.repository import Gdk as gdk
63 from gi.repository import Gtk as gtk
64 from gi.repository import GObject as gobject
65 from gi.repository import AppIndicator3 as appindicator
66 from gi.repository import Pango as pango
67 appIndicator = True
68
69 MESSAGETYPE_ERROR = gtk.MessageType.ERROR
70 MESSAGETYPE_QUESTION = gtk.MessageType.QUESTION
71 MESSAGETYPE_INFO = gtk.MessageType.INFO
72 RESPONSETYPE_OK = gtk.ResponseType.OK
73 RESPONSETYPE_YES = gtk.ResponseType.YES
74 RESPONSETYPE_NO = gtk.ResponseType.NO
75 RESPONSETYPE_ACCEPT = gtk.ResponseType.ACCEPT
76 RESPONSETYPE_REJECT = gtk.ResponseType.REJECT
77 RESPONSETYPE_CANCEL = gtk.ResponseType.CANCEL
78 ACCEL_VISIBLE = gtk.AccelFlags.VISIBLE
79 CONTROL_MASK = gdk.ModifierType.CONTROL_MASK
80 DIALOG_MODAL = gtk.DialogFlags.MODAL
81 WRAP_WORD = gtk.WrapMode.WORD
82 JUSTIFY_CENTER = gtk.Justification.CENTER
83
84 CONTROL_MASK = gdk.ModifierType.CONTROL_MASK
85 SHIFT_MASK = gdk.ModifierType.SHIFT_MASK
86 BUTTON1_MASK = gdk.ModifierType.BUTTON1_MASK
87
88 SCROLL_UP = gdk.ScrollDirection.UP
89 SCROLL_DOWN = gdk.ScrollDirection.DOWN
90
91 SPIN_USER_DEFINED = gtk.SpinType.USER_DEFINED
92
93 FILE_CHOOSER_ACTION_SELECT_FOLDER = gtk.FileChooserAction.SELECT_FOLDER
94 FILE_CHOOSER_ACTION_OPEN = gtk.FileChooserAction.OPEN
95 FILE_CHOOSER_ACTION_SAVE = gtk.FileChooserAction.SAVE
96
97 SELECTION_MULTIPLE = gtk.SelectionMode.MULTIPLE
98
99 import codecs
100 _utf8Decoder = codecs.getdecoder("utf-8")
101
102 def text2unicode(str):
103 """Convert the given text, returned by a Gtk widget, to Unicode."""
104 return _utf8Decoder(str)[0]
105
106import cairo
107
108#------------------------------------------------------------------------------
109
110class FlightStatusHandler(object):
111 """Base class for objects that handle the flight status in some way."""
112 def __init__(self):
113 self._stage = None
114 self._rating = 100
115 self._noGoReason = None
116
117 def resetFlightStatus(self):
118 """Reset the flight status."""
119 self._stage = None
120 self._rating = 100
121 self._noGoReason = None
122 self._updateFlightStatus()
123
124 def setStage(self, stage):
125 """Set the stage of the flight."""
126 if stage!=self._stage:
127 self._stage = stage
128 self._updateFlightStatus()
129
130 def setRating(self, rating):
131 """Set the rating to the given value."""
132 if rating!=self._rating:
133 self._rating = rating
134 if self._noGoReason is None:
135 self._updateFlightStatus()
136
137 def setNoGo(self, reason):
138 """Set a No-Go condition with the given reason."""
139 if self._noGoReason is None:
140 self._noGoReason = reason
141 self._updateFlightStatus()
142
143#------------------------------------------------------------------------------
144
145class IntegerEntry(gtk.Entry):
146 """An entry that allows only either an empty value, or an integer."""
147 def __init__(self, defaultValue = None):
148 """Construct the entry."""
149 gtk.Entry.__init__(self)
150
151 self.set_alignment(1.0)
152
153 self._defaultValue = defaultValue
154 self._currentInteger = defaultValue
155 self._selfSetting = False
156 self._set_text()
157
158 self.connect("changed", self._handle_changed)
159
160 def get_int(self):
161 """Get the integer."""
162 return self._currentInteger
163
164 def set_int(self, value):
165 """Set the integer."""
166 if value!=self._currentInteger:
167 self._currentInteger = value
168 self.emit("integer-changed", self._currentInteger)
169 self._set_text()
170
171 def _handle_changed(self, widget):
172 """Handle the changed signal."""
173 if self._selfSetting:
174 return
175 text = self.get_text()
176 if text=="":
177 self.set_int(self._defaultValue)
178 else:
179 try:
180 self.set_int(int(text))
181 except:
182 self._set_text()
183
184 def _set_text(self):
185 """Set the text value from the current integer."""
186 self._selfSetting = True
187 self.set_text("" if self._currentInteger is None
188 else str(self._currentInteger))
189 self._selfSetting = False
190
191#------------------------------------------------------------------------------
192
193gobject.signal_new("integer-changed", IntegerEntry, gobject.SIGNAL_RUN_FIRST,
194 None, (object,))
195
196#------------------------------------------------------------------------------
197
198WINDOW_TITLE_BASE = "MAVA Logger X " + _const.VERSION
199
200#------------------------------------------------------------------------------
201
202# A mapping of aircraft types to their screen names
203aircraftNames = { _const.AIRCRAFT_B736 : xstr("aircraft_b736"),
204 _const.AIRCRAFT_B737 : xstr("aircraft_b737"),
205 _const.AIRCRAFT_B738 : xstr("aircraft_b738"),
206 _const.AIRCRAFT_B733 : xstr("aircraft_b733"),
207 _const.AIRCRAFT_B734 : xstr("aircraft_b734"),
208 _const.AIRCRAFT_B735 : xstr("aircraft_b735"),
209 _const.AIRCRAFT_DH8D : xstr("aircraft_dh8d"),
210 _const.AIRCRAFT_B762 : xstr("aircraft_b762"),
211 _const.AIRCRAFT_B763 : xstr("aircraft_b763"),
212 _const.AIRCRAFT_CRJ2 : xstr("aircraft_crj2"),
213 _const.AIRCRAFT_F70 : xstr("aircraft_f70"),
214 _const.AIRCRAFT_DC3 : xstr("aircraft_dc3"),
215 _const.AIRCRAFT_T134 : xstr("aircraft_t134"),
216 _const.AIRCRAFT_T154 : xstr("aircraft_t154"),
217 _const.AIRCRAFT_YK40 : xstr("aircraft_yk40") }
218
219#------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.