Skip to content

Commit ea67d19

Browse files
committed
Added version to title
1 parent 2c57627 commit ea67d19

3 files changed

Lines changed: 49 additions & 3 deletions

File tree

src/layout_pyside.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@
4545
from constants import Colors, Fonts, Messages, UIConstants
4646

4747
# Local imports
48-
from utils import WindowInfo, clean_window_title, convert_hex_to_rgb, invert_hex_color
48+
from utils import (
49+
WindowInfo,
50+
clean_window_title,
51+
convert_hex_to_rgb,
52+
get_version,
53+
invert_hex_color,
54+
)
4955

5056
if TYPE_CHECKING:
5157
from collections.abc import Callable
@@ -91,6 +97,13 @@ def __init__(
9197
)
9298
global_hotkeys.start_checking_hotkeys()
9399

100+
# Set window title with version
101+
version = get_version()
102+
if version:
103+
self.setWindowTitle(f"Ultrawide Window Positioner v{version}")
104+
else:
105+
self.setWindowTitle("Ultrawide Window Positioner")
106+
94107
# ---------------- Helper methods ----------------
95108
def _init_state(self, is_admin:int, initial_states:dict) -> None:
96109
"""Initialize basic window state variables."""
@@ -1041,7 +1054,7 @@ def _create_apply_order_list(self, order: list | None = None) -> QWidget:
10411054
return container
10421055

10431056

1044-
def show_config_settings(self, sorted_windows: list) -> None:
1057+
def show_config_settings(self, sorted_windows: list) -> None: # noqa: PLR0915
10451058
"""Display settings rows, controls, and layout preview for selected windows."""
10461059
self.sorted_window = sorted_windows
10471060
self.settings_area = QWidget()

src/utils.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
"""Collection of utilities."""
22
import re
3+
import sys
34
from dataclasses import dataclass
5+
from pathlib import Path
46

57
import roman
8+
import win32api
69

710

811
@dataclass
@@ -96,3 +99,33 @@ def match_titles(section: str, title: str) -> bool:
9699
pattern = r"^" + re.escape(sc) + r"(\b|$)"
97100
return bool(re.match(pattern, tc))
98101

102+
103+
def get_version() -> str:
104+
"""Read the application version from version.txt file."""
105+
try:
106+
if hasattr(__import__("sys"), "_MEIPASS"):
107+
# Pyinstaller fix
108+
exe = Path(sys.executable)
109+
info = win32api.GetFileVersionInfo(str(exe), "\\")
110+
ms = info["FileVersionMS"]
111+
ls = info["FileVersionLS"]
112+
version = (win32api.HIWORD(ms), win32api.LOWORD(ms),
113+
win32api.HIWORD(ls), win32api.LOWORD(ls))
114+
return f"{version[0]}.{version[1]}.{version[2]}.{version[3]}"
115+
116+
version_file = Path(__file__).resolve().parent.parent / "version.txt"
117+
if version_file.exists():
118+
with Path.open(version_file, "r", encoding="utf-8") as f:
119+
content = f.read()
120+
# Extract filevers tuple: filevers=(1, 0, 3, 0)
121+
match = re.search(
122+
r"filevers=\((\d+),\s*(\d+),\s*(\d+),\s*(\d+)\)", content,
123+
)
124+
if match:
125+
major, minor, patch, build = match.groups()
126+
# Ignore the build number, format as X.Y.Z
127+
return f"{major}.{minor}.{patch}"
128+
except (OSError, AttributeError):
129+
pass
130+
131+
return None

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)