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

[Minor] Minor Code Tweaks

Officially Deprecates ttkHyperlinkLabel/openurl() function, a few minor code readability updates, and updates dependencies
This commit is contained in:
David Sangrey 2023-12-23 20:12:17 -05:00
parent b0b9113e51
commit 57b00c6105
No known key found for this signature in database
GPG Key ID: 3AEADBB0186884BC
5 changed files with 15 additions and 10 deletions

View File

@ -25,7 +25,7 @@ from config import config
from EDMCLogging import get_main_logger
if TYPE_CHECKING:
def _(x: str) -> str: ...
def _(x: str) -> str: return x
# Note that this is also done in EDMarketConnector.py, and thus removing this here may not have a desired effect
try:

View File

@ -5,7 +5,7 @@ wheel
# We can't rely on just picking this up from either the base (not venv),
# or venv-init-time version. Specify here so that dependabot will prod us
# about new versions.
setuptools==69.0.2
setuptools==69.0.3
# Static analysis tools
flake8==6.1.0
@ -18,7 +18,7 @@ flake8-noqa==1.3.2
flake8-polyfill==1.0.2
flake8-use-fstring==1.4
mypy==1.7.1
mypy==1.8.0
pep8-naming==0.13.3
safety==2.3.5
types-requests==2.31.0.10
@ -28,7 +28,7 @@ types-pkg-resources==0.1.3
autopep8==2.0.4
# Git pre-commit checking
pre-commit==3.5.0
pre-commit==3.6.0
# HTML changelogs
grip==4.6.2
@ -40,7 +40,7 @@ py2exe==0.13.0.1; sys_platform == 'win32'
# Testing
pytest==7.4.3
pytest-cov==4.1.0 # Pytest code coverage support
coverage[toml]==7.3.2 # pytest-cov dep. This is here to ensure that it includes TOML support for pyproject.toml configs
coverage[toml]==7.3.4 # pytest-cov dep. This is here to ensure that it includes TOML support for pyproject.toml configs
coverage-conditional-plugin==0.9.0
# For manipulating folder permissions and the like.
pywin32==306; sys_platform == 'win32'

View File

@ -5,6 +5,8 @@ Copyright (c) EDCD, All Rights Reserved
Licensed under the GNU General Public License.
See LICENSE file.
"""
from __future__ import annotations
import csv
import json
import sys
@ -22,7 +24,7 @@ from monitor import monitor
logger = EDMCLogging.get_main_logger()
if TYPE_CHECKING:
def _(x: str) -> str: ...
def _(x: str) -> str: return x
if sys.platform == 'win32':
import ctypes

2
td.py
View File

@ -32,7 +32,7 @@ def export(data: CAPIData) -> None:
with open(data_path / data_filename, 'wb') as h:
# Format described here: https://github.com/eyeonus/Trade-Dangerous/wiki/Price-Data
h.write('#! trade.py import -\n'.encode('utf-8'))
this_platform = sys.platform == 'darwin' and "Mac OS" or system()
this_platform = "Mac OS" if sys.platform == 'darwin' else system()
cmdr_name = data['commander']['name'].strip()
h.write(
f'# Created by {applongname} {appversion()} on {this_platform} for Cmdr {cmdr_name}.\n'.encode('utf-8')

View File

@ -22,20 +22,21 @@ from __future__ import annotations
import sys
import tkinter as tk
import warnings
import webbrowser
from tkinter import font as tk_font
from tkinter import ttk
from typing import TYPE_CHECKING, Any
if TYPE_CHECKING:
def _(x: str) -> str: ...
def _(x: str) -> str: return x
# FIXME: Split this into multi-file module to separate the platforms
class HyperlinkLabel(sys.platform == 'darwin' and tk.Label or ttk.Label): # type: ignore
"""Clickable label for HTTP links."""
def __init__(self, master: tk.Frame | None = None, **kw: Any) -> None:
def __init__(self, master: ttk.Frame | None = None, **kw: Any) -> None:
"""
Initialize the HyperlinkLabel.
@ -135,7 +136,7 @@ class HyperlinkLabel(sys.platform == 'darwin' and tk.Label or ttk.Label): # typ
url = self.url(self['text']) if callable(self.url) else self.url
if url:
self._leave(event) # Remove underline before we change window to browser
openurl(url)
webbrowser.open(url)
def _contextmenu(self, event: tk.Event) -> None:
if self['text'] and (self.popup_copy(self['text']) if callable(self.popup_copy) else self.popup_copy):
@ -183,4 +184,6 @@ def openurl(url: str) -> None:
ended up using `webbrowser.open()` *anyway*.
:param url: URL to open.
"""
warnings.warn("This function is deprecated. "
"Please use `webbrowser.open() instead.", DeprecationWarning, stacklevel=2)
webbrowser.open(url)