Updater: refact as a class
This commit is contained in:
parent
ed0364eb7a
commit
238b26067e
49
Updater.py
49
Updater.py
@ -5,34 +5,39 @@ from tkinter.messagebox import *
|
|||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
file = None
|
|
||||||
def Install():
|
|
||||||
|
|
||||||
ip = e.get()
|
class Updater(Frame):
|
||||||
print ("Installing ",file)
|
file = None
|
||||||
print ("At ip ", ip)
|
|
||||||
|
|
||||||
if file != None:
|
def __init__(self, win, **kwargs):
|
||||||
subprocess.call(["python", "espota.py", "-i", ip, "-f", file])
|
Frame.__init__(self, win, **kwargs)
|
||||||
|
button_opt = {'fill': constants.BOTH, 'padx': 5, 'pady': 5}
|
||||||
|
Button(root, text='Select firmware',
|
||||||
|
command=self.askopenfile).pack(**button_opt)
|
||||||
|
|
||||||
|
self.ipEntry = Entry(root)
|
||||||
|
self.ipEntry.pack()
|
||||||
|
self.ipEntry.delete(0, END)
|
||||||
|
self.ipEntry.insert(0, "192.168.0.XX")
|
||||||
|
|
||||||
|
Button(root, text='Install', command=self.install).pack(pady=20)
|
||||||
|
|
||||||
|
def install(self):
|
||||||
|
ip = self.ipEntry.get()
|
||||||
|
print("Installing", self.file, "at ip", ip)
|
||||||
|
|
||||||
|
if self.file != None:
|
||||||
|
subprocess.call(["python", "espota.py", "-i", ip, "-f", self.file])
|
||||||
else:
|
else:
|
||||||
showerror("Error", "Select a firmware first")
|
showerror("Error", "Select a firmware first")
|
||||||
|
|
||||||
|
def askopenfile(self):
|
||||||
def askopenfile():
|
self.file = filedialog.askopenfilename(
|
||||||
global file
|
title='Select Firmware', filetypes=[('binaries', '*.bin')])
|
||||||
file = filedialog.askopenfilename(title='Select Firmware', filetypes=[('binaries', '*.bin')])
|
|
||||||
|
|
||||||
root = Tk()
|
root = Tk()
|
||||||
root.title("Firmware Updater")
|
root.title("Firmware Updater")
|
||||||
|
|
||||||
button_opt = {'fill': constants.BOTH, 'padx': 5, 'pady': 5}
|
updater = Updater(root)
|
||||||
Button(root, text='Select firmware', command=askopenfile).pack(**button_opt)
|
updater.mainloop()
|
||||||
|
updater.destroy()
|
||||||
e = Entry(root)
|
|
||||||
e.pack()
|
|
||||||
e.delete(0, END)
|
|
||||||
e.insert(0, "192.168.0.XX")
|
|
||||||
|
|
||||||
Button(root, text = 'Install', command = Install).pack(pady=20)
|
|
||||||
|
|
||||||
root.mainloop()
|
|
||||||
|
Loading…
Reference in New Issue
Block a user