mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-14 16:27:13 +03:00
[2186] Remove Monitor, L10n References
This commit is contained in:
parent
57b6ecd88e
commit
93d26e07e0
50
l10n.py
50
l10n.py
@ -17,8 +17,8 @@ import re
|
|||||||
import sys
|
import sys
|
||||||
import warnings
|
import warnings
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
from os import pardir, listdir, sep, makedirs
|
from os import listdir, sep, makedirs
|
||||||
from os.path import basename, dirname, isdir, isfile, join, abspath, exists
|
from os.path import basename, dirname, isdir, join, abspath, exists
|
||||||
from typing import TYPE_CHECKING, Iterable, TextIO, cast
|
from typing import TYPE_CHECKING, Iterable, TextIO, cast
|
||||||
from config import config
|
from config import config
|
||||||
from EDMCLogging import get_main_logger
|
from EDMCLogging import get_main_logger
|
||||||
@ -39,12 +39,7 @@ logger = get_main_logger()
|
|||||||
LANGUAGE_ID = '!Language'
|
LANGUAGE_ID = '!Language'
|
||||||
LOCALISATION_DIR = 'L10n'
|
LOCALISATION_DIR = 'L10n'
|
||||||
|
|
||||||
if sys.platform == 'darwin':
|
if sys.platform == 'win32':
|
||||||
from Foundation import ( # type: ignore # exists on Darwin
|
|
||||||
NSLocale, NSNumberFormatter, NSNumberFormatterDecimalStyle
|
|
||||||
)
|
|
||||||
|
|
||||||
elif sys.platform == 'win32':
|
|
||||||
import ctypes
|
import ctypes
|
||||||
from ctypes.wintypes import BOOL, DWORD, LPCVOID, LPCWSTR, LPWSTR
|
from ctypes.wintypes import BOOL, DWORD, LPCVOID, LPCWSTR, LPWSTR
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@ -178,14 +173,8 @@ class _Translations:
|
|||||||
def available(self) -> set[str]:
|
def available(self) -> set[str]:
|
||||||
"""Return a list of available language codes."""
|
"""Return a list of available language codes."""
|
||||||
path = self.respath()
|
path = self.respath()
|
||||||
if getattr(sys, 'frozen', False) and sys.platform == 'darwin':
|
|
||||||
available = {
|
|
||||||
x[:-len('.lproj')] for x in listdir(path)
|
|
||||||
if x.endswith('.lproj') and isfile(join(x, 'Localizable.strings'))
|
|
||||||
}
|
|
||||||
|
|
||||||
else:
|
available = {x[:-len('.strings')] for x in listdir(path) if x.endswith('.strings')}
|
||||||
available = {x[:-len('.strings')] for x in listdir(path) if x.endswith('.strings')}
|
|
||||||
|
|
||||||
return available
|
return available
|
||||||
|
|
||||||
@ -206,9 +195,6 @@ class _Translations:
|
|||||||
def respath(self) -> str:
|
def respath(self) -> str:
|
||||||
"""Path to localisation files."""
|
"""Path to localisation files."""
|
||||||
if getattr(sys, 'frozen', False):
|
if getattr(sys, 'frozen', False):
|
||||||
if sys.platform == 'darwin':
|
|
||||||
return abspath(join(dirname(sys.executable), pardir, 'Resources'))
|
|
||||||
|
|
||||||
return abspath(join(dirname(sys.executable), LOCALISATION_DIR))
|
return abspath(join(dirname(sys.executable), LOCALISATION_DIR))
|
||||||
|
|
||||||
if __file__:
|
if __file__:
|
||||||
@ -234,10 +220,6 @@ class _Translations:
|
|||||||
except OSError:
|
except OSError:
|
||||||
logger.exception(f'could not open {file_path}')
|
logger.exception(f'could not open {file_path}')
|
||||||
|
|
||||||
elif getattr(sys, 'frozen', False) and sys.platform == 'darwin':
|
|
||||||
res_path = join(self.respath(), f'{lang}.lproj', 'Localizable.strings')
|
|
||||||
return open(res_path, encoding='utf-16')
|
|
||||||
|
|
||||||
res_path = join(self.respath(), f'{lang}.strings')
|
res_path = join(self.respath(), f'{lang}.strings')
|
||||||
return open(res_path, encoding='utf-8')
|
return open(res_path, encoding='utf-8')
|
||||||
|
|
||||||
@ -245,15 +227,6 @@ class _Translations:
|
|||||||
class _Locale:
|
class _Locale:
|
||||||
"""Locale holds a few utility methods to convert data to and from localized versions."""
|
"""Locale holds a few utility methods to convert data to and from localized versions."""
|
||||||
|
|
||||||
def __init__(self) -> None:
|
|
||||||
if sys.platform == 'darwin':
|
|
||||||
self.int_formatter = NSNumberFormatter.alloc().init()
|
|
||||||
self.int_formatter.setNumberStyle_(NSNumberFormatterDecimalStyle)
|
|
||||||
self.float_formatter = NSNumberFormatter.alloc().init()
|
|
||||||
self.float_formatter.setNumberStyle_(NSNumberFormatterDecimalStyle)
|
|
||||||
self.float_formatter.setMinimumFractionDigits_(5)
|
|
||||||
self.float_formatter.setMaximumFractionDigits_(5)
|
|
||||||
|
|
||||||
def stringFromNumber(self, number: float | int, decimals: int | None = None) -> str: # noqa: N802
|
def stringFromNumber(self, number: float | int, decimals: int | None = None) -> str: # noqa: N802
|
||||||
warnings.warn(DeprecationWarning('use _Locale.string_from_number instead.'))
|
warnings.warn(DeprecationWarning('use _Locale.string_from_number instead.'))
|
||||||
return self.string_from_number(number, decimals) # type: ignore
|
return self.string_from_number(number, decimals) # type: ignore
|
||||||
@ -279,14 +252,6 @@ class _Locale:
|
|||||||
if decimals == 0 and not isinstance(number, numbers.Integral):
|
if decimals == 0 and not isinstance(number, numbers.Integral):
|
||||||
number = int(round(number))
|
number = int(round(number))
|
||||||
|
|
||||||
if sys.platform == 'darwin':
|
|
||||||
if not decimals and isinstance(number, numbers.Integral):
|
|
||||||
return self.int_formatter.stringFromNumber_(number)
|
|
||||||
|
|
||||||
self.float_formatter.setMinimumFractionDigits_(decimals)
|
|
||||||
self.float_formatter.setMaximumFractionDigits_(decimals)
|
|
||||||
return self.float_formatter.stringFromNumber_(number)
|
|
||||||
|
|
||||||
if not decimals and isinstance(number, numbers.Integral):
|
if not decimals and isinstance(number, numbers.Integral):
|
||||||
return locale.format_string('%d', number, True)
|
return locale.format_string('%d', number, True)
|
||||||
return locale.format_string('%.*f', (decimals, number), True)
|
return locale.format_string('%.*f', (decimals, number), True)
|
||||||
@ -299,9 +264,6 @@ class _Locale:
|
|||||||
:param string: The string to convert
|
:param string: The string to convert
|
||||||
:return: None if the string cannot be parsed, otherwise an int or float dependant on input data.
|
:return: None if the string cannot be parsed, otherwise an int or float dependant on input data.
|
||||||
"""
|
"""
|
||||||
if sys.platform == 'darwin':
|
|
||||||
return self.float_formatter.numberFromString_(string)
|
|
||||||
|
|
||||||
with suppress(ValueError):
|
with suppress(ValueError):
|
||||||
return locale.atoi(string)
|
return locale.atoi(string)
|
||||||
|
|
||||||
@ -332,10 +294,8 @@ class _Locale:
|
|||||||
:return: The preferred language list
|
:return: The preferred language list
|
||||||
"""
|
"""
|
||||||
languages: Iterable[str]
|
languages: Iterable[str]
|
||||||
if sys.platform == 'darwin':
|
|
||||||
languages = NSLocale.preferredLanguages()
|
|
||||||
|
|
||||||
elif sys.platform != 'win32':
|
if sys.platform != 'win32':
|
||||||
# POSIX
|
# POSIX
|
||||||
lang = locale.getlocale()[0]
|
lang = locale.getlocale()[0]
|
||||||
languages = [lang.replace('_', '-')] if lang else []
|
languages = [lang.replace('_', '-')] if lang else []
|
||||||
|
23
monitor.py
23
monitor.py
@ -38,16 +38,7 @@ if TYPE_CHECKING:
|
|||||||
def _(x: str) -> str:
|
def _(x: str) -> str:
|
||||||
return x
|
return x
|
||||||
|
|
||||||
if sys.platform == 'darwin':
|
if sys.platform == 'win32':
|
||||||
from fcntl import fcntl
|
|
||||||
|
|
||||||
from AppKit import NSWorkspace
|
|
||||||
from watchdog.events import FileSystemEventHandler
|
|
||||||
from watchdog.observers import Observer
|
|
||||||
from watchdog.observers.api import BaseObserver
|
|
||||||
F_GLOBAL_NOCACHE = 55
|
|
||||||
|
|
||||||
elif sys.platform == 'win32':
|
|
||||||
import ctypes
|
import ctypes
|
||||||
from ctypes.wintypes import BOOL, HWND, LPARAM, LPWSTR
|
from ctypes.wintypes import BOOL, HWND, LPARAM, LPWSTR
|
||||||
|
|
||||||
@ -382,8 +373,6 @@ class EDLogs(FileSystemEventHandler):
|
|||||||
logfile = self.logfile
|
logfile = self.logfile
|
||||||
if logfile:
|
if logfile:
|
||||||
loghandle: BinaryIO = open(logfile, 'rb', 0) # unbuffered
|
loghandle: BinaryIO = open(logfile, 'rb', 0) # unbuffered
|
||||||
if sys.platform == 'darwin':
|
|
||||||
fcntl(loghandle, F_GLOBAL_NOCACHE, -1) # required to avoid corruption on macOS over SMB
|
|
||||||
|
|
||||||
self.catching_up = True
|
self.catching_up = True
|
||||||
for line in loghandle:
|
for line in loghandle:
|
||||||
@ -483,9 +472,6 @@ class EDLogs(FileSystemEventHandler):
|
|||||||
|
|
||||||
if logfile:
|
if logfile:
|
||||||
loghandle = open(logfile, 'rb', 0) # unbuffered
|
loghandle = open(logfile, 'rb', 0) # unbuffered
|
||||||
if sys.platform == 'darwin':
|
|
||||||
fcntl(loghandle, F_GLOBAL_NOCACHE, -1) # required to avoid corruption on macOS over SMB
|
|
||||||
|
|
||||||
log_pos = 0
|
log_pos = 0
|
||||||
|
|
||||||
sleep(self._POLL)
|
sleep(self._POLL)
|
||||||
@ -2144,12 +2130,7 @@ class EDLogs(FileSystemEventHandler):
|
|||||||
|
|
||||||
:return: bool - True if the game is running.
|
:return: bool - True if the game is running.
|
||||||
"""
|
"""
|
||||||
if sys.platform == 'darwin':
|
if sys.platform == 'win32':
|
||||||
for app in NSWorkspace.sharedWorkspace().runningApplications():
|
|
||||||
if app.bundleIdentifier() == 'uk.co.frontier.EliteDangerous':
|
|
||||||
return True
|
|
||||||
|
|
||||||
elif sys.platform == 'win32':
|
|
||||||
def WindowTitle(h): # noqa: N802
|
def WindowTitle(h): # noqa: N802
|
||||||
if h:
|
if h:
|
||||||
length = GetWindowTextLength(h) + 1
|
length = GetWindowTextLength(h) + 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user