Ignore:
Timestamp:
12/08/12 15:02:57 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Implemented the new, more flexible way of storing the log during flight (#143)

Location:
src/mlx/gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/gui/common.py

    r302 r345  
    297297    faultTag.set_property("foreground", "red")
    298298    faultTag.set_property("weight", WEIGHT_BOLD)
    299     buffer.get_tag_table().add(faultTag)   
     299    buffer.get_tag_table().add(faultTag)
    300300
    301301#------------------------------------------------------------------------------
     
    305305
    306306    If isFault is set, use the tag named 'fault'."""
     307    insertTextBuffer(buffer, buffer.get_end_iter(), text, isFault)
     308
     309#------------------------------------------------------------------------------
     310
     311def insertTextBuffer(buffer, iter, text, isFault = False):
     312    """Insert the given line into the given text buffer at the given iterator.
     313
     314    If isFault is set, use the tag named 'fault'."""
    307315    if isFault:
    308         buffer.insert_with_tags_by_name(buffer.get_end_iter(), text,
    309                                         "fault")
     316        buffer.insert_with_tags_by_name(iter, text, "fault")
    310317    else:
    311         buffer.insert(buffer.get_end_iter(), text)
    312 
    313 #------------------------------------------------------------------------------
     318        buffer.insert(iter, text)
     319
     320#------------------------------------------------------------------------------
  • src/mlx/gui/gui.py

    r304 r345  
    9090    def build(self, iconDirectory):
    9191        """Build the GUI."""
    92        
     92
    9393        self._mainWindow = window = gtk.Window()
    9494        window.set_title(WINDOW_TITLE_BASE)
     
    112112        self._notebook = gtk.Notebook()
    113113        mainVBox.pack_start(self._notebook, True, True, 4)
    114        
     114
    115115        self._wizard = Wizard(self)
    116116        label = gtk.Label(xstr("tab_flight"))
     
    131131        label.set_tooltip_text(xstr("tab_weight_help_tooltip"))
    132132        self._notebook.append_page(self._weightHelp, label)
    133        
     133
    134134        (logWidget, self._logView)  = self._buildLogWidget()
    135         addFaultTag(self._logView.get_buffer())       
     135        addFaultTag(self._logView.get_buffer())
    136136        label = gtk.Label(xstr("tab_log"))
    137137        label.set_use_underline(True)
     
    144144        label.set_tooltip_text(xstr("tab_gates_tooltip"))
    145145        self._notebook.append_page(self._fleetGateStatus, label)
    146        
     146
    147147        (self._debugLogWidget, self._debugLogView) = self._buildLogWidget()
    148148        self._debugLogWidget.show_all()
     
    186186        """Get the main window of the GUI."""
    187187        return self._mainWindow
    188        
     188
    189189    @property
    190190    def logger(self):
    191191        """Get the logger used by us."""
    192192        return self._logger
    193        
     193
    194194    @property
    195195    def simulator(self):
    196196        """Get the simulator used by us."""
    197197        return self._simulator
    198        
     198
    199199    @property
    200200    def flight(self):
     
    211211        """Indicate if the user has logged in properly."""
    212212        return self._wizard.loggedIn
    213        
     213
    214214    @property
    215215    def loginResult(self):
     
    251251        """Get Zero-Fuel Weight calculated for the current flight."""
    252252        return self._wizard.zfw
    253        
     253
    254254    @property
    255255    def filedCruiseAltitude(self):
    256256        """Get cruise altitude filed for the current flight."""
    257257        return self._wizard.filedCruiseAltitude
    258        
     258
    259259    @property
    260260    def cruiseAltitude(self):
     
    271271        """Get the METAR of the deprature airport."""
    272272        return self._wizard.departureMETAR
    273        
     273
    274274    @property
    275275    def arrivalMETAR(self):
     
    281281        """Get the name of the departure runway."""
    282282        return self._wizard.departureRunway
    283        
     283
    284284    @property
    285285    def sid(self):
     
    291291        """Get the V1 speed calculated for the flight."""
    292292        return self._wizard.v1
    293        
     293
    294294    @property
    295295    def vr(self):
    296296        """Get the Vr speed calculated for the flight."""
    297297        return self._wizard.vr
    298        
     298
    299299    @property
    300300    def v2(self):
    301301        """Get the V2 speed calculated for the flight."""
    302302        return self._wizard.v2
    303        
     303
    304304    @property
    305305    def arrivalRunway(self):
     
    326326        """Get the Vref speed calculated for the flight."""
    327327        return self._wizard.vref
    328        
     328
    329329    @property
    330330    def flightType(self):
     
    360360                                    self._mainWindow)
    361361            self._updater.start()
    362        
     362
    363363        singleton.raiseCallback = self.raiseCallback
    364364        gtk.main()
     
    398398                                   type = MESSAGETYPE_ERROR,
    399399                                   message_format = xstr("conn_failed"))
    400    
     400
    401401        dialog.set_title(WINDOW_TITLE_BASE)
    402402        dialog.format_secondary_markup(xstr("conn_failed_sec"))
    403        
     403
    404404        dialog.add_button(xstr("button_cancel"), 0)
    405405        dialog.add_button(xstr("button_tryagain"), 1)
    406406        dialog.set_default_response(1)
    407        
     407
    408408        result = dialog.run()
    409409        dialog.hide()
     
    413413        else:
    414414            self.reset()
    415        
     415
    416416    def disconnected(self):
    417417        """Called when we have disconnected from the simulator."""
     
    422422
    423423    def _disconnected(self):
    424         """Called when we have disconnected from the simulator unexpectedly."""       
     424        """Called when we have disconnected from the simulator unexpectedly."""
    425425        self._statusbar.updateConnection(self._connecting, self._connected)
    426426
     
    460460        result = dialog.run()
    461461        dialog.hide()
    462        
     462
    463463        if result==RESPONSETYPE_YES:
    464464            self.reset()
     
    507507
    508508        return True
    509            
    510     def addFlightLogLine(self, timeStr, line, isFault = False):
    511         """Write the given message line to the log."""
    512         gobject.idle_add(self._writeLog,
    513                          formatFlightLogLine(timeStr, line),
    514                          self._logView, isFault)
    515 
    516     def updateFlightLogLine(self, index, timeStr, line):
    517         """Update the line with the given index."""
    518         gobject.idle_add(self._updateFlightLogLine, index,
    519                          formatFlightLogLine(timeStr, line))
    520 
    521     def _updateFlightLogLine(self, index, line):
    522         """Replace the contents of the given line in the log."""
     509
     510    def insertFlightLogLine(self, index, timestampString, text, isFault):
     511        """Insert the flight log line with the given data."""
     512        gobject.idle_add(self._insertFlightLogLine, index,
     513                         formatFlightLogLine(timestampString, text),
     514                         isFault)
     515
     516    def _insertFlightLogLine(self, index, line, isFault):
     517        """Perform the real insertion.
     518
     519        To be called from the event loop."""
     520        buffer = self._logView.get_buffer()
     521        lineIter = buffer.get_iter_at_line(index)
     522        insertTextBuffer(buffer, lineIter, line, isFault = isFault)
     523        self._logView.scroll_mark_onscreen(buffer.get_insert())
     524
     525    def removeFlightLogLine(self, index):
     526        """Remove the flight log line with the given index."""
     527        gobject.idle_add(self._removeFlightLogLine, index)
     528
     529    def _removeFlightLogLine(self, index):
     530        """Perform the real removal."""
    523531        buffer = self._logView.get_buffer()
    524532        startIter = buffer.get_iter_at_line(index)
    525         endIter = buffer.get_iter_at_line(index + 1)
     533        endIter = buffer.get_iter_at_line(index+1)
    526534        buffer.delete(startIter, endIter)
    527         buffer.insert(startIter, line)
    528535        self._logView.scroll_mark_onscreen(buffer.get_insert())
    529536
     
    591598             (event.new_window_state&WINDOW_STATE_ICONIFIED)==0:
    592599            self._mainWindow.present()
    593            
     600
    594601    def raiseCallback(self):
    595602        """Callback for the singleton handling code."""
     
    630637            self._mainWindow.present()
    631638        self._mainWindow.deiconify()
    632            
     639
    633640    def toggleMainWindow(self):
    634641        """Toggle the main window."""
     
    679686        if self._stdioText:
    680687            sys.__stderr__.write(self._stdioText)
    681            
     688
    682689    def writeStdIO(self, text):
    683690        """Write the given text into standard I/O log."""
     
    758765        self._updatePlaneStatus = status
    759766        self._updatePlaneGateNumber = gateNumber
    760        
     767
    761768        self.webHandler.updatePlane(self._updatePlaneResultCallback,
    762769                                    tailNumber, status, gateNumber)
     
    799806            self._stdioText = ""
    800807        if not text: return
    801            
     808
    802809        lines = text.splitlines()
    803810        if text[-1]=="\n":
     
    809816        now = datetime.datetime.now()
    810817        timeStr = "%02d:%02d:%02d: " % (now.hour, now.minute, now.second)
    811            
     818
    812819        for line in lines:
    813820            #print >> sys.__stdout__, line
     
    833840        self._flight.aircraft = acft.Aircraft.create(self._flight)
    834841        self._flight.aircraft._checkers.append(self)
    835        
     842
    836843        if self._simulator is None:
    837844            self._simulator = fs.createSimulator(const.SIM_MSFS9, self)
    838845            fs.setupMessageSending(self.config, self._simulator)
    839846            self._setupTimeSync()
    840        
     847
    841848        self._flight.simulator = self._simulator
    842849
     
    845852
    846853        self._connecting = True
    847         self._simulator.connect(self._flight.aircraft)       
     854        self._simulator.connect(self._flight.aircraft)
    848855
    849856    def startMonitoring(self):
     
    867874        """Build the main menu bar."""
    868875        menuBar = gtk.MenuBar()
    869        
     876
    870877        fileMenuItem = gtk.MenuItem(xstr("menu_file"))
    871878        fileMenu = gtk.Menu()
     
    965972
    966973        helpMenu.append(gtk.SeparatorMenuItem())
    967        
     974
    968975        aboutMenuItem = gtk.ImageMenuItem(gtk.STOCK_ABOUT)
    969976        aboutMenuItem.set_use_stock(True)
     
    982989            label = gtk.Label(xstr("tab_debug_log"))
    983990            label.set_use_underline(True)
    984             label.set_tooltip_text(xstr("tab_debug_log_tooltip"))       
     991            label.set_tooltip_text(xstr("tab_debug_log_tooltip"))
    985992            self._debugLogPage = self._notebook.append_page(self._debugLogWidget, label)
    986993            self._notebook.set_current_page(self._debugLogPage)
     
    10371044            result = dialog.run()
    10381045            dialog.hide()
    1039        
     1046
    10401047        if result==RESPONSETYPE_YES:
    10411048            self._statusIcon.destroy()
     
    10521059        """Callback for editing the checklists."""
    10531060        self._checklistEditor.run()
    1054        
     1061
    10551062    def _editApproachCallouts(self, menuItem):
    10561063        """Callback for editing the approach callouts."""
    10571064        self._approachCalloutsEditor.run()
    1058        
     1065
    10591066    def _editPreferences(self, menuItem):
    10601067        """Callback for editing the preferences."""
     
    10841091            if pirepDirectory is not None:
    10851092                dialog.set_current_folder(pirepDirectory)
    1086        
     1093
    10871094        result = dialog.run()
    10881095        dialog.hide()
     
    11321139                                           parent = self._mainWindow)
    11331140            dialog.set_modal(True)
    1134            
     1141
    11351142
    11361143            filter = gtk.FileFilter()
     
    11381145            filter.add_pattern("*.pirep")
    11391146            dialog.add_filter(filter)
    1140            
     1147
    11411148            filter = gtk.FileFilter()
    11421149            filter.set_name(xstr("file_filter_all"))
     
    11841191        labelAlignment.add(label)
    11851192        table.attach(labelAlignment, 0, 1, 0, 1)
    1186        
     1193
    11871194        label = gtk.Label(bookedFlight.callsign)
    11881195        labelAlignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
     
    11971204        labelAlignment.add(label)
    11981205        table.attach(labelAlignment, 0, 1, 1, 2)
    1199        
     1206
    12001207        label = gtk.Label(str(bookedFlight.departureTime.date()))
    12011208        labelAlignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
     
    12101217        labelAlignment.add(label)
    12111218        table.attach(labelAlignment, 0, 1, 2, 3)
    1212        
     1219
    12131220        label = gtk.Label(bookedFlight.departureICAO)
    12141221        labelAlignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
     
    12231230        labelAlignment.add(label)
    12241231        table.attach(labelAlignment, 0, 1, 3, 4)
    1225        
     1232
    12261233        label = gtk.Label(bookedFlight.arrivalICAO)
    12271234        labelAlignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
     
    12431250        else:
    12441251            label.set_text("%.1f %%" % (rating,))
    1245        
     1252
    12461253        labelAlignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
    12471254                                       xscale = 0.0, yscale = 0.0)
     
    12521259        dialog.add_button(xstr("viewPIREP"), 1)
    12531260        dialog.add_button(xstr("sendPIREP"), RESPONSETYPE_OK)
    1254        
     1261
    12551262        return dialog
    1256                            
     1263
    12571264    def sendPIREP(self, pirep, callback = None):
    12581265        """Send the given PIREP."""
     
    12871294            messageFormat = xstr("sendPIREP_failed")
    12881295            secondaryMarkup = xstr("sendPIREP_failed_sec")
    1289        
     1296
    12901297        dialog = gtk.MessageDialog(parent = self._wizard.gui.mainWindow,
    12911298                                   type = type, message_format = messageFormat)
     
    13651372            dialog.set_transient_for(self._mainWindow)
    13661373            dialog.set_modal(True)
    1367            
     1374
    13681375            logoPath = os.path.join(self._programDirectory, "logo.png")
    13691376            logo = pixbuf_new_from_file(logoPath)
    13701377            dialog.set_logo(logo)
    1371                                
     1378
    13721379            dialog.set_program_name(PROGRAM_NAME)
    13731380            dialog.set_version(const.VERSION)
     
    13961403
    13971404    def _showAboutURL(self, dialog, link, user_data):
    1398         """Show the about URL."""       
     1405        """Show the about URL."""
    13991406        webbrowser.open(url = link, new = 1)
Note: See TracChangeset for help on using the changeset viewer.