source: src/mlx/gui/common.py@ 123:3b181cd0ab99

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

The Preferences dialog works

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