source: src/mlx/gui/common.py@ 86:285443d1c1e2

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

The IntegerEntry widget is used for the VRef as well on the landing page

File size: 3.9 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 BUTTONSTYPE_OK = gtk.BUTTONS_OK
24 BUTTONSTYPE_YES_NO = gtk.BUTTONS_YES_NO
25 RESPONSETYPE_YES = gtk.RESPONSE_YES
26else:
27 print "Using PyGObject"
28 pygobject = True
29 from gi.repository import Gdk as gdk
30 from gi.repository import Gtk as gtk
31 from gi.repository import GObject as gobject
32 from gi.repository import AppIndicator3 as appindicator
33 from gi.repository import Pango as pango
34 appIndicator = True
35
36 MESSAGETYPE_ERROR = gtk.MessageType.ERROR
37 MESSAGETYPE_QUESTION = gtk.MessageType.QUESTION
38 BUTTONSTYPE_OK = gtk.ButtonsType.OK
39 BUTTONSTYPE_YES_NO = gtk.ButtonsType.YES_NO
40 RESPONSETYPE_YES = gtk.ResponseType.YES
41
42import cairo
43
44#------------------------------------------------------------------------------
45
46class FlightStatusHandler(object):
47 """Base class for objects that handle the flight status in some way."""
48 def __init__(self):
49 self._stage = None
50 self._rating = 100
51 self._noGoReason = None
52
53 def resetFlightStatus(self):
54 """Reset the flight status."""
55 self._stage = None
56 self._rating = 100
57 self._noGoReason = None
58 self._updateFlightStatus()
59
60 def setStage(self, stage):
61 """Set the stage of the flight."""
62 if stage!=self._stage:
63 self._stage = stage
64 self._updateFlightStatus()
65
66 def setRating(self, rating):
67 """Set the rating to the given value."""
68 if rating!=self._rating:
69 self._rating = rating
70 if self._noGoReason is None:
71 self._updateFlightStatus()
72
73 def setNoGo(self, reason):
74 """Set a No-Go condition with the given reason."""
75 if self._noGoReason is None:
76 self._noGoReason = reason
77 self._updateFlightStatus()
78
79#------------------------------------------------------------------------------
80
81class IntegerEntry(gtk.Entry):
82 """An entry that allows only either an empty value, or an integer."""
83 def __init__(self, defaultValue = None):
84 """Construct the entry."""
85 gtk.Entry.__init__(self)
86
87 self.set_alignment(1.0)
88
89 self._defaultValue = defaultValue
90 self._currentInteger = defaultValue
91 self._selfSetting = False
92 self._set_text()
93
94 self.connect("changed", self._handle_changed)
95
96 def get_int(self):
97 """Get the integer."""
98 return self._currentInteger
99
100 def set_int(self, value):
101 """Set the integer."""
102 if value!=self._currentInteger:
103 self._currentInteger = value
104 self.emit("integer-changed", self._currentInteger)
105 self._set_text()
106
107 def _handle_changed(self, widget):
108 """Handle the changed signal."""
109 if self._selfSetting:
110 return
111 text = self.get_text()
112 if text=="":
113 self.set_int(self._defaultValue)
114 else:
115 try:
116 self.set_int(int(text))
117 except:
118 self._set_text()
119
120 def _set_text(self):
121 """Set the text value from the current integer."""
122 self._selfSetting = True
123 self.set_text("" if self._currentInteger is None
124 else str(self._currentInteger))
125 self._selfSetting = False
126
127#------------------------------------------------------------------------------
128
129gobject.signal_new("integer-changed", IntegerEntry, gobject.SIGNAL_RUN_FIRST,
130 None, (object,))
131
132#------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.