1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-23 12:20:30 +03:00

403 Commits

Author SHA1 Message Date
Athanasius
2b60220365 EDMarketConnector: popup for "already running"
* This also refactors code around so that isort and flake8 are happy
  about the module level imports.
2020-12-08 16:06:50 +00:00
A_D
d650db5a1a Added name mangling support to EDMCContextFilter
Python name mangling is more about name collisions than actually making
things private.

This commit adds a check to resolve mangled names to their runtime
names, and adds a just-in-case default to fetching the attribute.

Fixes #764
2020-12-08 15:59:40 +00:00
Athanasius
582b981afa Locale: Be even more paranoid about setting UTF-8 encoding
* Only set if not on win32, or if we are and a known good version of
 Windows 10 (or later).
2020-10-14 19:15:48 +01:00
Athanasius
58bf8466ae locale: Remove conditional on locale setting & comments cleanup
* We're using try/except so can just attempt the setting of a UTF-8
  encoding.  In cases where it doesn't work we'll have some obvious log
  output to help diagnose any issues it causes later.

* Cleaned up the comments to be more 'why' than 'what'.
2020-10-06 16:16:21 +01:00
Athanasius
b235684dd6 Only attempt locale changes if *not* running frozen on win32.
Any running from source, or on a non-win32 platform will attempt to
force UTF-8 encoding.

For frozen win32 we'll rely on the windows manifest setting.  On too-old
versions of Windows we'll have to ensure all code works with non-UTF-8
encodings.
2020-10-06 15:16:15 +01:00
Athanasius
fb21cdfa94 Add reporting of Windows version at startup. 2020-10-06 15:03:51 +01:00
Athanasius
3063b237b6 Locale: Use LC_CTYPE as source of language for setting UTF-8 encoding
See #725 - LC_ALL is actually invalid here, but is allowed in Python
3.7.9, but not in later 3.8.x.
2020-10-01 11:00:11 +01:00
Athanasius
611db09fd0 Re-order imports so stdout/err redirect works for logging too.
Else the StreamHandler gets created with old stdout/err and causes
py2exe to attempt to write log file to CWD, which doesn't work when
installed.
2020-09-28 14:04:51 +01:00
Athanasius
9e6e718e23 Logging: Document trace/TRACE workaround & expand other docs. 2020-09-28 11:02:13 +01:00
Athanasius
1aba1a0596 Trace: Change several calls from debug to trace. 2020-09-23 22:07:18 +01:00
Athanasius
3c0ac76f90 Trace: Add support to EDMC.py & misc cleanups
* EDMC: Add --trace (to match EDMarketConnector.py) and TRACE as option to
  --loglevel.
* EDMC: docstrings added.
* EDMCLogging: Set logger name based on if GUI or CLI.
* EDMarketConnector:
  * Re-order imports.
  * Misc. formatting cleanups.
  * f-strings not .format().
  * Removed un-necessary "# noqa: N806" comments.
2020-09-23 17:38:38 +01:00
Athanasius
46e3b3aff8 Implement a TRACE level of logging.
For things that are too spammy for DEBUG, but we might need them
sometimes.
2020-09-23 15:58:19 +01:00
Athanasius
85d45aadd7 Place detailed logging for "Location" events.
To try and track down what's happening with #713
2020-09-23 11:45:48 +01:00
Athanasius
c1584d06fa EDMarketConnector.py: Tweak setting of UTF-8.
"UTF-8" is the official name, although it results in the same "utf8"
afterwards in this case.
2020-09-21 10:58:33 +01:00
Athanasius
8b5e5e73de Locale: More detailed login at startup around changes
As we might run into some special cases with users we need to log in
more detail what the locale is around our changes.

NB: Also contains some misc. PyCharm-enacted formatting changes, white
space, wrapping etc.
2020-09-15 10:28:28 +01:00
Athanasius
52dcd3b28a Use tkinter.filedialog on win32, because we now fix locale encoding
tkinter ends up calling something where utf8 characters won't work
because of the windows encoding, e.g. cp1252.

We can't set encoding just for the dialogs, as it's not thread safe.  So
we'll just set it at startup instead.  Utilising:

	locale.setlocale(locale.LC_ALL, '')

to get things set up initially, so we can properly retrieve the language
to go with the encoding on the subsequent setlocale() call.
2020-09-14 15:16:26 +01:00
Athanasius
cd24db88a9 UI Scaling: Size the Scale bar as per our startup value
If we use the last configured value then the width of the Scale bar
changes as per the user's last setting, even though they might not have
yet restarted for all the rest of the UI to resize.
2020-09-11 11:14:19 +01:00
Athanasius
0a5bbad55b UI Scaling: Change our %age scaling to be relative to base tk-scaling
So if at startup tk-scaling is 1.33 then a user configured 200(%) will
set it to 2.66 for this run.

* Low end of scale bar set to 10, not 0, because now 0 makes absolutely
  no sense.
* In theory the width of the scale bar, in pixels, is now also correctly
  scaled.
2020-09-11 09:26:01 +01:00
Athanasius
575acb3006 Log locale settings at start & ask in bug template. 2020-09-10 17:52:08 +01:00
Athanasius
f2ab8f0fd1 UI Scaling: Switch to using integers to avoid tk bug
Using a Tk.DoubleVar() with a locale where a comma is used as the
decimals separator leads to internal tk code recording values with the
comma but then other tk code not accepting that back, so it always
thinks the value is zero and the scale slider can't be moved.

Ref: https://stackoverflow.com/questions/45289237/tkinter-scale-slider-with-float-values-doesnt-work-with-locale-of-language-that

* Change to storing as a REG_DWORD under 'ui_scale' not 'ui_scaling'.
* Change all the code, except the call to *set* the tk scaling to use an
  integer, with 100 = 100%, i.e. equivalent to the old 1.0.
* Update strings slightly, so translations will need updating too.

NB: The theme.default_ui_scale value for plugin authors to query is
still the float that tk returns.
2020-09-10 16:54:14 +01:00
Athanasius
b4d7d56222 Startup: Log application and Python version, extra in debug.
* appversion and sys.version logged at INFO.
* At DEBUG: platform, argv[0], exec_prefix, executable, sys.path
2020-09-10 10:14:58 +01:00
Athanasius
1446796eb8 UI Scaling: Store pre-fiddling default in theme.default_ui_scale
This is in case anything needs to know the ratio between what was the
default and what we then set it to.
2020-09-09 16:18:23 +01:00
Athanasius
f25c743d14 Logging: Move stdout/stderr redirect to before logging can be run
If anything does `import logging` it's likely to grab a copy of
sys.stderr before we redirect it meaning things aren't properly
redirected when we start logging.

So put the redirect as early as possible in EDMarketConnector.py.

This will need a test implemented to be sure it's not accidentally
broken by addition of an import before this.
2020-09-09 15:26:08 +01:00
Athanasius
94607bf55f UI Scaling: Use a tk.Scale instead, allowing for finer grained setting.
* NB: Windows Registry has no type for 'Float', so we use a string.
* We now store '0.0' to mean 'default'.
2020-09-09 13:31:36 +01:00
Athanasius
1850354b8d UI Scaling: Implement a 'default' option
* If no ui_scaling yet set, set it to 'default'.
* 'default' added to dropdown choices.

Note that you still need an application restart for this to take effect.
2020-09-08 12:27:57 +01:00
Athanasius
09add21a1a Logging: DEBUG always to rotated files, configured level to stdout/err
* EDMCLogging.Logger.get_streamhandler() method to get the
  logger_channel so prefs.py can call setLevel() on it.
* The top-level Logger level is always DEBUG.
* The RotatingFileHandler level is always DEBUG.
* The StreamHandler level is as configured by the user.
* EDMCLogging now creates a singleton of EDMCLogging.Logger and its
  associated Logger.
* plug.py tweaked to only import EDMCLogging where it's needed for
  getting/creating plugin loggers, else `import logging`.
2020-09-08 10:03:16 +01:00
Athanasius
d940357854 EDMarketConnector.py: Blank line at the end. 2020-09-07 14:44:09 +01:00
Athanasius
10c3fec4f8 Logging: Set configured loglevel on creation 2020-09-07 14:40:55 +01:00
Athanasius
c3fbd1164e Logging: Implement additional logging to rotated set of files.
* All logging duplicated into %TEMP%/{appname}/{logger_name}.log
* These are handled by the RotatingFileHandler, currently set to 1MiB
  per file and 10 backup files.
* Do *NOT* setLevel() on the handlers, as we want to control the level
  up at the logger instead.  This would have caused the CL and GUI
  selection of loglevel to NOT have any effect (hidden by default having
  been DEBUG).
* EDMarketConnector.py now INFO logs its startup and exit.
2020-09-07 14:17:49 +01:00
Athanasius
bebe162071 logging: Now setting loglevel from Settings, and loading at start 2020-09-06 18:29:26 +01:00
Athanasius
c126251246 "Not Python 3.x" popup message sub-substitutions fixed.
string.format() doesn't assign to string, so actually need to do that.
2020-08-27 11:30:13 +01:00
Athanasius
98b6d4db38 Plugins "Not Python 3.x": Hacky escaping fix so translations work 2020-08-27 11:30:05 +01:00
Athanasius
3b87df17af Tweak EDMarketConnector.py startup so the redirect is first
* Don't want any output until the redirect is done when running frozen.
* Make the line buffering in the redirect more obvious.
2020-07-29 15:02:47 +01:00
Athanasius
4ecb4f573a 2 lines after def test_logging() 2020-07-29 15:02:47 +01:00
Athanasius
589bc0b5f1 Cover all cases with inspect
* <module> works.
* top-level function in <module> works, presumably also any other file.
* Call from within classes works.
* Extra, commented out, test cases in EDMarketConnector.py
2020-07-29 15:02:47 +01:00
Athanasius
a5b7bea2ca Move comment to line above if 2020-07-27 15:16:23 +01:00
Athanasius
9face638fe Minor cleanups all done.
Only remaining are:

 * TAE001 too few type annotations
 * Multiple "Cognitive complexity is too high" / "is too complex"
2020-07-27 13:00:59 +01:00
Athanasius
e0324cb9cd More flake8 cleanup 2020-07-27 11:15:03 +01:00
Athanasius
63f3859af4 Remove extraneous __class__ in logging strings 2020-07-27 10:56:57 +01:00
Athanasius
19e750eddd Use logger.exception() not log.error(.., exc_info=..) 2020-07-27 10:47:57 +01:00
Athanasius
6c9139e395 TODO: unittest hint about testing logging
And comment out the use of it here.
2020-07-27 10:35:08 +01:00
Athanasius
d7c2372417 Flake8 cleanup round #2 2020-07-27 10:14:16 +01:00
Athanasius
f9a23cc831 Clean up flake8 output for this branch 2020-07-27 09:37:10 +01:00
Athanasius
307910739a Remove now un-necessary imports for logging/traceback 2020-07-27 06:57:53 +01:00
Athanasius
66e2c354c7 Documentation update and getLogger() -> get_logger()
* Technically %(class)s can be e.g. A.B not just 'B' so say "name(s)".
* To not confuse EDMCLogging.getLogger() with logging.getLogger() it's
 been renamed to get_logger().
* Note how we signal errors with finding class and/or qualname.
* Call out EDMCLogging.py in Contributing.md.
2020-07-27 06:57:53 +01:00
Athanasius
596527bda2 Move logging setup to EDMCLogging.py with a class
* Also now providers single caller_class_and_qualname() method to get
 both strings, returned as a Tuple[str, str].  Either could be empty
 if something went wrong.
* Rather than a fragile 'skip' this now:
    1. Looks for the first up-stack frame with self of logging.Logger
    1. Then looks for the next up-stack frame with self NOT of
     logging.Logger.  This should be the call site we want.
2020-07-27 06:57:53 +01:00
Athanasius
c196a38e09 Add logging TODOs. logger creation & frame detection
* Nothing should "from EDMarketConnector import logger" any more, so
 we can move this back inside __main__ section
* We shouldn't rely on a magic number of frames to skip.  Detect the
 proper frame automatically.
2020-07-27 06:57:52 +01:00
Athanasius
2176187be7 Fix typos in class/qualname finders 2020-07-27 06:57:52 +01:00
Athanasius
4d7f81cec1 Add emergency print()s if we can't find class/qualname 2020-07-27 06:57:52 +01:00
Athanasius
89cadbc0eb Add paranoia checks to class and qualname finders 2020-07-27 06:57:52 +01:00