[28] | 1 | # Common things for the GUI
|
---|
| 2 |
|
---|
| 3 | import os
|
---|
| 4 |
|
---|
| 5 | appIndicator = False
|
---|
| 6 |
|
---|
| 7 | if os.name=="nt" or "FORCE_PYGTK" in os.environ:
|
---|
| 8 | print "Using PyGTK"
|
---|
| 9 | pygobject = False
|
---|
| 10 | import pygtk
|
---|
[29] | 11 | import gtk.gdk as gdk
|
---|
[28] | 12 | import gtk
|
---|
| 13 | import gobject
|
---|
[44] | 14 | import pango
|
---|
[28] | 15 | try:
|
---|
| 16 | import appindicator
|
---|
| 17 | appIndicator = True
|
---|
| 18 | except Exception, e:
|
---|
| 19 | pass
|
---|
[42] | 20 |
|
---|
| 21 | MESSAGETYPE_ERROR = gtk.MESSAGE_ERROR
|
---|
[76] | 22 | MESSAGETYPE_QUESTION = gtk.MESSAGE_QUESTION
|
---|
[42] | 23 | BUTTONSTYPE_OK = gtk.BUTTONS_OK
|
---|
[76] | 24 | BUTTONSTYPE_YES_NO = gtk.BUTTONS_YES_NO
|
---|
| 25 | RESPONSETYPE_YES = gtk.RESPONSE_YES
|
---|
[28] | 26 | else:
|
---|
| 27 | print "Using PyGObject"
|
---|
| 28 | pygobject = True
|
---|
[29] | 29 | from gi.repository import Gdk as gdk
|
---|
[28] | 30 | from gi.repository import Gtk as gtk
|
---|
| 31 | from gi.repository import GObject as gobject
|
---|
| 32 | from gi.repository import AppIndicator3 as appindicator
|
---|
[44] | 33 | from gi.repository import Pango as pango
|
---|
[28] | 34 | appIndicator = True
|
---|
[76] | 35 |
|
---|
[42] | 36 | MESSAGETYPE_ERROR = gtk.MessageType.ERROR
|
---|
[76] | 37 | MESSAGETYPE_QUESTION = gtk.MessageType.QUESTION
|
---|
[42] | 38 | BUTTONSTYPE_OK = gtk.ButtonsType.OK
|
---|
[76] | 39 | BUTTONSTYPE_YES_NO = gtk.ButtonsType.YES_NO
|
---|
| 40 | RESPONSETYPE_YES = gtk.ResponseType.YES
|
---|
[42] | 41 |
|
---|
[28] | 42 | import cairo
|
---|
| 43 |
|
---|
[32] | 44 | #------------------------------------------------------------------------------
|
---|
| 45 |
|
---|
| 46 | class FlightStatusHandler(object):
|
---|
| 47 | """Base class for objects that handle the flight status in some way."""
|
---|
| 48 | def __init__(self):
|
---|
| 49 | self._stage = None
|
---|
| 50 | self._rating = 100
|
---|
| 51 | self._noGoReason = None
|
---|
| 52 |
|
---|
| 53 | def resetFlightStatus(self):
|
---|
| 54 | """Reset the flight status."""
|
---|
| 55 | self._stage = None
|
---|
| 56 | self._rating = 100
|
---|
| 57 | self._noGoReason = None
|
---|
| 58 | self._updateFlightStatus()
|
---|
| 59 |
|
---|
| 60 | def setStage(self, stage):
|
---|
| 61 | """Set the stage of the flight."""
|
---|
| 62 | if stage!=self._stage:
|
---|
| 63 | self._stage = stage
|
---|
| 64 | self._updateFlightStatus()
|
---|
| 65 |
|
---|
| 66 | def setRating(self, rating):
|
---|
| 67 | """Set the rating to the given value."""
|
---|
| 68 | if rating!=self._rating:
|
---|
| 69 | self._rating = rating
|
---|
| 70 | if self._noGoReason is None:
|
---|
| 71 | self._updateFlightStatus()
|
---|
| 72 |
|
---|
| 73 | def setNoGo(self, reason):
|
---|
| 74 | """Set a No-Go condition with the given reason."""
|
---|
| 75 | if self._noGoReason is None:
|
---|
| 76 | self._noGoReason = reason
|
---|
| 77 | self._updateFlightStatus()
|
---|
| 78 |
|
---|
| 79 | #------------------------------------------------------------------------------
|
---|
[84] | 80 |
|
---|
| 81 | class IntegerEntry(gtk.Entry):
|
---|
| 82 | """An entry that allows only either an empty value, or an integer."""
|
---|
| 83 | def __init__(self, defaultValue = None):
|
---|
| 84 | """Construct the entry."""
|
---|
| 85 | gtk.Entry.__init__(self)
|
---|
| 86 |
|
---|
| 87 | self._defaultValue = defaultValue
|
---|
| 88 | self._currentInteger = defaultValue
|
---|
| 89 | self._selfSetting = False
|
---|
| 90 | self._set_text()
|
---|
| 91 |
|
---|
| 92 | self.connect("changed", self._handle_changed)
|
---|
| 93 |
|
---|
| 94 | def get_int(self):
|
---|
| 95 | """Get the integer."""
|
---|
| 96 | return self._currentInteger
|
---|
| 97 |
|
---|
| 98 | def set_int(self, value):
|
---|
| 99 | """Set the integer."""
|
---|
| 100 | if value!=self._currentInteger:
|
---|
| 101 | self._currentInteger = value
|
---|
| 102 | self.emit("integer-changed", self._currentInteger)
|
---|
| 103 | self._set_text()
|
---|
| 104 |
|
---|
| 105 | def _handle_changed(self, widget):
|
---|
| 106 | """Handle the changed signal."""
|
---|
| 107 | if self._selfSetting:
|
---|
| 108 | return
|
---|
| 109 | text = self.get_text()
|
---|
| 110 | if text=="":
|
---|
| 111 | self.set_int(self._defaultValue)
|
---|
| 112 | else:
|
---|
| 113 | try:
|
---|
| 114 | self.set_int(int(text))
|
---|
| 115 | except:
|
---|
| 116 | self._set_text()
|
---|
| 117 |
|
---|
| 118 | def _set_text(self):
|
---|
| 119 | """Set the text value from the current integer."""
|
---|
| 120 | self._selfSetting = True
|
---|
| 121 | self.set_text("" if self._currentInteger is None
|
---|
| 122 | else str(self._currentInteger))
|
---|
| 123 | self._selfSetting = False
|
---|
| 124 |
|
---|
| 125 | #------------------------------------------------------------------------------
|
---|
| 126 |
|
---|
| 127 | gobject.signal_new("integer-changed", IntegerEntry, gobject.SIGNAL_RUN_FIRST,
|
---|
| 128 | None, (object,))
|
---|
| 129 |
|
---|
| 130 | #------------------------------------------------------------------------------
|
---|