From 03424815c32cfd1b372d1ccbc3598b9152172368 Mon Sep 17 00:00:00 2001
From: Paul S
Date: Mon, 28 Jun 2021 15:21:08 +0200
Subject: [PATCH] Code refactoring; Ui-file in Ui-folder
---
.gitignore | 1 +
scripts/pyinstaller_v2.cmd | 95 ++++++++++++++++++++++++++++++++++++++
src/main.py | 6 ++-
{src => ui}/main.ui | 0
4 files changed, 100 insertions(+), 2 deletions(-)
create mode 100644 scripts/pyinstaller_v2.cmd
rename {src => ui}/main.ui (100%)
diff --git a/.gitignore b/.gitignore
index c5bf5ab..02ba53d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
env2
dist
+src/__pycache__
diff --git a/scripts/pyinstaller_v2.cmd b/scripts/pyinstaller_v2.cmd
new file mode 100644
index 0000000..da1ed72
--- /dev/null
+++ b/scripts/pyinstaller_v2.cmd
@@ -0,0 +1,95 @@
+@ECHO OFF
+:: --------------------------------------------------------------------------------------------------------------------------------------
+:: project: GarageCalc1 Window-Exe Generator
+:: summary: create a GarageCalc1-executable for Windows (version with no-console-windows as well as version with console windows for traces)
+:: file: pyinstaller.cmd
+:: date: version author
+:: 2021-06-27 1 paul salajean
+:: --------------------------------------------------------------------------------------------------------------------------------------
+SET version="v0.1"
+SET release_dir="D:\Temp\Prog\ownCloud\profp@uberspace\transfer"
+
+SET prev_dir=%cd%
+SET reinstall_venv="true"
+SET do_zip="false"
+
+CD ..
+
+ECHO Creating GarageCalc1 Windows.exe-version in folder %cd%\dist
+PAUSE
+REM pyinstaller --noconfirm --log-level=ERROR ^
+REM --onedir --nowindow ^
+REM --add-data="README;." ^
+REM --add-data="image1.png;img" ^
+REM --add-data="img;doc;ui" ^
+REM --add-data="LICENSE.txt;changelog.md;GarageCalc1.bat" ^
+REM --add-binary="libfoo.so;lib" ^
+REM --hidden-import=secret1 ^
+REM --hidden-import=secret2 ^
+REM --icon=.\img\GarageCalc1.ico ^
+REM --debug=imports ^
+REM --key=N0T1me40pp0ssum5
+REM --paths=.\src ^
+REM GarageCalc1.spec
+REM The key-string is a string of 16 characters which is used to encrypt each file of Python byte-code before it is stored in the archive inside the executable file.
+REM This feature uses the "tinyaes" module internally for the encryption.
+REM
+
+::one dir:
+ECHO ...Running...
+
+RMDIR /S /Q .\dist>nul
+RMDIR /S /Q .\build>nul
+
+::Use Virtual env
+IF %reinstall_venv%=="false" GOTO PYINSTALL
+ECHO Installing virtual env as ".\env2"...
+RMDIR /S /Q .\env2>NUL
+python -m venv env2
+CALL .\env2\Scripts\activate.bat
+
+ECHO Installing necessary python packages...
+python -m pip install --upgrade pip
+python -m pip install -r requirements.txt
+
+:PYINSTALL
+IF %reinstall_venv%=="false" CALL .\env2\Scripts\activate.bat
+ECHO Running "pyinstaller"...
+REM pyinstaller .\main.py --name=GarageCalc1 --noconfirm --console --clean --onedir --log-level=ERROR --hidden-import=PySide2.QtXml --icon=.\img\GarageCalc1.ico --add-data="LICENSE;." --add-data="README.md;." --add-data="changelog.md;." --add-data="*.ui;." --add-data="img;.\img"
+pyinstaller .\src\main.py --name=GarageCalc1 --noconfirm --windowed --clean --onefile --log-level=ERROR --hidden-import=PySide2.QtXml ^
+ --icon=.\img\icons8-garage-32.ico ^
+ --add-data="*.txt;." ^
+ --add-data="*.md;." ^
+ --add-data="ui;.\ui" ^
+ --add-data="img;.\img"
+
+::MOVE .\dist\GarageCalc1\*.md .\dist\
+::MOVE .\dist\GarageCalc1\LICENSE .\dist\
+
+::clean-up img-folder
+::MOVE .\dist\GarageCalc1\img .\dist\img>NUL
+
+::Remove temp dir and files
+DEL /Q *.spec>NUL
+RMDIR /S /Q .\build
+
+::Create self extracting archive
+IF %do_zip%=="false" GOTO END
+::-mx0 = Don't compress at all - just copy the contents to archive.
+::-mx1 = Consumes least time, but compression is low.
+::-mx3 = Better than -mx1.
+::-mx5 = This is default (compression is normal).
+::-mx7 = Maximum compression.
+::-mx9 = Ultra compression.
+"C:\Program Files\7-zip\7z.exe" a %release_dir%\GarageCalc1_%version%_portable.exe -mx9 -sfx7z.sfx .\dist\*
+
+::Disable Virtual env
+CALL .\env2\Scripts\deactivate.bat
+
+:END
+CD %prev_dir%
+
+ECHO Done. Check %prev_dir%\..\dist
+IF %do_zip%=="true" ECHO Done. Check %release_dir%
+
+PAUSE
diff --git a/src/main.py b/src/main.py
index 22dbd50..baf068f 100644
--- a/src/main.py
+++ b/src/main.py
@@ -23,7 +23,6 @@ from PySide2.QtUiTools import QUiLoader
from utils import show_about, resource_path
# Local globals
-UI_FILE = "main.ui"
APP_NAME = "Garagenraum-Rechner"
APP_DISPNAME = "GarageCalc"
APP_VERSION = "v0.3"
@@ -32,6 +31,7 @@ APP_DESCR = "Berechnet zur Verfügung stehenden Garagenraum"
APP_COPYRIGHT = "(c) Paul Salajean 2021"
APP_WEBSITE = "https://gitlab.com/ProfP303"
APP_DESKTOPFILENAME = "GarageCalc"
+
APP_ICON = "./img/icons8-garage-32.ico"
ICON_NEW = "./img/icons8-new-file-32.png"
@@ -41,6 +41,8 @@ ICON_EXPORT = "./img/icons8-export-xls-32.png"
ICON_ABOUT = "./img/icons8-information-32.png"
ICON_QUIT = "./img/system-shutdown.png"
+UI_MAIN = "./ui/main.ui"
+
COL_STUFF = 0
COL_LENGTH = 1
COL_WIDTH = 2
@@ -72,7 +74,7 @@ class MyMainWindow(QMainWindow):
def load_ui(self):
loader = QUiLoader()
- path = os.path.join(os.path.dirname(__file__), resource_path( UI_FILE))
+ path = os.path.join(os.path.dirname(__file__), resource_path(UI_MAIN))
ui_file = QFile(path)
ui_file.open(QFile.ReadOnly)
self.ui = loader.load(ui_file, self)
diff --git a/src/main.ui b/ui/main.ui
similarity index 100%
rename from src/main.ui
rename to ui/main.ui