mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-12 23:37:14 +03:00
Handover a number of Lists to Tuples
Tuples are (slightly) more efficient for comparing if x in y. Not that it'll really matter at this scale, but it's technically better and simple to implement. Applying to all files except theme.py, because theme.py is scary.
This commit is contained in:
parent
1976ddb0cf
commit
b7633fa6e3
@ -1547,7 +1547,7 @@ class AppWindow:
|
|||||||
self.w.update_idletasks()
|
self.w.update_idletasks()
|
||||||
|
|
||||||
# Companion login
|
# Companion login
|
||||||
if entry['event'] in [None, 'StartUp', 'NewCommander', 'LoadGame'] and monitor.cmdr:
|
if entry['event'] in (None, 'StartUp', 'NewCommander', 'LoadGame') and monitor.cmdr:
|
||||||
if not config.get_list('cmdrs') or monitor.cmdr not in config.get_list('cmdrs'):
|
if not config.get_list('cmdrs') or monitor.cmdr not in config.get_list('cmdrs'):
|
||||||
config.set('cmdrs', config.get_list('cmdrs', default=[]) + [monitor.cmdr])
|
config.set('cmdrs', config.get_list('cmdrs', default=[]) + [monitor.cmdr])
|
||||||
self.login()
|
self.login()
|
||||||
@ -1565,7 +1565,7 @@ class AppWindow:
|
|||||||
logger.trace_if('journal.queue', 'Startup, returning')
|
logger.trace_if('journal.queue', 'Startup, returning')
|
||||||
return # Startup
|
return # Startup
|
||||||
|
|
||||||
if entry['event'] in ['StartUp', 'LoadGame'] and monitor.started:
|
if entry['event'] in ('StartUp', 'LoadGame') and monitor.started:
|
||||||
logger.info('StartUp or LoadGame event')
|
logger.info('StartUp or LoadGame event')
|
||||||
|
|
||||||
# Disable WinSparkle automatic update checks, IFF configured to do so when in-game
|
# Disable WinSparkle automatic update checks, IFF configured to do so when in-game
|
||||||
|
@ -211,12 +211,12 @@ class MacHotkeyMgr(AbstractHotkeyMgr):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
# BkSp, Del, Clear = clear hotkey
|
# BkSp, Del, Clear = clear hotkey
|
||||||
if keycode in [0x7f, ord(NSDeleteFunctionKey), ord(NSClearLineFunctionKey)]:
|
if keycode in (0x7f, ord(NSDeleteFunctionKey), ord(NSClearLineFunctionKey)):
|
||||||
self.acquire_state = MacHotkeyMgr.ACQUIRE_INACTIVE
|
self.acquire_state = MacHotkeyMgr.ACQUIRE_INACTIVE
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# don't allow keys needed for typing in System Map
|
# don't allow keys needed for typing in System Map
|
||||||
if keycode in [0x13, 0x20, 0x2d] or 0x61 <= keycode <= 0x7a:
|
if keycode in (0x13, 0x20, 0x2d) or 0x61 <= keycode <= 0x7a:
|
||||||
NSBeep()
|
NSBeep()
|
||||||
self.acquire_state = MacHotkeyMgr.ACQUIRE_INACTIVE
|
self.acquire_state = MacHotkeyMgr.ACQUIRE_INACTIVE
|
||||||
return None
|
return None
|
||||||
|
@ -284,23 +284,23 @@ class WindowsHotkeyMgr(AbstractHotkeyMgr):
|
|||||||
| ((GetKeyState(VK_RWIN) & 0x8000) and MOD_WIN)
|
| ((GetKeyState(VK_RWIN) & 0x8000) and MOD_WIN)
|
||||||
keycode = event.keycode
|
keycode = event.keycode
|
||||||
|
|
||||||
if keycode in [VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN]:
|
if keycode in (VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN):
|
||||||
return 0, modifiers
|
return 0, modifiers
|
||||||
|
|
||||||
if not modifiers:
|
if not modifiers:
|
||||||
if keycode == VK_ESCAPE: # Esc = retain previous
|
if keycode == VK_ESCAPE: # Esc = retain previous
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if keycode in [VK_BACK, VK_DELETE, VK_CLEAR, VK_OEM_CLEAR]: # BkSp, Del, Clear = clear hotkey
|
if keycode in (VK_BACK, VK_DELETE, VK_CLEAR, VK_OEM_CLEAR): # BkSp, Del, Clear = clear hotkey
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if (
|
if (
|
||||||
keycode in [VK_RETURN, VK_SPACE, VK_OEM_MINUS] or ord('A') <= keycode <= ord('Z')
|
keycode in (VK_RETURN, VK_SPACE, VK_OEM_MINUS) or ord('A') <= keycode <= ord('Z')
|
||||||
): # don't allow keys needed for typing in System Map
|
): # don't allow keys needed for typing in System Map
|
||||||
winsound.MessageBeep()
|
winsound.MessageBeep()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if (keycode in [VK_NUMLOCK, VK_SCROLL, VK_PROCESSKEY]
|
if (keycode in (VK_NUMLOCK, VK_SCROLL, VK_PROCESSKEY)
|
||||||
or VK_CAPITAL <= keycode <= VK_MODECHANGE): # ignore unmodified mode switch keys
|
or VK_CAPITAL <= keycode <= VK_MODECHANGE): # ignore unmodified mode switch keys
|
||||||
return 0, modifiers
|
return 0, modifiers
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ def lookup(module, ship_map, entitled=False) -> dict | None: # noqa: C901, CCR0
|
|||||||
new['rating'] = 'I'
|
new['rating'] = 'I'
|
||||||
|
|
||||||
# Skip uninteresting stuff - some no longer present in ED 3.1 cAPI data
|
# Skip uninteresting stuff - some no longer present in ED 3.1 cAPI data
|
||||||
elif (name[0] in [
|
elif (name[0] in (
|
||||||
'bobble',
|
'bobble',
|
||||||
'decal',
|
'decal',
|
||||||
'nameplate',
|
'nameplate',
|
||||||
@ -87,7 +87,7 @@ def lookup(module, ship_map, entitled=False) -> dict | None: # noqa: C901, CCR0
|
|||||||
'enginecustomisation',
|
'enginecustomisation',
|
||||||
'voicepack',
|
'voicepack',
|
||||||
'weaponcustomisation'
|
'weaponcustomisation'
|
||||||
]
|
)
|
||||||
or name[1].startswith('shipkit')):
|
or name[1].startswith('shipkit')):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -205,10 +205,10 @@ def lookup(module, ship_map, entitled=False) -> dict | None: # noqa: C901, CCR0
|
|||||||
elif len(name) < 4 and name[1] == 'resourcesiphon': # Hack! 128066402 has no size or class.
|
elif len(name) < 4 and name[1] == 'resourcesiphon': # Hack! 128066402 has no size or class.
|
||||||
(new['class'], new['rating']) = ('1', 'I')
|
(new['class'], new['rating']) = ('1', 'I')
|
||||||
|
|
||||||
elif len(name) < 4 and name[1] in ['guardianpowerdistributor', 'guardianpowerplant']: # Hack! No class.
|
elif len(name) < 4 and name[1] in ('guardianpowerdistributor', 'guardianpowerplant'): # Hack! No class.
|
||||||
(new['class'], new['rating']) = (str(name[2][4:]), 'A')
|
(new['class'], new['rating']) = (str(name[2][4:]), 'A')
|
||||||
|
|
||||||
elif len(name) < 4 and name[1] in ['guardianfsdbooster']: # Hack! No class.
|
elif len(name) < 4 and name[1] == 'guardianfsdbooster': # Hack! No class.
|
||||||
(new['class'], new['rating']) = (str(name[2][4:]), 'H')
|
(new['class'], new['rating']) = (str(name[2][4:]), 'H')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
4
plug.py
4
plug.py
@ -165,7 +165,7 @@ def load_plugins(master: tk.Tk) -> None:
|
|||||||
def _load_internal_plugins():
|
def _load_internal_plugins():
|
||||||
internal = []
|
internal = []
|
||||||
for name in sorted(os.listdir(config.internal_plugin_dir_path)):
|
for name in sorted(os.listdir(config.internal_plugin_dir_path)):
|
||||||
if name.endswith('.py') and name[0] not in ['.', '_']:
|
if name.endswith('.py') and name[0] not in ('.', '_'):
|
||||||
try:
|
try:
|
||||||
plugin = Plugin(name[:-3], os.path.join(config.internal_plugin_dir_path, name), logger)
|
plugin = Plugin(name[:-3], os.path.join(config.internal_plugin_dir_path, name), logger)
|
||||||
plugin.folder = None
|
plugin.folder = None
|
||||||
@ -184,7 +184,7 @@ def _load_found_plugins():
|
|||||||
|
|
||||||
for name in sorted(os.listdir(config.plugin_dir_path), key=lambda n: (
|
for name in sorted(os.listdir(config.plugin_dir_path), key=lambda n: (
|
||||||
not os.path.isfile(os.path.join(config.plugin_dir_path, n, '__init__.py')), n.lower())):
|
not os.path.isfile(os.path.join(config.plugin_dir_path, n, '__init__.py')), n.lower())):
|
||||||
if not os.path.isdir(os.path.join(config.plugin_dir_path, name)) or name[0] in ['.', '_']:
|
if not os.path.isdir(os.path.join(config.plugin_dir_path, name)) or name[0] in ('.', '_'):
|
||||||
pass
|
pass
|
||||||
elif name.endswith('.disabled'):
|
elif name.endswith('.disabled'):
|
||||||
name, discard = name.rsplit('.', 1)
|
name, discard = name.rsplit('.', 1)
|
||||||
|
@ -918,7 +918,7 @@ def journal_entry( # noqa: C901, CCR001
|
|||||||
])
|
])
|
||||||
|
|
||||||
# optional mission-specific properties
|
# optional mission-specific properties
|
||||||
for (iprop, prop) in [
|
for (iprop, prop) in (
|
||||||
('missionExpiry', 'Expiry'), # Listed as optional in the docs, but always seems to be present
|
('missionExpiry', 'Expiry'), # Listed as optional in the docs, but always seems to be present
|
||||||
('starsystemNameTarget', 'DestinationSystem'),
|
('starsystemNameTarget', 'DestinationSystem'),
|
||||||
('stationNameTarget', 'DestinationStation'),
|
('stationNameTarget', 'DestinationStation'),
|
||||||
@ -932,7 +932,7 @@ def journal_entry( # noqa: C901, CCR001
|
|||||||
('passengerCount', 'PassengerCount'),
|
('passengerCount', 'PassengerCount'),
|
||||||
('passengerIsVIP', 'PassengerVIPs'),
|
('passengerIsVIP', 'PassengerVIPs'),
|
||||||
('passengerIsWanted', 'PassengerWanted'),
|
('passengerIsWanted', 'PassengerWanted'),
|
||||||
]:
|
):
|
||||||
|
|
||||||
if prop in entry:
|
if prop in entry:
|
||||||
data[iprop] = entry[prop]
|
data[iprop] = entry[prop]
|
||||||
@ -1295,7 +1295,7 @@ def journal_entry( # noqa: C901, CCR001
|
|||||||
|
|
||||||
# Friends
|
# Friends
|
||||||
if event_name == 'Friends':
|
if event_name == 'Friends':
|
||||||
if entry['Status'] in ['Added', 'Online']:
|
if entry['Status'] in ('Added', 'Online'):
|
||||||
new_add_event(
|
new_add_event(
|
||||||
'addCommanderFriend',
|
'addCommanderFriend',
|
||||||
entry['timestamp'],
|
entry['timestamp'],
|
||||||
@ -1305,7 +1305,7 @@ def journal_entry( # noqa: C901, CCR001
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
elif entry['Status'] in ['Declined', 'Lost']:
|
elif entry['Status'] in ('Declined', 'Lost'):
|
||||||
new_add_event(
|
new_add_event(
|
||||||
'delCommanderFriend',
|
'delCommanderFriend',
|
||||||
entry['timestamp'],
|
entry['timestamp'],
|
||||||
@ -1666,7 +1666,7 @@ def handle_special_events(data_event: dict[str, Any], reply_event: dict[str, Any
|
|||||||
this.lastlocation = reply_event.get('eventData', {})
|
this.lastlocation = reply_event.get('eventData', {})
|
||||||
if not config.shutting_down:
|
if not config.shutting_down:
|
||||||
this.system_link.event_generate('<<InaraLocation>>', when="tail")
|
this.system_link.event_generate('<<InaraLocation>>', when="tail")
|
||||||
elif data_event['eventName'] in ['addCommanderShip', 'setCommanderShip']:
|
elif data_event['eventName'] in ('addCommanderShip', 'setCommanderShip'):
|
||||||
this.lastship = reply_event.get('eventData', {})
|
this.lastship = reply_event.get('eventData', {})
|
||||||
if not config.shutting_down:
|
if not config.shutting_down:
|
||||||
this.system_link.event_generate('<<InaraShip>>', when="tail")
|
this.system_link.event_generate('<<InaraShip>>', when="tail")
|
||||||
|
@ -296,7 +296,7 @@ class OldConfig:
|
|||||||
None,
|
None,
|
||||||
ctypes.byref(key_size)
|
ctypes.byref(key_size)
|
||||||
)
|
)
|
||||||
or key_type.value not in [REG_SZ, REG_MULTI_SZ]
|
or key_type.value not in (REG_SZ, REG_MULTI_SZ)
|
||||||
):
|
):
|
||||||
return default
|
return default
|
||||||
|
|
||||||
|
@ -80,10 +80,10 @@ class HyperlinkLabel(sys.platform == 'darwin' and tk.Label or ttk.Label): # typ
|
|||||||
) -> dict[str, tuple[str, str, str, Any, Any]] | None:
|
) -> dict[str, tuple[str, str, str, Any, Any]] | None:
|
||||||
"""Change cursor and appearance depending on state and text."""
|
"""Change cursor and appearance depending on state and text."""
|
||||||
# This class' state
|
# This class' state
|
||||||
for thing in ['url', 'popup_copy', 'underline']:
|
for thing in ('url', 'popup_copy', 'underline'):
|
||||||
if thing in kw:
|
if thing in kw:
|
||||||
setattr(self, thing, kw.pop(thing))
|
setattr(self, thing, kw.pop(thing))
|
||||||
for thing in ['foreground', 'disabledforeground']:
|
for thing in ('foreground', 'disabledforeground'):
|
||||||
if thing in kw:
|
if thing in kw:
|
||||||
setattr(self, thing, kw[thing])
|
setattr(self, thing, kw[thing])
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user