mirror of
https://github.com/ihaveamac/custom-install.git
synced 2025-12-06 06:41:45 +00:00
gui: reformat, add license information, use correct script name
This commit is contained in:
50
gui.py
50
gui.py
@@ -1,3 +1,9 @@
|
||||
# This file is a part of custom-install.py.
|
||||
#
|
||||
# Copyright (c) 2019-2020 Ian Burgwin
|
||||
# This file is licensed under The MIT License (MIT).
|
||||
# You can find the full license text in LICENSE.md in the root of this project.
|
||||
|
||||
# A gui for custom-install.py
|
||||
# By LyfeOnEdge
|
||||
import os, sys, platform, subprocess, threading
|
||||
@@ -5,6 +11,7 @@ import tkinter as tk
|
||||
import tkinter.filedialog as tkfiledialog
|
||||
import style
|
||||
|
||||
|
||||
# BUTTON_COLOR =
|
||||
# BUTTON_HIGHLIGHT_COLOR =
|
||||
# BUTTON_FONT =
|
||||
@@ -24,6 +31,7 @@ class themedFrame(tk.Frame):
|
||||
|
||||
class Button(tk.Label):
|
||||
"""Cross-platform button"""
|
||||
|
||||
def __init__(self, frame, callback, **kw):
|
||||
self.callback = callback
|
||||
self.background = "#aaaaaa"
|
||||
@@ -61,8 +69,10 @@ class Button(tk.Label):
|
||||
if not self.selected:
|
||||
self.configure(background=self.background)
|
||||
|
||||
|
||||
class PathEntry(tk.Entry):
|
||||
"""Tkinter entry widget with a button to set the file path using tkinter's file dialog"""
|
||||
|
||||
def __init__(self, frame, dir=False, filetypes=None, *args, **kw):
|
||||
self.dir = dir
|
||||
self.filetypes = filetypes
|
||||
@@ -101,14 +111,17 @@ class PathEntry(tk.Entry):
|
||||
else:
|
||||
self.set(tkfiledialog.askdirectory())
|
||||
|
||||
|
||||
class LabeledPathEntry(PathEntry):
|
||||
"""Gives the PathEntry class a label"""
|
||||
|
||||
def __init__(self, frame, text, *args, **kw):
|
||||
self.xtainer = themedFrame(frame)
|
||||
label = tk.Label(self.xtainer, text=text, background=style.BACKGROUND_COLOR, foreground=style.LABEL_COLOR)
|
||||
label.place(width=label.winfo_reqwidth(), relheight=1)
|
||||
PathEntry.__init__(self, self.xtainer, *args, **kw)
|
||||
PathEntry.place(self, relwidth = 1, relheight = 1, width = - (label.winfo_reqwidth() + 5), x = label.winfo_reqwidth() + 5)
|
||||
PathEntry.place(self, relwidth=1, relheight=1, width=- (label.winfo_reqwidth() + 5),
|
||||
x=label.winfo_reqwidth() + 5)
|
||||
|
||||
def place(self, **kw):
|
||||
self.xtainer.place(**kw)
|
||||
@@ -145,10 +158,10 @@ class AutoScroll(object):
|
||||
if m[0] != '_' and m not in ('config', 'configure'):
|
||||
setattr(self, m, getattr(master, m))
|
||||
|
||||
|
||||
@staticmethod
|
||||
def _autoscroll(sbar):
|
||||
'''Hide and show scrollbar as needed.'''
|
||||
|
||||
def wrapped(first, last):
|
||||
first, last = float(first), float(last)
|
||||
if first <= 0 and last >= 1:
|
||||
@@ -156,6 +169,7 @@ class AutoScroll(object):
|
||||
else:
|
||||
sbar.grid()
|
||||
sbar.set(first, last)
|
||||
|
||||
return wrapped
|
||||
|
||||
def __str__(self):
|
||||
@@ -165,12 +179,14 @@ class AutoScroll(object):
|
||||
def _create_container(func):
|
||||
'''Creates a tk Frame with a given master, and use this new frame to
|
||||
place the scrollbars and the widget.'''
|
||||
|
||||
def wrapped(cls, master, **kw):
|
||||
container = themedFrame(master)
|
||||
container.bind('<Enter>', lambda e: _bound_to_mousewheel(e, container))
|
||||
container.bind(
|
||||
'<Leave>', lambda e: _unbound_to_mousewheel(e, container))
|
||||
return func(cls, container, **kw)
|
||||
|
||||
return wrapped
|
||||
|
||||
|
||||
@@ -216,6 +232,7 @@ class ScrolledText(AutoScroll, tk.Text):
|
||||
tk.Text.__init__(self, master, **kw)
|
||||
AutoScroll.__init__(self, master)
|
||||
|
||||
|
||||
# from https://stackoverflow.com/questions/3221956/how-do-i-display-tooltips-in-tkinter
|
||||
|
||||
|
||||
@@ -223,6 +240,7 @@ class CreateToolTip(object):
|
||||
'''
|
||||
create a tooltip for a given widget
|
||||
'''
|
||||
|
||||
def __init__(self, widget, text='widget info'):
|
||||
self.widget = widget
|
||||
self.text = text
|
||||
@@ -256,6 +274,7 @@ class threader_object:
|
||||
things can be called asyncronously (you cannot start
|
||||
a new thread from within a tkinter callback so you
|
||||
must call it from an object that exists outside)"""
|
||||
|
||||
def do_async(self, func, arglist=[]):
|
||||
threading.Thread(target=func, args=arglist).start()
|
||||
|
||||
@@ -270,7 +289,8 @@ class gui(tk.Tk):
|
||||
self.f.place(relwidth=1, relheight=1)
|
||||
|
||||
outer_frame = themedFrame(self.f)
|
||||
outer_frame.place(relwidth = 1, relheight = 1, x = + style.STANDARD_OFFSET, width = - 2 * style.STANDARD_OFFSET, y = + style.STANDARD_OFFSET, height = - 2 * style.STANDARD_OFFSET)
|
||||
outer_frame.place(relwidth=1, relheight=1, x=+ style.STANDARD_OFFSET, width=- 2 * style.STANDARD_OFFSET,
|
||||
y=+ style.STANDARD_OFFSET, height=- 2 * style.STANDARD_OFFSET)
|
||||
|
||||
self.sd_box = LabeledPathEntry(outer_frame, "Path to SD root -", dir=True)
|
||||
self.sd_box.place(relwidth=1, height=20, x=0)
|
||||
@@ -288,11 +308,14 @@ class gui(tk.Tk):
|
||||
cia_container = themedFrame(outer_frame, borderwidth=0, highlightthickness=0)
|
||||
cia_container.place(y=90, relwidth=1, height=115)
|
||||
|
||||
cia_label = tk.Label(cia_container, text = "cia paths - ", foreground = style.LABEL_COLOR, background = style.BACKGROUND_COLOR)
|
||||
cia_label = tk.Label(cia_container, text="cia paths - ", foreground=style.LABEL_COLOR,
|
||||
background=style.BACKGROUND_COLOR)
|
||||
cia_label.place(relwidth=1, height=20)
|
||||
self.cia_box = tk.Listbox(cia_container, highlightthickness = 0, bg = style.ENTRY_COLOR, foreground = style.ENTRY_FOREGROUND)
|
||||
self.cia_box = tk.Listbox(cia_container, highlightthickness=0, bg=style.ENTRY_COLOR,
|
||||
foreground=style.ENTRY_FOREGROUND)
|
||||
self.cia_box.place(relwidth=1, height=70, y=20)
|
||||
CreateToolTip(cia_label, "Select the cias you wish to install to the sd card. The `add folder` button will add all cias in the selected folder, but will not check subdirs. The `remove cia` button will remove the currently selected file from the listbox.")
|
||||
CreateToolTip(cia_label,
|
||||
"Select the cias you wish to install to the sd card. The `add folder` button will add all cias in the selected folder, but will not check subdirs. The `remove cia` button will remove the currently selected file from the listbox.")
|
||||
|
||||
add_cia_button = Button(cia_container, self.add_cia, text="add cia", font=style.monospace)
|
||||
add_cia_button.place(relx=0, relwidth=0.333, height=20, y=92, width=- 6)
|
||||
@@ -305,10 +328,13 @@ class gui(tk.Tk):
|
||||
# -------------------------------------------------
|
||||
|
||||
self.skip_contents = tk.IntVar()
|
||||
skip_contents_checkbutton = tk.Checkbutton(outer_frame, text="Skip contents? (only add title info)", variable=self.skip_contents, background = style.BACKGROUND_COLOR, foreground = style.LABEL_COLOR, borderwidth = 0, highlightthickness = 0)
|
||||
skip_contents_checkbutton = tk.Checkbutton(outer_frame, text="Skip contents? (only add title info)",
|
||||
variable=self.skip_contents, background=style.BACKGROUND_COLOR,
|
||||
foreground=style.LABEL_COLOR, borderwidth=0, highlightthickness=0)
|
||||
skip_contents_checkbutton.place(relwidth=1, y=205, height=20)
|
||||
|
||||
console_label = tk.Label(outer_frame, text = "Console:", background = "black", foreground = "white", font = style.boldmonospace, borderwidth = 0, highlightthickness = 0)
|
||||
console_label = tk.Label(outer_frame, text="Console:", background="black", foreground="white",
|
||||
font=style.boldmonospace, borderwidth=0, highlightthickness=0)
|
||||
console_label.place(relwidth=1, height=20, y=230)
|
||||
self.console = ScrolledText(outer_frame, background="black", foreground="white", highlightthickness=0)
|
||||
self.console.place(relwidth=1, relheight=1, y=250, height=- 272)
|
||||
@@ -322,7 +348,8 @@ class gui(tk.Tk):
|
||||
|
||||
boot9 = self.boot9_box.get()
|
||||
if not boot9:
|
||||
self.output_to_console("Warning - boot9 not selected, if it's not set externally you may run into problems.\n")
|
||||
self.output_to_console(
|
||||
"Warning - boot9 not selected, if it's not set externally you may run into problems.\n")
|
||||
argstring += f"-b {boot9} "
|
||||
|
||||
sed = self.sed_box.get()
|
||||
@@ -362,7 +389,8 @@ class gui(tk.Tk):
|
||||
def add_cia_folder(self):
|
||||
cia_dir_to_add = tkfiledialog.askdirectory()
|
||||
if cia_dir_to_add:
|
||||
cias_to_add = [f for f in os.listdir(cia_dir_to_add) if (os.path.isfile(os.path.join(cia_dir_to_add, f)) and f.endswith(".cia"))]
|
||||
cias_to_add = [f for f in os.listdir(cia_dir_to_add) if
|
||||
(os.path.isfile(os.path.join(cia_dir_to_add, f)) and f.endswith(".cia"))]
|
||||
if cias_to_add:
|
||||
for cia_to_add in cias_to_add:
|
||||
self.cia_box.insert('end', cia_to_add)
|
||||
@@ -385,7 +413,7 @@ class gui(tk.Tk):
|
||||
def execute_script(argstring, printer):
|
||||
"""Wrapper function to pipe install script output to a printer"""
|
||||
try:
|
||||
args = [sys.executable, '-u', os.path.join(os.path.dirname(__file__), "custom-install.py")]
|
||||
args = [sys.executable, '-u', os.path.join(os.path.dirname(__file__), "custominstall.py")]
|
||||
for arg in argstring.split():
|
||||
args.append(arg.strip())
|
||||
p = subprocess.Popen(args,
|
||||
|
||||
Reference in New Issue
Block a user