-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathagendador.py
146 lines (103 loc) · 3.86 KB
/
agendador.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
from tkinter import ttk
from tkinter.constants import CENTER
from functions.aux_functions import createDesktopShortcut
from classes.webbrowser import WebBrowser
from classes.eprocfiles import EprocFiles
from classes.agendadorgui import AgendadorGUI
from classes.windowsnotifier import WindowsNotifier
from pystray import Icon as icon, Menu as menu, MenuItem as item
from PIL import Image
from dotenv.main import load_dotenv
from threading import Thread
import time
import os
import sys
import psutil
from tkinter import messagebox
class ChildGUI(AgendadorGUI):
def initButtons(self):
self.buttonStyle = ttk.Style()
self.buttonStyle.configure("W.TButton", background = "white", foreground = "black", font = ("Open Sans", 11))
self.rootLoginButton = ttk.Button(self.root, style = "W.TButton", text = " Login\nePROC", command = self.insert_login, width = 50.75)
self.rootLoginButton.pack()
self.rootLoginButton.place(relx = 0.23, rely = 0.72, anchor = CENTER)
self.startButton = ttk.Button(self.root, style = "W.TButton", text = "Clique aqui para iniciar o programa", command = start, width = 27.75)
self.startButton.pack()
self.startButton.place(relx = 0.5, rely = 0.65, anchor = CENTER)
self.startButton.configure(state = "disabled")
def addToSystemTray(self):
self.iconImage = Image.open("img/icon.ico")
self.trayMenu = menu(
item("Mostrar/Esconder", self.initGUI, default = True),
item("Enviar notificações", getProcessesData),
item("Fechar programa", self.closeRootTray)
)
self.trayIcon = icon("Agendador ePROC", icon = self.iconImage, menu = self.trayMenu, title = "Agendador ePROC")
self.trayIcon.run()
def getProcessesData():
global browser
EprocFiles.resetFilesAndTables()
if len(programGUI.login) < 6 or len(programGUI.password) < 4:
programGUI.initGUI()
return
try:
browser = WebBrowser(programGUI.login, programGUI.password)
except:
programGUI.initGUI()
return
Thread(target = browser.startBrowser(), daemon = True).start()
while browser.thread is True:
time.sleep(1)
if browser.loginFail is True:
programGUI.loginFail = True
programGUI.initGUI()
return
if browser.error is True:
if programGUI.active is False:
programGUI.initGUI(error = True)
return
if programGUI.active is True:
programGUI.root.update()
scFile = EprocFiles("sc")
scFile.initFile()
prFile = EprocFiles("pr")
prFile.initFile()
if programGUI.active is True:
programGUI.updateStatusLabel("Enviando notificações...", destroy = True)
notifier = WindowsNotifier()
notifier.sendNotifications()
def start():
programGUI.updateStatusLabel("Carregando... Aguarde")
programGUI.changeButtonState("disable")
getProcessesData()
programGUI.complete(error = browser.error)
def main():
processos = 0
for pid in psutil.pids():
p = psutil.Process(pid)
if p.name().startswith("Agendador"):
processos += 1
if processos >= 2:
messagebox.showwarning("Programa aberto!", "O programa já está aberto!\nProcure pelo ícone na barra de tarefas")
sys.exit()
global programGUI
load_dotenv()
createDesktopShortcut()
programGUI = ChildGUI()
try:
programGUI.login = os.environ["EPROC_LOGIN"]
programGUI.password = os.environ["EPROC_PASSWORD"]
except:
programGUI.initGUI()
else:
getProcessesData()
programGUI.addToSystemTray()
if __name__ == "__main__":
main()
#
#
#
# python3 -m PyInstaller --noconsole --onedir --icon=img/icon.ico --name="Agendador ePROC" agendador.py
#
#
#