source: src/mlx/gui/common.py@ 127:6141f30a2060

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

Enabled word wrapping in the comment fields

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