source: src/mlx/gui/common.py@ 119:0185f1446770

Last change on this file since 119:0185f1446770 was 105:d1c3dd71da77, checked in by István Váradi <ivaradi@…>, 13 years ago

The dialogs now have a proper parent window and title

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