Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Cli launching, file associations, shortcut generation #127

Merged
merged 50 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
7a8d142
initial draft of the launching window
zeptofine Aug 1, 2024
34a4f57
add more attributes to queries, settings to launching_window
zeptofine Aug 1, 2024
d4e8c41
add timer and actually launching
zeptofine Aug 1, 2024
c8b078e
bind launch button
zeptofine Aug 1, 2024
67608bb
add file association launch target
zeptofine Aug 1, 2024
a7ea3eb
add button in settings
zeptofine Aug 2, 2024
bee0bc2
add registering Open With for Windows
zeptofine Aug 2, 2024
f84aa2f
force basicbuildinfos to use UTC timezone
zeptofine Aug 2, 2024
4076e38
Use a different key so privilege elevation is not necessary
zeptofine Aug 2, 2024
af3d49b
fix the broken unregister command
zeptofine Aug 2, 2024
74b5b9b
implement windows program shortcut properly
zeptofine Aug 3, 2024
5b9f688
allow registering open-with in non-frozen scenarios
zeptofine Aug 3, 2024
452c01b
disable buttons when associations are added and removed
zeptofine Aug 3, 2024
146a6fb
add cancel button, make matcher more strict
zeptofine Aug 3, 2024
fa95765
update pdm lock
zeptofine Aug 3, 2024
5ecd910
re-fix an old downloading bug
zeptofine Aug 3, 2024
e6f4e89
add launch timer configuration
zeptofine Aug 3, 2024
62a9db5
remove unnecessary function and comments
zeptofine Aug 3, 2024
9bfbb92
add registry edits for .blend1 files
zeptofine Aug 3, 2024
c28f5a7
add actual cli launching, no windows opening
zeptofine Aug 3, 2024
6afa7ef
fix quick launch option
zeptofine Aug 3, 2024
a138693
assertions to hide windows related issues in linux
zeptofine Aug 4, 2024
6ad30c9
fix shortcut creation cancellation
zeptofine Aug 4, 2024
01f4c85
fix shortcut creation cancellation (1)
zeptofine Aug 4, 2024
67fa49e
Remove Timer if Timer is set to -1
Victor-IX Aug 4, 2024
036fa4a
Change Timer Range
Victor-IX Aug 4, 2024
6e9c08d
Add parsing for build version and branch
Victor-IX Aug 4, 2024
b02640b
skip running timer when set to 0, add suffix to show meaning
zeptofine Aug 4, 2024
2c6abf0
Merge branch 'main' into cli-launching
Victor-IX Aug 4, 2024
4755792
improve build_info sorting method
zeptofine Aug 4, 2024
f387813
Improve version list readability
Victor-IX Aug 4, 2024
6d186ec
Merge branch 'cli-launching' of https://github.com/Victor-IX/Blender-…
Victor-IX Aug 4, 2024
3c92bf2
Update "Save Quarry" button
Victor-IX Aug 4, 2024
3051fc8
Make the white button darker to be able to see mouse feedback
Victor-IX Aug 4, 2024
3fb5b69
Revert "Update "Save Quarry" button"
Victor-IX Aug 5, 2024
d4fb0ee
Add version search syntax to the help
zeptofine Aug 5, 2024
b848d0b
New Icon for Blender Files
Victor-IX Aug 5, 2024
2466db9
Merge branch 'cli-launching' of https://github.com/Victor-IX/Blender-…
Victor-IX Aug 5, 2024
9c74eef
Fix new icon importing
Victor-IX Aug 5, 2024
d57e71e
refactor dictionaries, use logger
zeptofine Aug 5, 2024
5dd01cb
add padding to align text
zeptofine Aug 5, 2024
c7330fe
hide save button until usable, update program shortcut for linux
zeptofine Aug 6, 2024
5bde30d
rephrase save button
zeptofine Aug 9, 2024
d675193
use display_label for branch
zeptofine Aug 9, 2024
bee85c3
Add New icon in the blend file
Victor-IX Aug 11, 2024
77726a2
First Documentation Draft
Victor-IX Aug 11, 2024
5665714
Add new Blend file icon on the top left of the launching window
Victor-IX Aug 12, 2024
800b781
add bl_file.ico to pyinstaller bundle, point to it during file associ…
zeptofine Aug 13, 2024
a7d4b6a
add keypress shortcuts for LaunchingWindow
zeptofine Aug 13, 2024
a2eff56
ruff fixes
zeptofine Aug 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ nav:
- Settings: settings.md
- Manual Blender Installation: manual_build_installation.md
- Build Initialization: build_initialization.md
- File Association: file_association.md
- Troubleshooting: troubleshooting.md
- Known Issues: known_issues.md
- Feature Request: feature_request.md
Expand Down
41 changes: 41 additions & 0 deletions docs/mkdocs/file_association.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<style>body {text-align: justify}</style>

# File Association

## Version Selection

: TODO

## Branch

: TODO

## Build Hash

: TODO

## Date Selection

: TODO

### Latest

: TODO

### Any

: TODO

### Oldest

: TODO

## Build List

: TODO

## Save Current Query

: TODO

## Launch
Binary file modified docs/mkdocs/imgs/settings_window_general.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 33 additions & 2 deletions docs/mkdocs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@

## Settings Window

To open the **Settings Window**, use the button with a gear icon on the top left of the **Main Window**. All changes are saved automatically.
: To open the **Settings Window**, use the button with a gear icon on the top left of the **Main Window**. All changes are saved automatically.

## General

![General page of Settings](imgs/settings_window_general.png)

### Library Folder

**Library Folder** - a directory on the hard drive where all downloaded builds are stored. For detailed information, check the [Library Folder](library_folder.md) page.
: **Library Folder** - a directory on the hard drive where all downloaded builds are stored.

: For detailed information, check the [Library Folder](library_folder.md) page.

### Launch When System Starts

Expand All @@ -34,6 +36,35 @@ If this option is enabled, to completely close the **Blender Launcher** you need

: Sets the maximal number of **CPU Thread Blender** Launcher can use.

### File Association
: Use the Blender Launcher as Default program to launch `.blend` files with the desired version
: For detail information, check the [File Association](file_association.md) page.

#### Create Shortcut

: TODO

#### Register File Association

: Add Blender Launcher as the Default program to open `.blend` and `.blend1` files

#### Unregister File Association

: Remove the Blender Launcher as the Default program to open `.blend` and `.blend1` files

#### Launch Time Duration

: Set the time to automatically lunch a `.blend` file with the corresponding version

!!! info
Blend files will be automatically lunch after this timer if the correspond Blender version exist in the [Blender Launcher Library](library_folder.md)

```
-1 -> No Timer (Require the user to click on launch)
0 -> instant (Only if matching version exist)
3 -> 3 Seconde (Will lunch after 3s if matching version exist)
```

## Appearance

![Appearance page of Settings](imgs/settings_window_appearance.png)
Expand Down
645 changes: 392 additions & 253 deletions pdm.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencies = [
"pywin32==303; sys_platform == \"win32\"",
"distro>=1.8.0",
"semver>=3.0.2",
"zstandard>=0.23.0",
]
requires-python = ">=3.9, <3.11"
readme = "README.md"
Expand Down
1 change: 1 addition & 0 deletions scripts/build_win.bat
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ python -OO -m PyInstaller ^
--name="Blender Launcher" ^
--version-file="version.txt" ^
--add-binary="source\resources\icons\winblender.ico;files" ^
--add-data="source\resources\icons\bl\bl_file.ico;files" ^
--add-binary="source\resources\certificates\custom.pem;files" ^
--distpath="./dist/release" ^
source\main.py
1 change: 1 addition & 0 deletions scripts/build_win_debug.bat
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ python -OO -m PyInstaller ^
--name="Blender Launcher" ^
--version-file="version.txt" ^
--add-binary="source\resources\icons\winblender.ico;files" ^
--add-data="source\resources\icons\bl\bl_file.ico;files" ^
--add-binary="source\resources\certificates\custom.pem;files" ^
--distpath="./dist/debug" ^
source\main.py
33 changes: 33 additions & 0 deletions source/items/enablable_list_widget_item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from PyQt5.QtWidgets import QListWidgetItem

if TYPE_CHECKING:
from modules.build_info import BuildInfo
from PyQt5.QtGui import QFont


class EnablableListWidgetItem(QListWidgetItem):
def __init__(self, enabled_font: QFont, disable_font: QFont, build: BuildInfo, parent=None):
super().__init__(parent)
self._enabled = True
self.__enabled_font = enabled_font
self.__disable_font = disable_font
self.build = build

@property
def enabled(self):
return self._enabled

@enabled.setter
def enabled(self, value):
self._enabled = value
if value:
self.setFont(self.__enabled_font)
else:
self.setFont(self.__disable_font)

def __lt__(self, other: EnablableListWidgetItem):
return self.enabled < other.enabled if self.enabled != other.enabled else self.build < other.build
115 changes: 104 additions & 11 deletions source/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
import sys
from argparse import ArgumentParser
from pathlib import Path
from typing import NoReturn

import modules._resources_rc
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 modules.cli_launching import cli_launch
from modules.shortcut import register_windows_filetypes, unregister_windows_filetypes
from modules.version_matcher import VALID_FULL_QUERIES, VALID_QUERIES, VERSION_SEARCH_SYNTAX
from PyQt5.QtWidgets import QApplication
from semver import Version
from windows.dialog_window import DialogWindow
Expand Down Expand Up @@ -65,11 +69,15 @@ def main():

subparsers = parser.add_subparsers(dest="command")

update_parser = subparsers.add_parser("update", help="Update the application to a new version.", add_help=False)
update_parser = subparsers.add_parser(
"update",
help="Update the application to a new version.",
add_help=False,
)
add_help(update_parser)
update_parser.add_argument("version", help="Version to update to.", nargs="?")

parser.add_argument("-debug", help="Enable debug logging.", action="store_true")
parser.add_argument("-d", "-debug", "--debug", help="Enable debug logging.", action="store_true")
parser.add_argument("-set-library-folder", help="Set library folder", type=Path)
parser.add_argument(
"--offline",
Expand All @@ -84,12 +92,40 @@ def main():
action="store_true",
)

# possible launch_parser
# args:
# "launch": Launch a specific version of Blender. If no file or version is specified,
# the favorite build is chosen. If there is no favorite build, TODO: BUILD_CHOOSER
# "-f" | "--file": Path to a specific Blender file to launch.
# "-v" | "--version": Version to launch. If not specified, the latest stable release is used.
launch_parser = subparsers.add_parser(
"launch",
help="Launch a specific version of Blender. If not file or version is specified, Quick launch is chosen.",
add_help=False,
)
add_help(launch_parser)
grp = launch_parser.add_mutually_exclusive_group()
grp.add_argument("-f", "--file", type=Path, help="Path to a specific Blender file to launch.")
grp.add_argument(
"-ol", "--open-last", action="store_true", help="Open the last file in the specified blender build"
)

launch_parser.add_argument("-v", "--version", help=f"Version to launch. {VERSION_SEARCH_SYNTAX}")
launch_parser.add_argument(
"-c",
"--cli",
action="store_true",
help="Launch Blender from CLI. does not open any QT frontend. WARNING: LIKELY DOES NOT WORK IN WINDOWS BUNDLED EXECUTABLE",
)

# This could be used better
launch_target_parser = subparsers.add_parser(
"__launch_target",
help="This is a target for launching the program from a shortcut.",
add_help=False,
)
launch_target_parser.add_argument("file", nargs="?", type=Path, help="Path to a specific Blender file to launch.")

if sys.platform == "win32":
subparsers.add_parser(
"register",
help="Registers the program to read .blend builds. Adds Blender Launcher to the Open With window. (WIN ONLY)",
)
subparsers.add_parser("unregister", help="Undoes the changes that `register` makes. (WIN ONLY)")

args, argv = parser.parse_known_args()
if argv:
Expand All @@ -98,7 +134,7 @@ def main():

# Custom help is necessary for frozen Windows builds
if args.help:
ap.show_help(parser, update_parser, args)
ap.show_help(parser, update_parser, launch_parser, args)
sys.exit(0)

if args.debug:
Expand All @@ -118,8 +154,15 @@ def main():
if args.command == "update":
start_update(app, args.instanced, args.version)

# if args.command == "launch":
# ...
if args.command == "launch":
start_launch(app, args.file, args.version, args.open_last, cli=args.cli)
if args.command == "__launch_target" and args.file:
start_launch(app, args.file, None, False)

if args.command == "register":
start_register()
if args.command == "unregister":
start_unregister()

if not args.instanced:
check_for_instance()
Expand Down Expand Up @@ -175,6 +218,56 @@ def start_update(app: QApplication, is_instanced: bool, tag: str | None):
sys.exit(0)


def start_launch(
app: QApplication,
file: Path | None = None,
version_query: str | None = None,
open_last: bool = False,
cli: bool = False,
) -> NoReturn:
from modules.version_matcher import VersionSearchQuery
from windows.launching_window import LaunchingWindow

# convert version_query to VersionSearchQuery
if version_query is not None:
try:
query = VersionSearchQuery.parse(version_query)
except Exception:
print("Failed to parse query")
print(VERSION_SEARCH_SYNTAX)
print("Valid version queries include: ")
print(VALID_FULL_QUERIES)
sys.exit(1)
else:
query = None

# remove quotes around file path if they exist
if file is not None:
file = Path(str(file).strip('"'))

if cli:
cli_launch(file=file, version_query=query, open_last=open_last)
sys.exit(1)
else:
LaunchingWindow(app, version_query=query, blendfile=file, open_last=open_last).show()
sys.exit(app.exec())


def start_register():
import sys

register_windows_filetypes()

sys.exit(0)


def start_unregister():
import sys

unregister_windows_filetypes()
sys.exit(0)


def check_for_instance():
from PyQt5.QtCore import QByteArray
from PyQt5.QtNetwork import QLocalSocket
Expand Down
9 changes: 5 additions & 4 deletions source/modules/argument_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,20 @@ def error(parser: ArgumentParser, msg: str):
def show_help(
parser: ArgumentParser,
update_parser: ArgumentParser,
launch_parser: ArgumentParser,
args: Namespace,
):
if is_frozen() and sys.platform == "win32":
if args.command == "update":
show_windows_help(update_parser)
# elif args.command == "launch":
# print_windows_help(launch_parser)
elif args.command == "launch":
show_windows_help(launch_parser)
else:
show_windows_help(parser)
else:
if args.command == "update":
update_parser.print_help()
# elif args.command == "launch":
# launch_parser.print_help()
elif args.command == "launch":
launch_parser.print_help()
else:
parser.print_help()
Loading