-
Notifications
You must be signed in to change notification settings - Fork 2
/
friendly-buspirate.py
129 lines (98 loc) · 3.73 KB
/
friendly-buspirate.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
# This file is part of Friendly BusPirate.
# Friendly BusPirate is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
# Friendly BusPirate is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with Friendly BusPirate. If not, see <http://www.gnu.org/licenses/>.
#developed by Valentin Sasek <[email protected]>
import sys, asyncio
import tkinter as tk
from tkinter import ttk, PanedWindow, messagebox
from modules.settings import Settings
from modules.buspyrate import BusPyrate
from modules.editor import Editor
from modules.mode_selector import ModeSelector
from modules.port_selector import PortSelector
from modules.aux_mode import AuxMode
from modules.pinout import Pinout
from modules.menu import AppMenu
_WINDOW_TITLE = 'Friendly BusPirate (v0.1) - UI automation over BusPirate'
class App(tk.Tk):
def __init__(self, loop, interval=1/100):
super().__init__()
super().title(_WINDOW_TITLE)
super().geometry('%dx%d+%d+%d' % (950, 650, 400, 0))
self.loop = loop
self.protocol('WM_DELETE_WINDOW', self.close)
self.settings = Settings()
self.tasks = []
self.create_task(self.updater(interval))
self.port = None
self.initUi()
self.columnconfigure(0,weight=1)
self.rowconfigure(0,weight=1)
def create_task(self,task):
self.tasks.append(loop.create_task(task))
def initUi(self):
root = PanedWindow(self, orient='horizontal')
root.grid(row=0,column=0,sticky='wens')
left_pane = PanedWindow(root, orient='vertical')
root.add(left_pane,width=100,height=100)
left_pane.grid(row=0,column=0,sticky='wens')
self.port_selector = PortSelector(left_pane,self)
left_pane.add(self.port_selector, width=300,height=125)
self.mode_selector = ModeSelector(left_pane,self)
left_pane.add(self.mode_selector,height=220)
self.aux_mode = AuxMode(left_pane,self)
left_pane.add(self.aux_mode,height=145)
self.pinout = Pinout(left_pane,self)
left_pane.add(self.pinout,height=80)
self.right_pane = PanedWindow(root, orient='vertical')
root.add(self.right_pane)
self.right_pane.grid(row=0,column=1,sticky='wens')
root.columnconfigure(1, weight=1)
root.rowconfigure(0, weight=1)
self.editor = Editor(self.right_pane,self)
self.right_pane.add(self.editor,height=200)
self.console = BusPyrate(self.right_pane,self)
self.right_pane.add(self.console)
menu = AppMenu(self)
self.config(menu=menu)
self.bind('<F5>',self.console.run_script)
if self.port_selector()['autoconnect']:
self.port_selector.connect()
self.mode_selector.btn_get_modes.configure(command=self.console.detect_modes)
self.mode_selector.select_mode()
try:
self.editor.open(self.settings('recent')[0])
except:
pass
async def updater(self, interval):
while True:
self.tasks = [x for x in self.tasks if x is not None]
self.update()
await asyncio.sleep(interval)
def close(self):
if self.editor.close() is None:
return
for task in self.tasks:
task.cancel()
try:
self.after_cancel(self.voltages_timer)
except:
pass
self.loop.stop()
self.destroy()
def about(self):
messagebox.showinfo('Friendly BusPirate - About',
'''GUI interface for BusPirate
http://dangerousprototypes.com/docs/Bus_Pirate
developed by Valentin Sasek <[email protected]>''')
loop = asyncio.get_event_loop()
app = App(loop)
loop.run_forever()
loop.close()