Restructuration + init test system

This commit is contained in:
Jérémi N ‘EndMove’ 2022-09-11 11:52:41 +02:00
parent a3dd6698fc
commit 6b26b89c69
Signed by: EndMove
GPG Key ID: 65C4A02E1F5371A4
23 changed files with 68 additions and 90 deletions

View File

@ -1,4 +0,0 @@
{
"todo-tree.tree.showBadges": true,
"todo-tree.tree.showCountsInTree": true
}

View File

@ -21,7 +21,9 @@ To start, find the script to use or to add to your code [here](model/WebPicDownl
To use the script check the following prerequisites.
* Python `>= 3.10.6` ;
* beautifulsoup4 `>= 4.11.1` ;
* bs4 (BeautifulSoup) `>= 0.0.1` ;
* urllib3 `>= 1.26.12` ;
### Console Use ?

View File

@ -1,11 +0,0 @@
from auto_py_to_exe import __main__ as apte
import pyinstaller_versionfile
if __name__ == '__main__':
pyinstaller_versionfile.create_versionfile_from_input_file(
output_file="versionfile.txt",
input_file="metadata.yml",
#version="1.2.3.4" # optional, can be set to overwrite version information (equivalent to --version when using the CLI)
)
apte.__name__ = '__main__'
apte.run()

10
build_tool.py Normal file
View File

@ -0,0 +1,10 @@
from auto_py_to_exe import __main__ as apte
import pyinstaller_versionfile
if __name__ == '__main__':
pyinstaller_versionfile.create_versionfile_from_input_file(
output_file="app_version_file.txt",
input_file="app_metadata.yml"
)
apte.__name__ = '__main__'
apte.run()

19
main.py
View File

@ -1,13 +1,14 @@
import os
import re
import sys
from controller.HomeController import HomeController
from controller.InfoController import InfoController
from controller.MainController import MainController
from controller.Frames import Frames
from model.WebPicDownloader import WebPicDownloader
from view.HomeView import HomeView
from view.InfoView import InfoView
from view.MainWindow import MainWindow
from webpicdownloader.model.WebPicDownloader import WebPicDownloader
from webpicdownloader.controller.HomeController import HomeController
from webpicdownloader.controller.InfoController import InfoController
from webpicdownloader.controller.MainController import MainController
from webpicdownloader.controller.Frames import Frames
from webpicdownloader.view.HomeView import HomeView
from webpicdownloader.view.InfoView import InfoView
from webpicdownloader.view.MainWindow import MainWindow
def get_sys_directory() -> str:
@ -29,7 +30,9 @@ def get_config() -> dict:
'app_folder': os.getcwd(),
'app_version': '1.0.0', # This version must match with the version.txt at root
'app_version_date': '2022-09-05',
'app_version_source': 'https://git.endmove.eu/EndMove/WebPicDownloader/src/branch/dev/version.txt',
'sys_version_matcher': re.compile(r'^(\d{1,2}\.)(\d{1,2}\.)(\d{1,2})$'),
'sys_directory': get_sys_directory(),
'about_title': 'About WebPicDownloader',

4
run_tests.py Normal file
View File

@ -0,0 +1,4 @@
import unittest
loader = unittest.TestLoader()
runner = unittest.TextTestRunner()
runner.run(loader.discover('./test/'))

0
test/__init__.py Normal file
View File

View File

@ -0,0 +1,11 @@
import unittest
class TestUpdateModule(unittest.TestCase):
def test_lol(self):
self.assertTrue(True)
if __name__ == '__main__':
unittest.main()

View File

@ -1,54 +0,0 @@
import threading
class AsyncTask(threading.Thread):
"""
AsyncTask
AsyncTask is a utility class allowing to execute a task asynchronously in a thread.
For more informations read the constructor documentation.
@author Jérémi Nihart / EndMove
@link https://git.endmove.eu/EndMove/WebPicDownloader
@version 1.0.1
@since 2022-09-04
"""
# Variables
__run_callback = None
__run_args: list = None
__quite_callback = None
__quite_args = None
# Constructor
def __init__(self, rcallback, rargs=None, qcallback=None, qargs=None) -> None:
"""
Constructor
=> Indicate in the constructors, the parameters for launching the process, as
well as the stop otpions. Then use the function {AsyncTask.start()} to start
the thread and the processing.
[!]: The function {AsyncTask.run()} is reserved for the thread and should not be run
from outside.
* :rcallback: -> Asynchronous start function.
* :rargs: -> Arguments for the asyncrone startup function.
* :qcallback: -> Stop function to stop asynchronous processing.
* :qargs: -> Argument for the stop function.
"""
super().__init__()
self.__run_callback = rcallback
self.__run_args = rargs if rargs else ()
self.__quite_callback = qcallback if qcallback else lambda: print("exiting thread")
self.__quite_args = qargs if qargs else ()
def run(self) -> None:
"""
[Internal function of (threading.Thread)]
[!] : This function must not be used! Start the task with {AsyncTask.start()} !
"""
self.__run_callback(*self.__run_args)
def stop(self) -> None:
"""
Stop the running task, make sure you have previously defined the stop function.
"""
self.__quite_callback(*self.__quite_args)

View File

Before

Width:  |  Height:  |  Size: 264 KiB

After

Width:  |  Height:  |  Size: 264 KiB

View File

@ -1,5 +1,5 @@
from controller.MainController import MainController
from model.WebPicDownloader import MessageType, WebPicDownloader
from webpicdownloader.controller.MainController import MainController
from webpicdownloader.model.WebPicDownloader import MessageType, WebPicDownloader
class HomeController:

View File

@ -1,5 +1,5 @@
from controller.Frames import Frames
from controller.MainController import MainController
from webpicdownloader.controller.Frames import Frames
from webpicdownloader.controller.MainController import MainController
class InfoController:

View File

@ -1,5 +1,5 @@
import os
from controller.Frames import Frames
from webpicdownloader.controller.Frames import Frames
class MainController:

View File

@ -0,0 +1,17 @@
from http.client import HTTPException
import re
from urllib import request as http
def fetch_version(headers: str, url: str) -> str:
"""
"""
request = http.Request(url=url, headers=headers, method='GET')
response = http.urlopen(request)
if response.getcode() != 200:
raise HTTPException("Bad response returned by server")
return response.read().decode('utf-8')

View File

@ -2,8 +2,8 @@ import tkinter as tk
import tkinter.font as tfont
from tkinter import ttk
from tkinter import scrolledtext as tst
from controller.HomeController import HomeController
from view.MainWindow import MainWindow
from webpicdownloader.controller.HomeController import HomeController
from webpicdownloader.view.MainWindow import MainWindow
class HomeView(ttk.Frame):

View File

@ -1,9 +1,9 @@
import tkinter as tk
from tkinter import font
from tkinter import ttk
from controller.Frames import Frames
from controller.InfoController import InfoController
from view.MainWindow import MainWindow
from webpicdownloader.controller.Frames import Frames
from webpicdownloader.controller.InfoController import InfoController
from webpicdownloader.view.MainWindow import MainWindow
class InfoView(ttk.Frame):

View File

@ -1,7 +1,7 @@
import tkinter as tk
from tkinter import messagebox
from controller.Frames import Frames
from controller.MainController import MainController
from webpicdownloader.controller.Frames import Frames
from webpicdownloader.controller.MainController import MainController
class MainWindow(tk.Tk):
@ -48,7 +48,7 @@ class MainWindow(tk.Tk):
[internal function]
=> Initialize window parameters
"""
self.iconbitmap(f"{self.__controller.get_config('sys_directory')}\\assets\logo.ico") # App logo
self.iconbitmap(f"{self.__controller.get_config('sys_directory')}\\webpicdownloader\\assets\\logo.ico") # App logo
window_width = 430 # App width
window_height = 305 # App height
x_cordinate = int((self.winfo_screenwidth()/2) - (window_width/2))