[90] | 1 | #The Flight Info tab
|
---|
| 2 |
|
---|
| 3 | from common import *
|
---|
| 4 |
|
---|
[98] | 5 | import mlx.const as const
|
---|
| 6 |
|
---|
[90] | 7 | class FlightInfo(gtk.VBox):
|
---|
| 8 | """The flight info tab."""
|
---|
[98] | 9 | _delayCodes = [ (const.DELAYCODE_LOADING, "L_oading problems"),
|
---|
| 10 | (const.DELAYCODE_VATSIM, "_VATSIM problem"),
|
---|
| 11 | (const.DELAYCODE_NETWORK, "_Net problems"),
|
---|
| 12 | (const.DELAYCODE_CONTROLLER, "Controller's _fault"),
|
---|
| 13 | (const.DELAYCODE_SYSTEM, "S_ystem crash/freeze"),
|
---|
| 14 | (const.DELAYCODE_NAVIGATION, "Navi_gation problem"),
|
---|
| 15 | (const.DELAYCODE_TRAFFIC, "T_raffic problems"),
|
---|
| 16 | (const.DELAYCODE_APRON, "_Apron navigation problem"),
|
---|
| 17 | (const.DELAYCODE_WEATHER, "_Weather problems"),
|
---|
| 18 | (const.DELAYCODE_PERSONAL, "_Personal reasons") ]
|
---|
| 19 |
|
---|
[90] | 20 | @staticmethod
|
---|
| 21 | def _createCommentArea(label):
|
---|
| 22 | """Create a comment area.
|
---|
| 23 |
|
---|
| 24 | Returns a tuple of two items:
|
---|
| 25 | - the top-level widget of the comment area, and
|
---|
| 26 | - the comment text editor."""
|
---|
| 27 |
|
---|
| 28 | frame = gtk.Frame(label = label)
|
---|
| 29 | label = frame.get_label_widget()
|
---|
| 30 | label.set_use_underline(True)
|
---|
| 31 |
|
---|
| 32 | alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
| 33 | xscale = 1.0, yscale = 1.0)
|
---|
| 34 | alignment.set_padding(padding_top = 4, padding_bottom = 4,
|
---|
| 35 | padding_left = 8, padding_right = 8)
|
---|
| 36 |
|
---|
| 37 | scroller = gtk.ScrolledWindow()
|
---|
[97] | 38 | # FIXME: these should be constants
|
---|
[90] | 39 | scroller.set_policy(gtk.PolicyType.AUTOMATIC if pygobject
|
---|
| 40 | else gtk.POLICY_AUTOMATIC,
|
---|
| 41 | gtk.PolicyType.AUTOMATIC if pygobject
|
---|
| 42 | else gtk.POLICY_AUTOMATIC)
|
---|
| 43 | scroller.set_shadow_type(gtk.ShadowType.IN if pygobject
|
---|
| 44 | else gtk.SHADOW_IN)
|
---|
| 45 | comments = gtk.TextView()
|
---|
| 46 | scroller.add(comments)
|
---|
| 47 | alignment.add(scroller)
|
---|
| 48 | frame.add(alignment)
|
---|
| 49 |
|
---|
| 50 | label.set_mnemonic_widget(comments)
|
---|
| 51 |
|
---|
| 52 | return (frame, comments)
|
---|
| 53 |
|
---|
| 54 | def __init__(self, gui):
|
---|
| 55 | """Construct the flight info tab."""
|
---|
| 56 | super(FlightInfo, self).__init__()
|
---|
| 57 | self._gui = gui
|
---|
| 58 |
|
---|
[93] | 59 | self._commentsAlignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
| 60 | xscale = 1.0, yscale = 1.0)
|
---|
[90] | 61 | commentsBox = gtk.HBox()
|
---|
| 62 |
|
---|
| 63 | (frame, self._comments) = FlightInfo._createCommentArea("_Comments")
|
---|
| 64 | commentsBox.pack_start(frame, True, True, 8)
|
---|
| 65 |
|
---|
| 66 | (frame, self._flightDefects) = FlightInfo._createCommentArea("Flight _defects")
|
---|
| 67 | commentsBox.pack_start(frame, True, True, 8)
|
---|
| 68 |
|
---|
[93] | 69 | self._commentsAlignment.add(commentsBox)
|
---|
| 70 | self.pack_start(self._commentsAlignment, True, True, 8)
|
---|
[90] | 71 |
|
---|
| 72 | frame = gtk.Frame(label = "Delay codes")
|
---|
| 73 | label = frame.get_label_widget()
|
---|
| 74 | label.set_use_underline(True)
|
---|
| 75 |
|
---|
| 76 | alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
| 77 | xscale = 0.0, yscale = 0.0)
|
---|
| 78 | alignment.set_padding(padding_top = 4, padding_bottom = 4,
|
---|
| 79 | padding_left = 8, padding_right = 8)
|
---|
| 80 |
|
---|
| 81 | table = gtk.Table(5, 2)
|
---|
| 82 | table.set_col_spacings(16)
|
---|
| 83 |
|
---|
[98] | 84 | row = 0
|
---|
| 85 | column = 0
|
---|
[90] | 86 |
|
---|
[98] | 87 | self._delayCodeWidgets = []
|
---|
| 88 | for (_code, label) in FlightInfo._delayCodes:
|
---|
| 89 | button = gtk.CheckButton(label)
|
---|
| 90 | button.set_use_underline(True)
|
---|
| 91 | table.attach(button, column, column + 1, row, row + 1)
|
---|
| 92 | self._delayCodeWidgets.append(button)
|
---|
| 93 | if column==0:
|
---|
| 94 | column += 1
|
---|
| 95 | else:
|
---|
| 96 | row += 1
|
---|
| 97 | column = 0
|
---|
[90] | 98 |
|
---|
| 99 | alignment.add(table)
|
---|
| 100 | frame.add(alignment)
|
---|
| 101 |
|
---|
[93] | 102 | self._delayAlignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
| 103 | xscale = 0.0, yscale = 0.0)
|
---|
| 104 | self._delayAlignment.add(frame)
|
---|
| 105 |
|
---|
| 106 | self.pack_start(self._delayAlignment, False, False, 8)
|
---|
[90] | 107 |
|
---|
[97] | 108 | @property
|
---|
| 109 | def comments(self):
|
---|
| 110 | """Get the comments."""
|
---|
| 111 | buffer = self._comments.get_buffer()
|
---|
| 112 | return text2unicode(buffer.get_text(buffer.get_start_iter(),
|
---|
| 113 | buffer.get_end_iter(), True))
|
---|
| 114 |
|
---|
| 115 | @property
|
---|
| 116 | def flightDefects(self):
|
---|
| 117 | """Get the flight defects."""
|
---|
| 118 | buffer = self._flightDefects.get_buffer()
|
---|
| 119 | return text2unicode(buffer.get_text(buffer.get_start_iter(),
|
---|
| 120 | buffer.get_end_iter(), True))
|
---|
| 121 |
|
---|
[99] | 122 | @property
|
---|
| 123 | def delayCodes(self):
|
---|
| 124 | """Get the list of delay codes checked by the user."""
|
---|
| 125 | codes = []
|
---|
| 126 | for index in range(0, len(FlightInfo._delayCodes)):
|
---|
| 127 | if self._delayCodeWidgets[index].get_active():
|
---|
| 128 | codes.append(FlightInfo._delayCodes[index][0])
|
---|
| 129 | return codes
|
---|
| 130 |
|
---|
[93] | 131 | def enable(self):
|
---|
| 132 | """Enable the flight info tab."""
|
---|
| 133 | #gobject.idle_add(self.set_sensitive, True)
|
---|
| 134 | self._commentsAlignment.set_sensitive(True)
|
---|
| 135 | self._delayAlignment.set_sensitive(True)
|
---|
| 136 |
|
---|
| 137 | def disable(self):
|
---|
| 138 | """Enable the flight info tab."""
|
---|
| 139 | #gobject.idle_add(self.set_sensitive, False)
|
---|
| 140 | self._commentsAlignment.set_sensitive(False)
|
---|
| 141 | self._delayAlignment.set_sensitive(False)
|
---|
[90] | 142 |
|
---|
| 143 | def reset(self):
|
---|
| 144 | """Reset the flight info tab."""
|
---|
| 145 | self._comments.get_buffer().set_text("")
|
---|
| 146 | self._flightDefects.get_buffer().set_text("")
|
---|
| 147 |
|
---|
| 148 | self._loadingProblems.set_active(False)
|
---|
| 149 | self._vatsimProblem.set_active(False)
|
---|
| 150 | self._netProblems.set_active(False)
|
---|
| 151 | self._controllersFault.set_active(False)
|
---|
| 152 | self._systemCrash.set_active(False)
|
---|
| 153 | self._navigationProblem.set_active(False)
|
---|
| 154 | self._trafficProblems.set_active(False)
|
---|
| 155 | self._apronProblem.set_active(False)
|
---|
| 156 | self._weatherProblems.set_active(False)
|
---|
| 157 | self._personalReasons.set_active(False)
|
---|