-
Notifications
You must be signed in to change notification settings - Fork 0
/
joyconppt-GUI.py
101 lines (88 loc) · 2.63 KB
/
joyconppt-GUI.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
# -*- coding: UTF-8 -*-
import Tkinter
import tkMessageBox
import ScrolledText
import PIL.Image
import PIL.ImageTk
import sys
import os
def resource_path(relative_path):
try:
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
root = Tkinter.Tk()
root.geometry('200x200')
root.resizable(False, False)
root.title('JoyConPPT')
root.iconbitmap(resource_path('joyconppt.ico'))
im1 = PIL.Image.open(resource_path('jc_right.png'))
im1.thumbnail((200,200))
jcimage_off = PIL.ImageTk.PhotoImage(im1)
im2 = PIL.Image.open(resource_path('jc_right_on.png'))
im2.thumbnail((200,200))
jcimage_on = PIL.ImageTk.PhotoImage(im2)
SW = Tkinter.Button(root,image=jcimage_off,height=200,width=200)
logs = ScrolledText.ScrolledText(root,height=15,width=20)
class IORedirector(object):
'''A general class for redirecting I/O to this Text widget.'''
def __init__(self,text_area):
self.text_area = text_area
self.text_area.tag_configure('STDOUT',foreground='black')
self.text_area.tag_configure('STDERR',foreground='red')
self.END = 'end'
class StdoutRedirector(IORedirector):
'''A class for redirecting stdout to this Text widget.'''
def write(self,str):
self.text_area.insert(self.END,str,'STDOUT')
self.text_area.see(self.END)
class StderrRedirector(IORedirector):
'''A class for redirecting stderr to this Text widget.'''
def write(self,str):
self.text_area.insert(self.END,str,'STDERR')
self.text_area.see(self.END)
sys.stdout = StdoutRedirector(logs)
sys.stderr = StderrRedirector(logs)
SW.grid(row=0)
logs.grid(row=0,column=1)
import joycon
import threading
run_statu = False
def change_statu():
global run_statu
run_statu = not(run_statu)
global SW
if run_statu == False:
SW.config(image=jcimage_off)
else:
SW.config(image=jcimage_on)
def runscript():
if run_statu == False:
try:
joycon.main()
except:
tkMessageBox.showinfo( "joystick error", "joystick error")
return
t=threading.Thread(target=joycon.threadfun)
t.start()
else:
joycon.postquit()
change_statu()
debug_statu = False
def bind_debug(event):
global debug_statu
if debug_statu == False:
root.geometry('')
else:
root.geometry('200x200')
debug_statu = not(debug_statu)
def bind_off(event):
if run_statu == True:
joycon.postquit()
change_statu()
root.bind('<F5>',bind_debug)
root.bind('<Escape>',bind_off)
SW.config(command=runscript)
# 进入消息循环
root.mainloop()