Skip to content

Commit

Permalink
Use semver.Version to handle the program's version
Browse files Browse the repository at this point in the history
  • Loading branch information
zeptofine committed Apr 3, 2024
1 parent 11aaff0 commit ed1d936
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 19 deletions.
16 changes: 12 additions & 4 deletions source/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@
from modules import argument_parsing as ap
from modules._platform import _popen, get_cache_path, get_cwd, get_launcher_name, get_platform, is_frozen
from PyQt5.QtWidgets import QApplication
from semver import Version
from windows.dialog_window import DialogWindow

version = "2.0.24"
version = Version(
2,
0,
24,
)

_ = gettext.gettext

Expand All @@ -24,7 +29,10 @@
cache_path.mkdir()
logging.basicConfig(
format=_format,
handlers=[logging.FileHandler(cache_path.absolute() / "Blender Launcher.log"), logging.StreamHandler(stream=sys.stdout)],
handlers=[
logging.FileHandler(cache_path.absolute() / "Blender Launcher.log"),
logging.StreamHandler(stream=sys.stdout),
],
)
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -100,7 +108,7 @@ def main():
# Create an instance of application and set its core properties
app = QApplication([])
app.setStyle("Fusion")
app.setApplicationVersion(version)
app.setApplicationVersion(str(version))

set_lib_folder: Path | None = args.set_library_folder
if set_lib_folder is not None:
Expand Down Expand Up @@ -174,7 +182,7 @@ def check_for_instance():
socket.connectToServer("blender-launcher-server")
is_running = socket.waitForConnected()
if is_running:
socket.write(QByteArray(version.encode()))
socket.write(QByteArray(str(version).encode()))
socket.waitForBytesWritten()
socket.close()
sys.exit()
Expand Down
5 changes: 3 additions & 2 deletions source/modules/connection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
get_use_custom_tls_certificates,
)
from PyQt5.QtCore import QObject, pyqtSignal
from semver import Version
from urllib3 import PoolManager, ProxyManager, make_headers
from urllib3.contrib.socks import SOCKSProxyManager

Expand All @@ -35,7 +36,7 @@
class ConnectionManager(QObject):
error = pyqtSignal()

def __init__(self, version, proxy_type=None) -> None:
def __init__(self, version: Version, proxy_type=None) -> None:
super().__init__()
self.version = version
if proxy_type is None:
Expand All @@ -44,7 +45,7 @@ def __init__(self, version, proxy_type=None) -> None:
self.manager: REQUEST_MANAGER | None = None

# Basic Headers
self._headers = {"user-agent": f"Blender-Launcher-v2/{self.version} ({get_platform_full()})"}
self._headers = {"user-agent": f"Blender-Launcher-v2/{self.version!s} ({get_platform_full()})"}

# Get custom certificates file path
if is_frozen() is True:
Expand Down
1 change: 0 additions & 1 deletion source/widgets/library_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,6 @@ def launch(self, update_selection=False, exe=None, blendfile: Path | None = None
b3d_exe = Path(self.link) / "Blender" / "Blender.app"
args = f"open -W -n {b3d_exe.as_posix()} --args"


if blendfile is not None:
if isinstance(args, list):
args.append(blendfile.as_posix())
Expand Down
3 changes: 2 additions & 1 deletion source/windows/base_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
from PyQt5.QtCore import QFile, QPoint, Qt, QTextStream
from PyQt5.QtGui import QFont, QFontDatabase
from PyQt5.QtWidgets import QApplication, QMainWindow
from semver import Version

if get_enable_high_dpi_scaling():
QApplication.setAttribute(Qt.ApplicationAttribute.AA_EnableHighDpiScaling, True)
QApplication.setAttribute(Qt.ApplicationAttribute.AA_UseHighDpiPixmaps, True)


class BaseWindow(QMainWindow):
def __init__(self, parent=None, app: QApplication | None = None, version=None):
def __init__(self, parent=None, app: QApplication | None = None, version: Version | None = None):
super().__init__()
self.parent = parent

Expand Down
18 changes: 7 additions & 11 deletions source/windows/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class BlenderLauncher(BaseWindow):
quit_signal = pyqtSignal()
quick_launch_fail_signal = pyqtSignal()

def __init__(self, app: QApplication, version, offline: bool = False):
def __init__(self, app: QApplication, version: Version, offline: bool = False):
super().__init__(app=app, version=version)
self.resize(640, 480)
self.setMinimumSize(QSize(640, 480))
Expand Down Expand Up @@ -136,7 +136,7 @@ def __init__(self, app: QApplication, version, offline: bool = False):

# Global scope
self.app = app
self.version = version
self.version: Version = version
self.offline = offline
self.favorite: BaseBuildWidget | None = None
self.status = "Unknown"
Expand Down Expand Up @@ -356,10 +356,6 @@ def draw(self, polish=False):
self.LibraryToolBox.setCurrentIndex(get_default_library_page())
self.DownloadsToolBox.setCurrentIndex(get_default_downloads_page())

version_status = self.version
if not is_frozen(): # Add an asterisk to the statusbar version if running from source
version_status = f"{version_status}"

# Status bar
self.status_bar = QStatusBar(self)
self.setStatusBar(self.status_bar)
Expand All @@ -376,7 +372,7 @@ def draw(self, polish=False):
self.NewVersionButton = QPushButton()
self.NewVersionButton.hide()
self.NewVersionButton.clicked.connect(self.show_update_window)
self.statusbarVersion = QPushButton(version_status)
self.statusbarVersion = QPushButton(str(self.version))
self.statusbarVersion.clicked.connect(self.show_changelog)
self.statusbarVersion.setToolTip(
"The version of Blender Launcher that is currently run. Press to check changelog."
Expand Down Expand Up @@ -481,7 +477,7 @@ def on_activate_quick_launch(self):
self.quick_launch()

def show_changelog(self):
url = f"https://github.com/Victor-IX/Blender-Launcher-V2/releases/tag/v{self.version}"
url = f"https://github.com/Victor-IX/Blender-Launcher-V2/releases/tag/v{self.version!s}"
webbrowser.open(url)

def toggle_sync_library_and_downloads_pages(self, is_sync):
Expand Down Expand Up @@ -949,10 +945,10 @@ def set_status(self, status=None, is_force_check_on=None):
self.statusbarLabel.setText(self.status)

def set_version(self, latest_tag):
if "dev" in self.version:
if self.version.build is not None and "dev" in self.version.build:
return
latest = Version.parse(latest_tag[1:])
current = Version.parse(self.version)
current = self.version
logging.debug(f"Latest version on GitHub is {latest}")

if latest > current:
Expand Down Expand Up @@ -997,7 +993,7 @@ def read_socket_data(self):
assert self.socket is not None
data = self.socket.readAll()

if str(data, encoding="ascii") != self.version:
if str(data, encoding="ascii") != str(self.version):
self.dlg = DialogWindow(
parent=self,
title="Warning",
Expand Down

0 comments on commit ed1d936

Please sign in to comment.