small fixes, autstart points to venv now

This commit is contained in:
Stefan Schmidt-Bilkenroth 2023-11-06 18:49:49 +01:00
parent e8c0341468
commit 10fbc62825
2 changed files with 59 additions and 55 deletions

View file

@ -1,4 +1,4 @@
#! /bin/python3
#! /usr/bin/python3
# import sys, shutil and osutil for file system access
import sys

112
setup.py
View file

@ -1,4 +1,4 @@
#! /bin/python3
#! /usr/bin/python3
import os
import subprocess
@ -28,6 +28,15 @@ except:
modules.append('requests')
master=None
#when setup can't find the conf file, inited is set to True
inited = False
#URL for the Intro-Screens, use as default, if conf is inited
introURL="https://wolke.netzbegruenung.de/s/2TPGWN5FtWYy2d8/download"
#set "dirty" flag to False
#any change should set it to True, so we can ask on quit to save data
isDirty=False
# try:
# import crontab
@ -47,7 +56,7 @@ Type=Application
Name=Green Signals Autostart
Comment=Starten der Slideshow von Gruene Signale
NoDisplay=false
Exec=sh -c 'cd %(path)s && /bin/python3 gruene_signale.py'
Exec=sh -c 'cd %(path)s && %(path)s/venv/bin/python3 gruene_signale.py'
"""
if os.path.isfile(autostartfile) == False:
if os.path.exists(os.path.dirname(autostartfile)) == False:
@ -84,52 +93,6 @@ def installModules():
failed.append(module)
modules=failed
#the main window
try:
master=tk.Tk()
except:
if len(sys.argv)>1:
# started from command line with arguments
if "modinst" in sys.argv:
installModules()
print("Die Module wurden erfolgreich installiert.")
if "autostart" in sys.argv:
createAutostart()
print("Das Autostart-Objekt wurde erstellt.")
if "noautostart" in sys.argv:
removeAutostart()
print("Das Autostart-Objekt wurde entfernt.")
else:
print("Es ist ein Tcl-Fehler aufgetreten. Das Skript muss im Desktop-Modus gestartet werden.")
print("""Folgende Kommandos sind erlaubt:
modinst: wenn notwendig werden fehlende Python Module installiert
autostart: Das Autostart-Objekt wird geschrieben
noautostart: Das Autostart-Objekt wird entfernt
Die weiteren Enstellungen koennen in der Datei gruene-signal.conf angepasst werden.""")
exit(0)
#init variables used in config file and some other places
doAutostart=tk.IntVar()
bild_dauer=tk.IntVar()
DEBUG_PREVIEW=tk.IntVar()
localPath=tk.StringVar()
remoteURL=tk.StringVar()
energyMode=tk.IntVar()
energyStart=tk.StringVar()
energyStop=tk.StringVar()
#when setup can't find the conf file, inited is set to True
inited = False
#URL for the Intro-Screens, use as default, if conf is inited
introURL="https://wolke.netzbegruenung.de/s/2TPGWN5FtWYy2d8/download"
#set "dirty" flag to False
#any change should set it to True, so we can ask on quit to save data
isDirty=False
class Popup(tk.Toplevel):
"""modal window requires a master"""
def __init__(self, master, **kwargs):
@ -295,7 +258,6 @@ def writeConfig(configFile=None):
with open(configFile, 'w') as file:
config.write(file)
def save():
global isDirty,inited
if isDirty == False:
@ -435,10 +397,14 @@ def createVenv():
print( "Not running in a virtual environment" )
if not os.path.exists( "./venv/bin/python3" ):
splash = tk.Tk()
splash.geometry("800x450+560+300")
splash.title("einen Moment...")
splash.geometry("440x120+660+400")
# splash.title("Einstellungen: Gruene Signale")
splash.configure(bg="DarkSeaGreen1")
splash.overrideredirect(True)
label = tk.Label(splash, text="Bitte ein wenig Geduld", font=("System", 32)).pack(pady=200)
label = tk.Label(splash, text="Bitte ein wenig Geduld", bg="DarkSeaGreen1", font=("System", 24))
label.pack(padx=4, pady=4, ipady=4)
label2 = tk.Label(splash, text="Es wird eine virtuelle Umgebung angelegt.", bg="DarkSeaGreen1", font=("System", 14))
label2.pack(padx=4, pady=0, ipady=4)
splash.update()
print( "Create a new virtual environment" )
subprocess.check_call([sys.executable, "-m", "venv", "./venv"] )
@ -452,10 +418,48 @@ def createVenv():
return
def main():
global master, dx, dy
global master #, dx, dy
createVenv()
readConfig()
#init variables used in config file and some other places
global doAutostart, bild_dauer, DEBUG_PREVIEW, localPath, remoteURL, energyMode, energyStart, energyStop
#the main window
try:
master=tk.Tk()
except:
if len(sys.argv)>1:
# started from command line with arguments
if "modinst" in sys.argv:
installModules()
print("Die Module wurden erfolgreich installiert.")
if "autostart" in sys.argv:
createAutostart()
print("Das Autostart-Objekt wurde erstellt.")
if "noautostart" in sys.argv:
removeAutostart()
print("Das Autostart-Objekt wurde entfernt.")
else:
print("Es ist ein Tcl-Fehler aufgetreten. Das Skript muss im Desktop-Modus gestartet werden.")
print("""Folgende Kommandos sind erlaubt:
modinst: wenn notwendig werden fehlende Python Module installiert
autostart: Das Autostart-Objekt wird geschrieben
noautostart: Das Autostart-Objekt wird entfernt
Die weiteren Enstellungen koennen in der Datei gruene-signal.conf angepasst werden.""")
exit(0)
doAutostart=tk.IntVar()
bild_dauer=tk.IntVar()
DEBUG_PREVIEW=tk.IntVar()
localPath=tk.StringVar()
remoteURL=tk.StringVar()
energyMode=tk.IntVar()
energyStart=tk.StringVar()
energyStop=tk.StringVar()
readConfig()
master.minsize(600,300)
master.geometry("800x450+560+300")
master.title("Einstellungen: Gruene Signale")