source: src/mlx/gui/common.py@ 95:d941f0f18648

Last change on this file since 95:d941f0f18648 was 93:fbcbfa72cdb2, checked in by István Váradi <ivaradi@…>, 13 years ago

Implemented the beginnings of the main menu and the separate debug log tab

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