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