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