Rewrite main to use AboutData, drop arguments

This commit is contained in:
Björn Bidar 2023-10-15 03:03:04 +03:00 committed by Roman
parent eba4cd596a
commit 0b65600489
3 changed files with 31 additions and 40 deletions

View File

@ -1,13 +1,8 @@
from pathlib import Path
import re
import setuptools
setup_dir = Path(__file__).resolve().parent
version = re.search( r'__version__ = "(.*)"', Path(setup_dir, 'waypaper/__main__.py').open().read())
if version is None:
raise SystemExit("Could not determine version to use")
version = version.group(1)
setuptools.setup(
name='waypaper',
author='Roman Anufriev',
@ -23,7 +18,7 @@ setuptools.setup(
]
},
install_requires=["PyGObject", "importlib_metadata", "platformdirs"],
version=version,
version='0.0.2',
python_requires='>3.9',
classifiers=[
"Development Status :: 4 - Beta",

View File

@ -1,16 +1,40 @@
"""Main module that runs the program and either runs GUI or just changer wallpaper"""
import time
import argparse
from waypaper.config import cf
from waypaper.arguments import args
from waypaper.config import Config
from waypaper.app import App
from waypaper.changer import change_wallpaper
from waypaper.common import get_random_file
from waypaper.aboutdata import AboutData
from waypaper.options import FILL_OPTIONS, BACKEND_OPTIONS
aboutData = AboutData()
cf = Config()
if cf.lang == "de":
from waypaper.translation_de import *
elif cf.lang == "fr":
from waypaper.translation_fr import *
elif cf.lang == "ru":
from waypaper.translation_ru import *
elif cf.lang == "pl":
from waypaper.translation_pl import *
else:
from waypaper.translation_en import *
__version__ = "2.0.2"
parser = argparse.ArgumentParser(prog = aboutData.applicationName(), description = MSG_DESC,
epilog = MSG_INFO)
parser.add_argument("-v", "--version", help=MSG_ARG_HELP, action="store_true")
parser.add_argument("--restore", help=MSG_ARG_REST, action="store_true")
parser.add_argument("--random", help=MSG_ARG_RAND, action="store_true")
parser.add_argument("--fill", help=MSG_ARG_FILL, action="store_true")
parser.add_argument("--backend", help=MSG_ARG_BACK, choices=BACKEND_OPTIONS)
args = parser.parse_args()
def run():
@ -29,12 +53,12 @@ def run():
continue
change_wallpaper(wallpaper, cf.fill_option, cf.color, cf.backend, monitor)
time.sleep(0.1)
exit()
exit(0)
# Print the version and quit:
if args.version:
print(f"waypaper v.{__version__}")
exit()
print(f"{aboutData.applicationName()} v.{aboutData.applicationVersion()}")
exit(0)
# Start GUI:
app = App()

View File

@ -1,28 +0,0 @@
"""Module that parses user arguments and returns them in args object"""
import argparse
from waypaper.options import FILL_OPTIONS, BACKEND_OPTIONS
from waypaper.config import cf
if cf.lang == "de":
from waypaper.translation_de import *
elif cf.lang == "fr":
from waypaper.translation_fr import *
elif cf.lang == "ru":
from waypaper.translation_ru import *
elif cf.lang == "pl":
from waypaper.translation_pl import *
elif cf.lang == "zh":
from waypaper.translation_zh import *
else:
from waypaper.translation_en import *
parser = argparse.ArgumentParser(prog = "waypaper", description = MSG_DESC, epilog = MSG_INFO)
parser.add_argument("-v", "--version", help=MSG_ARG_HELP, action="store_true")
parser.add_argument("--restore", help=MSG_ARG_REST, action="store_true")
parser.add_argument("--random", help=MSG_ARG_RAND, action="store_true")
parser.add_argument("--fill", help=MSG_ARG_FILL, action="store_true")
parser.add_argument("--backend", help=MSG_ARG_BACK, choices=BACKEND_OPTIONS)
args = parser.parse_args()