source: src/mlx/gui/common.py@ 97:f885322fb296

Last change on this file since 97:f885322fb296 was 97:f885322fb296, checked in by István Váradi <ivaradi@…>, 12 years ago

The PIREP can be created and sent.

File size: 4.5 KB
Line 
1# Common things for the GUI
2
3import os
4
5appIndicator = False
6
7if os.name=="nt" or "FORCE_PYGTK" in os.environ:
8 print "Using PyGTK"
9 pygobject = False
10 import pygtk
11 import gtk.gdk as gdk
12 import gtk
13 import gobject
14 import pango
15 try:
16 import appindicator
17 appIndicator = True
18 except Exception, e:
19 pass
20
21 MESSAGETYPE_ERROR = gtk.MESSAGE_ERROR
22 MESSAGETYPE_QUESTION = gtk.MESSAGE_QUESTION
23 MESSAGETYPE_INFO = gtk.MESSAGE_INFO
24 BUTTONSTYPE_OK = gtk.BUTTONS_OK
25 BUTTONSTYPE_YES_NO = gtk.BUTTONS_YES_NO
26 RESPONSETYPE_YES = gtk.RESPONSE_YES
27 ACCEL_VISIBLE = gtk.ACCEL_VISIBLE
28 CONTROL_MASK = gdk.CONTROL_MASK
29
30 def text2unicode(text):
31 """Convert the given text, returned by a Gtk widget, to Unicode."""
32 return unicode(text)
33else:
34 print "Using PyGObject"
35 pygobject = True
36 from gi.repository import Gdk as gdk
37 from gi.repository import Gtk as gtk
38 from gi.repository import GObject as gobject
39 from gi.repository import AppIndicator3 as appindicator
40 from gi.repository import Pango as pango
41 appIndicator = True
42
43 MESSAGETYPE_ERROR = gtk.MessageType.ERROR
44 MESSAGETYPE_QUESTION = gtk.MessageType.QUESTION
45 MESSAGETYPE_INFO = gtk.MessageType.INFO
46 BUTTONSTYPE_OK = gtk.ButtonsType.OK
47 BUTTONSTYPE_YES_NO = gtk.ButtonsType.YES_NO
48 RESPONSETYPE_YES = gtk.ResponseType.YES
49 ACCEL_VISIBLE = gtk.AccelFlags.VISIBLE
50 CONTROL_MASK = gdk.ModifierType.CONTROL_MASK
51
52 import codecs
53 _utf8Decoder = codecs.getdecoder("utf-8")
54
55 def text2unicode(str):
56 """Convert the given text, returned by a Gtk widget, to Unicode."""
57 return _utf8Decoder(str)[0]
58
59import cairo
60
61#------------------------------------------------------------------------------
62
63class FlightStatusHandler(object):
64 """Base class for objects that handle the flight status in some way."""
65 def __init__(self):
66 self._stage = None
67 self._rating = 100
68 self._noGoReason = None
69
70 def resetFlightStatus(self):
71 """Reset the flight status."""
72 self._stage = None
73 self._rating = 100
74 self._noGoReason = None
75 self._updateFlightStatus()
76
77 def setStage(self, stage):
78 """Set the stage of the flight."""
79 if stage!=self._stage:
80 self._stage = stage
81 self._updateFlightStatus()
82
83 def setRating(self, rating):
84 """Set the rating to the given value."""
85 if rating!=self._rating:
86 self._rating = rating
87 if self._noGoReason is None:
88 self._updateFlightStatus()
89
90 def setNoGo(self, reason):
91 """Set a No-Go condition with the given reason."""
92 if self._noGoReason is None:
93 self._noGoReason = reason
94 self._updateFlightStatus()
95
96#------------------------------------------------------------------------------
97
98class IntegerEntry(gtk.Entry):
99 """An entry that allows only either an empty value, or an integer."""
100 def __init__(self, defaultValue = None):
101 """Construct the entry."""
102 gtk.Entry.__init__(self)
103
104 self.set_alignment(1.0)
105
106 self._defaultValue = defaultValue
107 self._currentInteger = defaultValue
108 self._selfSetting = False
109 self._set_text()
110
111 self.connect("changed", self._handle_changed)
112
113 def get_int(self):
114 """Get the integer."""
115 return self._currentInteger
116
117 def set_int(self, value):
118 """Set the integer."""
119 if value!=self._currentInteger:
120 self._currentInteger = value
121 self.emit("integer-changed", self._currentInteger)
122 self._set_text()
123
124 def _handle_changed(self, widget):
125 """Handle the changed signal."""
126 if self._selfSetting:
127 return
128 text = self.get_text()
129 if text=="":
130 self.set_int(self._defaultValue)
131 else:
132 try:
133 self.set_int(int(text))
134 except:
135 self._set_text()
136
137 def _set_text(self):
138 """Set the text value from the current integer."""
139 self._selfSetting = True
140 self.set_text("" if self._currentInteger is None
141 else str(self._currentInteger))
142 self._selfSetting = False
143
144#------------------------------------------------------------------------------
145
146gobject.signal_new("integer-changed", IntegerEntry, gobject.SIGNAL_RUN_FIRST,
147 None, (object,))
148
149#------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.