-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
122 lines (111 loc) · 4.18 KB
/
app.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
### ------------------------------------------------------- ###
### EZ PRESENCE - DEVELOPED AND MANAGED BY NOTSNIPED ###
### ------------------------------------------------------- ###
### thoseArchLinuxCoders 2021-2022 ###
### ------------------------------------------------------- ###
## Imports
import os
try:
import pypresence
except:
os.system('pip install pypresence')
try:
from tkinter import *
except:
print('Failed to initialize GUI. Try installing tk.\n On Arch Linux: sudo pacman -S tk\n On Debian/Ubuntu: sudo apt-get tk')
raise SystemExit
## Init
root = Tk()
root.title('EZPresence - Easy Discord RPC')
root.geometry('500x500')
root.resizable(False, False)
wdir = os.getcwd()
try:
icon = None
if os.name == "nt": icon = PhotoImage(file = f"{wdir}\\icons\\500x500.png")
elif os.name == "posix": icon = PhotoImage(file = "icons/500x500.png")
icon = PhotoImage(file = "~/Desktop/EZ_presence/icons/500x500.png")
root.iconphoto(False, icon)
except:
print('WARN: Unable to load \'/icons/500x500.png\', running without icons.')
rpc = pypresence.Presence(947710719770632234, pipe=0, loop=None, handler=None)
rpcstarted = False
#root.configure(background='#121212') [Uncomment for Dark Mode (Later)!]
## Tk Design
label1 = Label(root, text='Details:')
input1 = Entry(root, width=30)
label1.place(relx=0.1, rely=0.1)
input1.place(relx=0.5, rely=0.1)
label2 = Label(root, text='State:')
input2 = Entry(root, width=30)
label2.place(relx=0.1, rely=0.2)
input2.place(relx=0.5, rely=0.2)
label3 = Label(root, text='Large Image Text:')
input3 = Entry(root, width=30)
label3.place(relx=0.1, rely=0.3)
input3.place(relx=0.5, rely=0.3)
label4 = Label(root, text='Small Image Text:')
input4 = Entry(root, width=30)
label4.place(relx=0.1, rely=0.4)
input4.place(relx=0.5, rely=0.4)
label5 = Label(root, text='Start Timestamp (UNIX):')
input5 = Entry(root, width=30)
label5.place(relx=0.1, rely=0.5)
input5.place(relx=0.5, rely=0.5)
label6 = Label(root, text='End Timestamp (UNIX):')
input6 = Entry(root, width=30)
label6.place(relx=0.1, rely=0.6)
input6.place(relx=0.5, rely=0.6)
label9 = Label(root, text='beta1.3')
label9.place(relx=0.03, rely=0.91)
## Functions and Classes
def startRPC():
try:
i1 = None
i2 = None
i3 = "EZPresence"
i4 = "EZPresence"
i5 = None
i6 = None
if input1.get() != "": i1 = input1.get()
if input2.get() != "": i2 = input2.get()
if input3.get() != "": i3 = input3.get()
if input4.get() != "": i4 = input4.get()
if input5.get() != "": i5 = input5.get()
if input6.get() != "": i6 = input6.get()
rpc.connect()
rpc.update(state=str(i2), details=str(i1), start=i5, end=i6, large_text=str(i3), small_text=str(i4)) #large_text=str(i3), small_text=str(i4)#
label9['fg'] = 'green'
label9['text'] = 'Discord RPC started!'
rpcstarted = True
except Exception as e:
label9['fg'] = '#FF0000'
print(e)
if e == 'Child "activity" fails because child "assets" fails because child "large_text" fails because "large_text" length must be at least 2 characters long\n':
label9['text'] = '\'Large Image Text\' needs to be 2 or longer.'
elif e == 'Child "activity" fails because child "assets" fails because child "small_text" fails because "small_text" length must be at least 2 characters long':
label9['text'] = '\'Small Image Text\' needs to be 2 or longer.'
else:
label9['text'] = 'An error occured! Check console for info.'
def closeRPC():
rpc.close()
label9['fg'] = 'green'
label9['text'] = 'Discord RPC closed.'
rpcstarted = False
def exit():
print("Exiting EZPresence")
root.destroy()
## Tk Design (Continuation XD)
btn1 = Button(root, text='Start RPC', command=startRPC)
btn1.place(relx=0.755, rely=0.9)
btn2 = Button(root, text='Close RPC', command=closeRPC)
btn2.place(relx=0.555, rely=0.9)
btn3 = Button(root, text='Exit', command=exit)
btn3.place(relx=0.425, rely=0.9)
## Do Not Edit!
try:
root.mainloop()
except KeyboardInterrupt:
print("Safely cleaning-up runtime environment...")
if rpcstarted: rpc.close()
exit()