source: src/mlx/gui/common.py@ 132:92f78dc5b965

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

Added support for enabling/disabling message types

File size: 5.1 KB
RevLine 
[28]1# Common things for the GUI
2
[105]3import mlx.const as _const
4
[28]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
[29]13 import gtk.gdk as gdk
[28]14 import gtk
15 import gobject
[44]16 import pango
[28]17 try:
18 import appindicator
19 appIndicator = True
20 except Exception, e:
21 pass
[42]22
23 MESSAGETYPE_ERROR = gtk.MESSAGE_ERROR
[76]24 MESSAGETYPE_QUESTION = gtk.MESSAGE_QUESTION
[97]25 MESSAGETYPE_INFO = gtk.MESSAGE_INFO
[124]26 RESPONSETYPE_OK = gtk.RESPONSE_OK
[76]27 RESPONSETYPE_YES = gtk.RESPONSE_YES
[124]28 RESPONSETYPE_NO = gtk.RESPONSE_NO
[123]29 RESPONSETYPE_ACCEPT = gtk.RESPONSE_ACCEPT
30 RESPONSETYPE_REJECT = gtk.RESPONSE_REJECT
[93]31 ACCEL_VISIBLE = gtk.ACCEL_VISIBLE
32 CONTROL_MASK = gdk.CONTROL_MASK
[123]33 DIALOG_MODAL = gtk.DIALOG_MODAL
[127]34 WRAP_WORD = gtk.WRAP_WORD
[132]35 JUSTIFY_CENTER = gtk.JUSTIFY_CENTER
[97]36
37 def text2unicode(text):
38 """Convert the given text, returned by a Gtk widget, to Unicode."""
39 return unicode(text)
[28]40else:
41 print "Using PyGObject"
42 pygobject = True
[29]43 from gi.repository import Gdk as gdk
[28]44 from gi.repository import Gtk as gtk
45 from gi.repository import GObject as gobject
46 from gi.repository import AppIndicator3 as appindicator
[44]47 from gi.repository import Pango as pango
[28]48 appIndicator = True
[76]49
[42]50 MESSAGETYPE_ERROR = gtk.MessageType.ERROR
[76]51 MESSAGETYPE_QUESTION = gtk.MessageType.QUESTION
[97]52 MESSAGETYPE_INFO = gtk.MessageType.INFO
[124]53 RESPONSETYPE_OK = gtk.ResponseType.OK
[76]54 RESPONSETYPE_YES = gtk.ResponseType.YES
[124]55 RESPONSETYPE_NO = gtk.ResponseType.NO
[123]56 RESPONSETYPE_ACCEPT = gtk.ResponseType.ACCEPT
57 RESPONSETYPE_REJECT = gtk.ResponseType.REJECT
[93]58 ACCEL_VISIBLE = gtk.AccelFlags.VISIBLE
59 CONTROL_MASK = gdk.ModifierType.CONTROL_MASK
[123]60 DIALOG_MODAL = gtk.DialogFlags.MODAL
[127]61 WRAP_WORD = gtk.WrapMode.WORD
[132]62 JUSTIFY_CENTER = gtk.Justification.CENTER
[42]63
[97]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
[28]71import cairo
72
[32]73#------------------------------------------------------------------------------
74
75class 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#------------------------------------------------------------------------------
[84]109
110class 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
[86]116 self.set_alignment(1.0)
117
[84]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
158gobject.signal_new("integer-changed", IntegerEntry, gobject.SIGNAL_RUN_FIRST,
159 None, (object,))
160
161#------------------------------------------------------------------------------
[105]162
163WINDOW_TITLE_BASE = "MAVA Logger X " + _const.VERSION
164
165#------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.