source: src/mlx/gui/common.py@ 130:f3b2a892af5a

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

Enabled word wrapping in the comment fields

File size: 5.0 KB
Line 
1# Common things for the GUI
2
3import mlx.const as _const
4
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
13 import gtk.gdk as gdk
14 import gtk
15 import gobject
16 import pango
17 try:
18 import appindicator
19 appIndicator = True
20 except Exception, e:
21 pass
22
23 MESSAGETYPE_ERROR = gtk.MESSAGE_ERROR
24 MESSAGETYPE_QUESTION = gtk.MESSAGE_QUESTION
25 MESSAGETYPE_INFO = gtk.MESSAGE_INFO
26 RESPONSETYPE_OK = gtk.RESPONSE_OK
27 RESPONSETYPE_YES = gtk.RESPONSE_YES
28 RESPONSETYPE_NO = gtk.RESPONSE_NO
29 RESPONSETYPE_ACCEPT = gtk.RESPONSE_ACCEPT
30 RESPONSETYPE_REJECT = gtk.RESPONSE_REJECT
31 ACCEL_VISIBLE = gtk.ACCEL_VISIBLE
32 CONTROL_MASK = gdk.CONTROL_MASK
33 DIALOG_MODAL = gtk.DIALOG_MODAL
34 WRAP_WORD = gtk.WRAP_WORD
35
36 def text2unicode(text):
37 """Convert the given text, returned by a Gtk widget, to Unicode."""
38 return unicode(text)
39else:
40 print "Using PyGObject"
41 pygobject = True
42 from gi.repository import Gdk as gdk
43 from gi.repository import Gtk as gtk
44 from gi.repository import GObject as gobject
45 from gi.repository import AppIndicator3 as appindicator
46 from gi.repository import Pango as pango
47 appIndicator = True
48
49 MESSAGETYPE_ERROR = gtk.MessageType.ERROR
50 MESSAGETYPE_QUESTION = gtk.MessageType.QUESTION
51 MESSAGETYPE_INFO = gtk.MessageType.INFO
52 RESPONSETYPE_OK = gtk.ResponseType.OK
53 RESPONSETYPE_YES = gtk.ResponseType.YES
54 RESPONSETYPE_NO = gtk.ResponseType.NO
55 RESPONSETYPE_ACCEPT = gtk.ResponseType.ACCEPT
56 RESPONSETYPE_REJECT = gtk.ResponseType.REJECT
57 ACCEL_VISIBLE = gtk.AccelFlags.VISIBLE
58 CONTROL_MASK = gdk.ModifierType.CONTROL_MASK
59 DIALOG_MODAL = gtk.DialogFlags.MODAL
60 WRAP_WORD = gtk.WrapMode.WORD
61
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
69import cairo
70
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#------------------------------------------------------------------------------
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
114 self.set_alignment(1.0)
115
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#------------------------------------------------------------------------------
160
161WINDOW_TITLE_BASE = "MAVA Logger X " + _const.VERSION
162
163#------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.