source: src/mlx/gui/common.py@ 150:0a6ffbd72d7e

Last change on this file since 150:0a6ffbd72d7e was 149:aab353620d1c, checked in by István Váradi <ivaradi@…>, 13 years ago

Added the handling of the PIREP directory preference

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