示例#1
0
    def journal_event(
        self, event
    ):  # called by event <<JournalEvent>> by monitor when it places an event in the queue
        while True:
            entry = monitor.get_entry()
            if not entry:
                return
            print(f'JE {entry}')
            #print(f'..Monitor state {monitor.state}')

            if entry['event'] == 'ExitProgram':
                self.onexit()
                return

            self.updatedetails()

            if not entry['event'] or not monitor.mode:
                return  # Startup or in CQC

            # Export loadout
            if entry['event'] == 'Loadout' and not monitor.state[
                    'Captain'] and config.getint('output') & config.OUT_SHIP:
                monitor.export_ship()

            if entry['event'] == 'Market' and not monitor.state['Captain']:
                lastmarket = entry

            # Plugins
            err = plug.notify_journal_entry(monitor.cmdr, monitor.is_beta,
                                            monitor.system, monitor.station,
                                            entry, monitor.state)
            if err:
                self.status['text'] = err
示例#2
0
 def run(self):
     if monitor.start():
         try:
             while True:
                 entry = monitor.get_entry()
                 if entry:
                     self.print_event(entry)
                     continue
                 sleep(1)
         except KeyboardInterrupt:
             monitor.stop()
    def journal_event(self, event):
        while True:
            entry = monitor.get_entry()
            if not entry:
                return

            system_changed = monitor.system and self.system[
                'text'] != monitor.system
            station_changed = monitor.station and self.station[
                'text'] != monitor.station

            # Update main window
            self.cmdr['text'] = monitor.cmdr or ''
            self.ship['text'] = monitor.shiptype and companion.ship_map.get(
                monitor.shiptype, monitor.shiptype) or ''
            self.station['text'] = monitor.station or (
                EDDB.system(monitor.system) and self.STATION_UNDOCKED or '')
            if system_changed or station_changed:
                self.status['text'] = ''
                if self.station['text'] == self.STATION_UNDOCKED:
                    self.ser.write('!0 \n')
                else:
                    self.ser.write('!0' +
                                   self.station['text'].encode('utf-8') +
                                   ' \n')
                self.ser.flush()
            if system_changed:
                self.system['text'] = monitor.system or ''
                self.system['image'] = ''
                self.edsm.link(monitor.system)
                self.ser.write('!1' + self.system['text'].encode('utf-8') +
                               ' \n')
                self.ser.flush()
            self.w.update_idletasks()

            # Send interesting events to EDSM
            if config.getint(
                    'output') & config.OUT_SYS_EDSM and not monitor.is_beta:
                self.status['text'] = _('Sending data to EDSM...')
                self.w.update_idletasks()
                try:
                    # Update system status on startup
                    if monitor.mode and not entry['event']:
                        self.edsm.lookup(monitor.system)

                    # Send credits to EDSM on new game (but not on startup - data might be old)
                    if entry['event'] == 'LoadGame':
                        self.edsm.setcredits(monitor.credits)

                    # Send rank info to EDSM on startup or change
                    if entry['event'] in [None, 'Progress', 'Promotion']:
                        self.edsm.setranks(monitor.ranks)

                    # Send ship info to EDSM on startup or change
                    if entry['event'] in [
                            None, 'LoadGame', 'ShipyardNew', 'ShipyardSwap'
                    ]:
                        self.edsm.setshipid(monitor.shipid)
                        self.edsm.updateship(
                            monitor.shipid, monitor.shiptype, monitor.shippaint
                            and [('paintJob', monitor.shippaint)] or [])
                    elif entry['event'] in ['ShipyardBuy', 'ShipyardSell']:
                        self.edsm.sellship(entry.get('SellShipID'))

                    # Send paintjob info to EDSM on change
                    if entry['event'] in ['ModuleBuy', 'ModuleSell'
                                          ] and entry['Slot'] == 'PaintJob':
                        self.edsm.updateship(monitor.shipid, monitor.shiptype,
                                             [('paintJob', monitor.shippaint)])

                    # Write EDSM log on change
                    if monitor.mode and entry['event'] in [
                            'Location', 'FSDJump'
                    ]:
                        self.edsm.writelog(
                            timegm(
                                strptime(entry['timestamp'],
                                         '%Y-%m-%dT%H:%M:%SZ')),
                            monitor.system, monitor.coordinates,
                            monitor.shipid)

                except Exception as e:
                    if __debug__: print_exc()
                    self.status['text'] = unicode(e)
                    if not config.getint('hotkey_mute'):
                        hotkeymgr.play_bad()
                else:
                    self.status['text'] = ''
            self.edsmpoll()

            if not entry['event'] or not monitor.mode:
                return  # Startup or in CQC

            # Plugins
            plug.notify_journal_entry(monitor.cmdr, monitor.system,
                                      monitor.station, entry)
            if system_changed:  # Backwards compatibility
                plug.notify_system_changed(
                    timegm(strptime(entry['timestamp'], '%Y-%m-%dT%H:%M:%SZ')),
                    monitor.system, monitor.coordinates)

            # Auto-Update after docking
            if station_changed and not monitor.is_beta and not config.getint(
                    'output') & config.OUT_MKT_MANUAL and config.getint(
                        'output') & config.OUT_STATION_ANY:
                self.w.after(int(SERVER_RETRY * 1000), self.getandsend)

            # Send interesting events to EDDN
            try:
                if (config.getint('output') & config.OUT_SYS_EDDN
                        and monitor.cmdr and
                    (entry['event'] == 'FSDJump' or entry['event'] == 'Docked'
                     or entry['event'] == 'Scan' and monitor.system
                     and monitor.coordinates)):
                    # strip out properties disallowed by the schema
                    for thing in [
                            'CockpitBreach', 'BoostUsed', 'FuelLevel',
                            'FuelUsed', 'JumpDist'
                    ]:
                        entry.pop(thing, None)
                    for thing in entry.keys():
                        if thing.endswith('_Localised'):
                            entry.pop(thing, None)

                    # add planet to Docked event for planetary stations if known
                    if entry['event'] == 'Docked' and monitor.body:
                        entry['BodyName'] = monitor.body

                    # add mandatory StarSystem and StarPos properties to Scan events
                    if 'StarSystem' not in entry:
                        entry['StarSystem'] = monitor.system
                    if 'StarPos' not in entry:
                        entry['StarPos'] = list(monitor.coordinates)

                    self.status['text'] = _('Sending data to EDDN...')
                    self.w.update_idletasks()
                    eddn.export_journal_entry(monitor.cmdr, monitor.is_beta,
                                              entry)
                    self.status['text'] = ''

                elif (config.getint('output') & config.OUT_MKT_EDDN
                      and monitor.cmdr and entry['event'] == 'MarketSell'
                      and entry.get('BlackMarket')):
                    # Construct blackmarket message
                    msg = OrderedDict([
                        ('systemName', monitor.system),
                        ('stationName', monitor.station),
                        ('timestamp', entry['timestamp']),
                        ('name', entry['Type']),
                        ('sellPrice', entry['SellPrice']),
                        ('prohibited', entry.get('IllegalGoods', False)),
                    ])

                    self.status['text'] = _('Sending data to EDDN...')
                    self.w.update_idletasks()
                    eddn.export_blackmarket(monitor.cmdr, monitor.is_beta, msg)
                    self.status['text'] = ''

            except requests.exceptions.RequestException as e:
                if __debug__: print_exc()
                self.status['text'] = _("Error: Can't connect to EDDN")
                if not config.getint('hotkey_mute'):
                    hotkeymgr.play_bad()

            except Exception as e:
                if __debug__: print_exc()
                self.status['text'] = unicode(e)
                if not config.getint('hotkey_mute'):
                    hotkeymgr.play_bad()
    def journal_event(self, event):
        def crewroletext(role):
            # Return translated crew role. Needs to be dynamic to allow for changing language.
            return {
                None: '',
                'Idle': '',
                'FighterCon': _('Fighter'),  # Multicrew role
                'FireCon': _('Gunner'),  # Multicrew role
                'FlightCon': _('Helm'),  # Multicrew role
            }.get(role, role)

        while True:
            entry = monitor.get_entry()
            if not entry:
                return

            # Update main window
            self.cooldown()
            if monitor.cmdr and monitor.state['Captain']:
                self.cmdr['text'] = '%s / %s' % (monitor.cmdr,
                                                 monitor.state['Captain'])
                self.ship_label['text'] = _(
                    'Role') + ':'  # Multicrew role label in main window
                self.ship.configure(state=tk.NORMAL,
                                    text=crewroletext(monitor.state['Role']),
                                    url=None)
            elif monitor.cmdr:
                if monitor.group:
                    self.cmdr['text'] = '%s / %s' % (monitor.cmdr,
                                                     monitor.group)
                else:
                    self.cmdr['text'] = monitor.cmdr
                self.ship_label['text'] = _('Ship') + ':'  # Main window
                self.ship.configure(
                    text=monitor.state['ShipName'] or companion.ship_map.get(
                        monitor.state['ShipType'], monitor.state['ShipType'])
                    or '',
                    url=self.shipyard_url)
            else:
                self.cmdr['text'] = ''
                self.ship_label['text'] = _('Ship') + ':'  # Main window
                self.ship['text'] = ''

            self.edit_menu.entryconfigure(0,
                                          state=monitor.system and tk.NORMAL
                                          or tk.DISABLED)  # Copy

            if entry['event'] in [
                    'Undocked', 'StartJump', 'SetUserShipName', 'ShipyardBuy',
                    'ShipyardSell', 'ShipyardSwap', 'ModuleBuy', 'ModuleSell',
                    'MaterialCollected', 'MaterialDiscarded',
                    'ScientificResearch', 'EngineerCraft', 'Synthesis',
                    'JoinACrew'
            ]:
                self.status['text'] = ''  # Periodically clear any old error
            self.w.update_idletasks()

            # Companion login
            if entry['event'] in [None, 'StartUp', 'NewCommander', 'LoadGame'
                                  ] and monitor.cmdr:
                if not config.get('cmdrs') or monitor.cmdr not in config.get(
                        'cmdrs'):
                    config.set('cmdrs',
                               (config.get('cmdrs') or []) + [monitor.cmdr])
                self.login()

            if not entry['event'] or not monitor.mode:
                return  # Startup or in CQC

            if entry['event'] in ['StartUp', 'LoadGame'] and monitor.started:
                # Disable WinSparkle automatic update checks, IFF configured to do so when in-game
                if config.getint('disable_autoappupdatecheckingame') and 1:
                    self.updater.setAutomaticUpdatesCheck(False)
                    print 'Monitor: Disable WinSparkle automatic update checks'
                # Can start dashboard monitoring
                if not dashboard.start(self.w, monitor.started):
                    print "Can't start Status monitoring"

            # Export loadout
            if entry['event'] == 'Loadout' and not monitor.state[
                    'Captain'] and config.getint('output') & config.OUT_SHIP:
                monitor.export_ship()

            # Plugins
            err = plug.notify_journal_entry(monitor.cmdr, monitor.is_beta,
                                            monitor.system, monitor.station,
                                            entry, monitor.state)
            if err:
                self.status['text'] = err
                if not config.getint('hotkey_mute'):
                    hotkeymgr.play_bad()

            # Auto-Update after docking, but not if auth callback is pending
            if entry['event'] in [
                    'StartUp', 'Location', 'Docked'
            ] and monitor.station and not config.getint(
                    'output'
            ) & config.OUT_MKT_MANUAL and config.getint(
                    'output'
            ) & config.OUT_STATION_ANY and companion.session.state != companion.Session.STATE_AUTH:
                self.w.after(int(SERVER_RETRY * 1000), self.getandsend)

            if entry['event'] == 'ShutDown':
                # Enable WinSparkle automatic update checks
                # NB: Do this blindly, in case option got changed whilst in-game
                self.updater.setAutomaticUpdatesCheck(True)
                print 'Monitor: Enable WinSparkle automatic update checks'
示例#5
0
    def journal_event(self, event):

        def crewroletext(role):
            # Return translated crew role. Needs to be dynamic to allow for changing language.
            return {
                None: '',
                'Idle': '',
                'FighterCon': _('Fighter'),	# Multicrew role
                'FireCon':    _('Gunner'),	# Multicrew role
                'FlightCon':  _('Helm'),	# Multicrew role
            }.get(role, role)

        while True:
            entry = monitor.get_entry()
            if not entry:
                return

            # Update main window
            self.cooldown()
            if monitor.cmdr and monitor.state['Captain']:
                self.cmdr['text'] = '%s / %s' % (monitor.cmdr, monitor.state['Captain'])
                self.ship_label['text'] = _('Role') + ':'	# Multicrew role label in main window
                self.ship.configure(state = tk.NORMAL, text = crewroletext(monitor.state['Role']), url = None)
            elif monitor.cmdr:
                if monitor.group:
                    self.cmdr['text'] = '%s / %s' % (monitor.cmdr, monitor.group)
                elif monitor.mode.lower() == 'solo':
                    self.cmdr['text'] = '%s / %s' % (monitor.cmdr, 'Solo')	# Game mode - not Open or Group. Don't translate
                else:
                    self.cmdr['text'] = monitor.cmdr
                self.ship_label['text'] = _('Ship') + ':'	# Main window
                self.ship.configure(text = monitor.state['ShipName'] or companion.ship_map.get(monitor.state['ShipType'], monitor.state['ShipType']) or '',
                                    url = self.shipyard_url)
            else:
                self.cmdr['text'] = ''
                self.ship_label['text'] = _('Ship') + ':'	# Main window
                self.ship['text'] = ''

            self.edit_menu.entryconfigure(0, state=monitor.system and tk.NORMAL or tk.DISABLED)	# Copy

            if entry['event'] in ['Undocked', 'StartJump', 'SetUserShipName', 'ShipyardBuy', 'ShipyardSell', 'ShipyardSwap', 'ModuleBuy', 'ModuleSell', 'MaterialCollected', 'MaterialDiscarded', 'ScientificResearch', 'EngineerCraft', 'Synthesis', 'JoinACrew']:
                self.status['text'] = ''	# Periodically clear any old error
            self.w.update_idletasks()

            # Companion login
            if entry['event'] in [None, 'StartUp', 'NewCommander', 'LoadGame'] and monitor.cmdr:
                if config.get('cmdrs') and monitor.cmdr in config.get('cmdrs'):
                    prefs.make_current(monitor.cmdr)
                    self.login()
                elif config.get('cmdrs') and entry['event'] == 'NewCommander':
                    cmdrs = config.get('cmdrs')
                    cmdrs[0] = monitor.cmdr	# New Cmdr uses same credentials as old
                    config.set('cmdrs', cmdrs)
                else:
                    prefs.PreferencesDialog(self.w, self.postprefs)	# First run or failed migration

            if not entry['event'] or not monitor.mode:
                return	# Startup or in CQC

            # Plugins
            err = plug.notify_journal_entry(monitor.cmdr, monitor.is_beta, monitor.system, monitor.station, entry, monitor.state)
            if err:
                self.status['text'] = err
                if not config.getint('hotkey_mute'):
                    hotkeymgr.play_bad()

            if entry['event'] in ['StartUp', 'LoadGame'] and monitor.started:
                # Can start dashboard monitoring
                if not dashboard.start(self.w, monitor.started):
                    print "Can't start Status monitoring"

            # Don't send to EDDN while on crew
            if monitor.state['Captain']:
                return

            # Plugin backwards compatibility
            if monitor.mode and entry['event'] in ['StartUp', 'Location', 'FSDJump']:
                plug.notify_system_changed(timegm(strptime(entry['timestamp'], '%Y-%m-%dT%H:%M:%SZ')), monitor.system, monitor.coordinates)

            # Auto-Update after docking
            if monitor.mode and monitor.station and entry['event'] in ['StartUp', 'Location', 'Docked'] and not config.getint('output') & config.OUT_MKT_MANUAL and config.getint('output') & config.OUT_STATION_ANY:
                self.w.after(int(SERVER_RETRY * 1000), self.getandsend)

            # Send interesting events to EDDN
            try:
                if (config.getint('output') & config.OUT_SYS_EDDN and monitor.cmdr and monitor.mode and
                    (entry['event'] == 'Location' or
                     entry['event'] == 'FSDJump' or
                     entry['event'] == 'Docked'  or
                     entry['event'] == 'Scan'    and monitor.system and monitor.coordinates)):
                    # strip out properties disallowed by the schema
                    for thing in ['CockpitBreach', 'BoostUsed', 'FuelLevel', 'FuelUsed', 'JumpDist', 'Latitude', 'Longitude']:
                        entry.pop(thing, None)
                    for thing in entry.keys():
                        if thing.endswith('_Localised'):
                            entry.pop(thing, None)

                    # add planet to Docked event for planetary stations if known
                    if entry['event'] == 'Docked' and monitor.planet:
                        entry['Body'] = monitor.planet
                        entry['BodyType'] = 'Planet'

                    # add mandatory StarSystem and StarPos properties to Scan events
                    if 'StarSystem' not in entry:
                        entry['StarSystem'] = monitor.system
                    if 'StarPos' not in entry:
                        entry['StarPos'] = list(monitor.coordinates)

                    self.eddn.export_journal_entry(monitor.cmdr, monitor.is_beta, entry)

            except requests.exceptions.RequestException as e:
                if __debug__: print_exc()
                self.status['text'] = _("Error: Can't connect to EDDN")
                if not config.getint('hotkey_mute'):
                    hotkeymgr.play_bad()

            except Exception as e:
                if __debug__: print_exc()
                self.status['text'] = unicode(e)
                if not config.getint('hotkey_mute'):
                    hotkeymgr.play_bad()
    def journal_event(self, event):
        while True:
            entry = monitor.get_entry()
            system_changed  = monitor.system  and self.system['text']  != monitor.system
            station_changed = monitor.station and self.station['text'] != monitor.station

            # Update main window
            self.cmdr['text'] = monitor.cmdr or ''
            self.system['text'] = monitor.system or ''
            self.station['text'] = monitor.station or (EDDB.system(monitor.system) and self.STATION_UNDOCKED or '')
            if system_changed or station_changed:
                self.status['text'] = ''

            if config.getint('output') & config.OUT_SYS_EDSM and not monitor.is_beta:
                # Send credits to EDSM on startup
                if monitor.credits and (not entry or entry['event'] == 'LoadGame'):
                    try:
                        self.status['text'] = _('Sending balance/loan to EDSM...')
                        self.w.update_idletasks()
                        self.edsm.setcredits(monitor.credits)
                        self.status['text'] = ''
                    except Exception as e:
                        if __debug__: print_exc()
                        self.status['text'] = unicode(e)
                        if not config.getint('hotkey_mute'):
                            hotkeymgr.play_bad()
                
                # Send shipid to EDSM on startup or change
                if monitor.shipid and (not entry or entry['event'] in ['LoadGame', 'ShipyardSwap']):
                    try:
                        self.status['text'] = _('Sending shipId to EDSM...')
                        self.w.update_idletasks()
                        self.edsm.setshipid(monitor.shipid)
                        self.status['text'] = ''
                    except Exception as e:
                        if __debug__: print_exc()
                        self.status['text'] = unicode(e)
                        if not config.getint('hotkey_mute'):
                            hotkeymgr.play_bad()
                
                # Send rank info to EDSM on startup or change
                if monitor.ranks and (not entry or entry['event'] in ['Progress', 'Promotion']):
                    try:
                        self.status['text'] = _('Sending ranks to EDSM...')
                        self.w.update_idletasks()
                        self.edsm.setranks(monitor.ranks)
                        self.status['text'] = ''
                    except Exception as e:
                        if __debug__: print_exc()
                        self.status['text'] = unicode(e)
                        if not config.getint('hotkey_mute'):
                            hotkeymgr.play_bad()

            if not entry or not monitor.mode:
                return	# Fake event or in CQC

            plug.notify_journal_entry(monitor.cmdr, monitor.system, monitor.station, entry)

            if system_changed:
                self.system['image'] = ''
                timestamp = timegm(strptime(entry['timestamp'], '%Y-%m-%dT%H:%M:%SZ'))

                # Backwards compatibility
                plug.notify_system_changed(timestamp, monitor.system, monitor.coordinates)

                # Update EDSM if we have coordinates - i.e. Location or FSDJump events
                if config.getint('output') & config.OUT_SYS_EDSM and monitor.coordinates:
                    try:
                        self.status['text'] = _('Sending flight log to EDSM...')
                        self.w.update_idletasks()
                        self.edsm.writelog(timestamp, monitor.system, monitor.coordinates)
                        self.status['text'] = ''
                    except Exception as e:
                        if __debug__: print_exc()
                        self.status['text'] = unicode(e)
                        if not config.getint('hotkey_mute'):
                            hotkeymgr.play_bad()
                else:
                    self.edsm.link(monitor.system)
                self.edsmpoll()

            # Auto-Update after docking
            if station_changed and not monitor.is_beta and not config.getint('output') & config.OUT_MKT_MANUAL and config.getint('output') & config.OUT_STATION_ANY:
                self.w.after(int(SERVER_RETRY * 1000), self.getandsend)

            # Send interesting events to EDDN
            try:
                if (config.getint('output') & config.OUT_SYS_EDDN and monitor.cmdr and
                    (entry['event'] == 'FSDJump' and system_changed  or
                     entry['event'] == 'Docked'  and station_changed or
                     entry['event'] == 'Scan'    and monitor.system and monitor.coordinates)):
                    # strip out properties disallowed by the schema
                    for thing in ['CockpitBreach', 'BoostUsed', 'FuelLevel', 'FuelUsed', 'JumpDist']:
                        entry.pop(thing, None)
                    for thing in entry.keys():
                        if thing.endswith('_Localised'):
                            entry.pop(thing, None)

                    # add mandatory StarSystem and StarPos properties to Scan events
                    if 'StarSystem' not in entry:
                        entry['StarSystem'] = monitor.system
                    if 'StarPos' not in entry:
                        entry['StarPos'] = list(monitor.coordinates)

                    self.status['text'] = _('Sending data to EDDN...')
                    eddn.export_journal_entry(monitor.cmdr, monitor.is_beta, entry)
                    self.status['text'] = ''

                elif (config.getint('output') & config.OUT_MKT_EDDN and monitor.cmdr and
                      entry['event'] == 'MarketSell' and entry.get('BlackMarket')):
                    # Construct blackmarket message
                    msg = OrderedDict([
                        ('systemName',  monitor.system),
                        ('stationName', monitor.station),
                        ('timestamp',   entry['timestamp']),
                        ('name',        entry['Type']),
                        ('sellPrice',   entry['SellPrice']),
                        ('prohibited' , entry.get('IllegalGoods', False)),
                    ])

                    self.status['text'] = _('Sending data to EDDN...')
                    eddn.export_blackmarket(monitor.cmdr, monitor.is_beta, msg)
                    self.status['text'] = ''

            except requests.exceptions.RequestException as e:
                if __debug__: print_exc()
                self.status['text'] = _("Error: Can't connect to EDDN")
                if not config.getint('hotkey_mute'):
                    hotkeymgr.play_bad()

            except Exception as e:
                if __debug__: print_exc()
                self.status['text'] = unicode(e)
                if not config.getint('hotkey_mute'):
                    hotkeymgr.play_bad()
    def journal_event(self, event):

        def crewroletext(role):
            # Return translated crew role. Needs to be dynamic to allow for changing language.
            return {
                None: '',
                'Idle': '',
                'FighterCon': _('Fighter'),	# Multicrew role
                'FireCon':    _('Gunner'),	# Multicrew role
                'FlightCon':  _('Helm'),	# Multicrew role
            }.get(role, role)

        while True:
            entry = monitor.get_entry()
            if not entry:
                return

            # Update main window
            self.cooldown()
            if monitor.cmdr and monitor.state['Captain']:
                self.cmdr['text'] = '%s / %s' % (monitor.cmdr, monitor.state['Captain'])
                self.ship_label['text'] = _('Role') + ':'	# Multicrew role label in main window
                self.ship.configure(state = tk.NORMAL, text = crewroletext(monitor.state['Role']), url = None)
            elif monitor.cmdr:
                if monitor.group:
                    self.cmdr['text'] = '%s / %s' % (monitor.cmdr, monitor.group)
                else:
                    self.cmdr['text'] = monitor.cmdr
                self.ship_label['text'] = _('Ship') + ':'	# Main window
                self.ship.configure(text = monitor.state['ShipName'] or companion.ship_map.get(monitor.state['ShipType'], monitor.state['ShipType']) or '',
                                    url = self.shipyard_url)
            else:
                self.cmdr['text'] = ''
                self.ship_label['text'] = _('Ship') + ':'	# Main window
                self.ship['text'] = ''

            self.edit_menu.entryconfigure(0, state=monitor.system and tk.NORMAL or tk.DISABLED)	# Copy

            if entry['event'] in ['Undocked', 'StartJump', 'SetUserShipName', 'ShipyardBuy', 'ShipyardSell', 'ShipyardSwap', 'ModuleBuy', 'ModuleSell', 'MaterialCollected', 'MaterialDiscarded', 'ScientificResearch', 'EngineerCraft', 'Synthesis', 'JoinACrew']:
                self.status['text'] = ''	# Periodically clear any old error
            self.w.update_idletasks()

            # Companion login
            if entry['event'] in [None, 'StartUp', 'NewCommander', 'LoadGame'] and monitor.cmdr:
                if not config.get('cmdrs') or monitor.cmdr not in config.get('cmdrs'):
                    config.set('cmdrs', (config.get('cmdrs') or []) + [monitor.cmdr])
                self.login()

            if not entry['event'] or not monitor.mode:
                return	# Startup or in CQC

            if entry['event'] in ['StartUp', 'LoadGame'] and monitor.started:
                # Can start dashboard monitoring
                if not dashboard.start(self.w, monitor.started):
                    print "Can't start Status monitoring"

            # Export loadout
            if entry['event'] == 'Loadout' and not monitor.state['Captain'] and config.getint('output') & config.OUT_SHIP:
                monitor.export_ship()

            # Plugins
            err = plug.notify_journal_entry(monitor.cmdr, monitor.is_beta, monitor.system, monitor.station, entry, monitor.state)
            if err:
                self.status['text'] = err
                if not config.getint('hotkey_mute'):
                    hotkeymgr.play_bad()

            # Auto-Update after docking, but not if auth callback is pending
            if entry['event'] in ['StartUp', 'Location', 'Docked'] and monitor.station and not config.getint('output') & config.OUT_MKT_MANUAL and config.getint('output') & config.OUT_STATION_ANY and companion.session.state != companion.Session.STATE_AUTH:
                self.w.after(int(SERVER_RETRY * 1000), self.getandsend)
示例#8
0
    def journal_event(self, event):

        def crewroletext(role):
            # Return translated crew role. Needs to be dynamic to allow for changing language.
            return {
                None: '',
                'Idle': '',
                'FighterCon': _('Fighter'),	# Multicrew role
                'FireCon':    _('Gunner'),	# Multicrew role
                'FlightCon':  _('Helm'),	# Multicrew role
            }.get(role, role)

        while True:
            entry = monitor.get_entry()
            if not entry:
                return

            # Update main window
            self.cooldown()
            if monitor.cmdr and monitor.state['Captain']:
                self.cmdr['text'] = '%s / %s' % (monitor.cmdr, monitor.state['Captain'])
                self.ship_label['text'] = _('Role') + ':'	# Multicrew role label in main window
                self.ship.configure(state = tk.NORMAL, text = crewroletext(monitor.state['Role']), url = None)
            elif monitor.cmdr:
                if monitor.group:
                    self.cmdr['text'] = '%s / %s' % (monitor.cmdr, monitor.group)
                else:
                    self.cmdr['text'] = monitor.cmdr
                self.ship_label['text'] = _('Ship') + ':'	# Main window
                self.ship.configure(text = monitor.state['ShipName'] or companion.ship_map.get(monitor.state['ShipType'], monitor.state['ShipType']) or '',
                                    url = self.shipyard_url)
            else:
                self.cmdr['text'] = ''
                self.ship_label['text'] = _('Ship') + ':'	# Main window
                self.ship['text'] = ''

            self.edit_menu.entryconfigure(0, state=monitor.system and tk.NORMAL or tk.DISABLED)	# Copy

            if entry['event'] in ['Undocked', 'StartJump', 'SetUserShipName', 'ShipyardBuy', 'ShipyardSell', 'ShipyardSwap', 'ModuleBuy', 'ModuleSell', 'MaterialCollected', 'MaterialDiscarded', 'ScientificResearch', 'EngineerCraft', 'Synthesis', 'JoinACrew']:
                self.status['text'] = ''	# Periodically clear any old error
            self.w.update_idletasks()

            # Companion login
            if entry['event'] in [None, 'StartUp', 'NewCommander', 'LoadGame'] and monitor.cmdr:
                if config.get('cmdrs') and monitor.cmdr in config.get('cmdrs'):
                    prefs.make_current(monitor.cmdr)
                    self.login()
                elif config.get('cmdrs') and entry['event'] == 'NewCommander':
                    cmdrs = config.get('cmdrs')
                    cmdrs[0] = monitor.cmdr	# New Cmdr uses same credentials as old
                    config.set('cmdrs', cmdrs)
                elif not self.prefsdialog:
                    self.prefsdialog = prefs.PreferencesDialog(self.w, self.postprefs)	# First run or failed migration

            if not entry['event'] or not monitor.mode:
                return	# Startup or in CQC

            if entry['event'] in ['StartUp', 'LoadGame'] and monitor.started:
                # Can start dashboard monitoring
                if not dashboard.start(self.w, monitor.started):
                    print "Can't start Status monitoring"

            # Export loadout
            if entry['event'] == 'Loadout' and not monitor.state['Captain'] and config.getint('output') & config.OUT_SHIP:
                monitor.export_ship()

            # Plugins
            err = plug.notify_journal_entry(monitor.cmdr, monitor.is_beta, monitor.system, monitor.station, entry, monitor.state)
            if err:
                self.status['text'] = err
                if not config.getint('hotkey_mute'):
                    hotkeymgr.play_bad()

            # Auto-Update after docking
            if entry['event'] in ['StartUp', 'Location', 'Docked'] and monitor.station and not config.getint('output') & config.OUT_MKT_MANUAL and config.getint('output') & config.OUT_STATION_ANY:
                self.w.after(int(SERVER_RETRY * 1000), self.getandsend)