2021-02-27 21:24:46 +00:00
|
|
|
import tkinter
|
2021-02-27 21:27:43 +00:00
|
|
|
import tkinter.ttk
|
2020-01-07 22:52:22 +00:00
|
|
|
import os
|
|
|
|
import subprocess
|
2020-06-17 20:46:22 +00:00
|
|
|
import sys
|
2020-01-07 22:52:22 +00:00
|
|
|
|
2020-12-24 04:07:01 +00:00
|
|
|
from voussoirkit import pathclass
|
2020-01-07 22:52:22 +00:00
|
|
|
|
|
|
|
def load_programs():
|
2020-01-27 00:57:47 +00:00
|
|
|
directory = os.path.join(os.path.dirname(__file__), 'PGUI')
|
|
|
|
shortcuts = [os.path.join(directory, p) for p in os.listdir(directory)]
|
|
|
|
shortcuts = [p for p in shortcuts if p.lower().endswith('.lnk')]
|
2020-12-24 04:07:01 +00:00
|
|
|
shortcuts = [pathclass.Path(p) for p in shortcuts]
|
|
|
|
return shortcuts
|
2020-01-07 22:52:22 +00:00
|
|
|
|
2021-02-27 21:27:43 +00:00
|
|
|
class PGUILauncher(tkinter.ttk.Frame):
|
2020-01-07 22:52:22 +00:00
|
|
|
def __init__(self, parent):
|
2021-02-27 21:27:43 +00:00
|
|
|
super().__init__(parent)
|
2020-01-07 22:52:22 +00:00
|
|
|
|
|
|
|
self.parent = parent
|
|
|
|
|
2021-02-27 21:27:43 +00:00
|
|
|
self.style = tkinter.ttk.Style()
|
2020-01-07 22:52:22 +00:00
|
|
|
self.style.theme_use("clam")
|
2021-02-27 21:27:43 +00:00
|
|
|
self.pack(fill=tkinter.BOTH, expand = 1)
|
2020-01-07 22:52:22 +00:00
|
|
|
|
2021-02-27 21:24:46 +00:00
|
|
|
self.filter_var = tkinter.StringVar()
|
|
|
|
self.filter_var.trace('w', self.filter)
|
|
|
|
self.filter_entry = tkinter.Entry(self, textvariable=self.filter_var)
|
|
|
|
self.filter_entry.grid(row=0, column=0, columnspan=999, sticky='ew')
|
|
|
|
self.filter_entry.bind('<Return>', self.launch_filtered)
|
|
|
|
self.filter_entry.focus()
|
|
|
|
|
2020-01-07 22:52:22 +00:00
|
|
|
x = 0
|
2021-02-27 21:24:46 +00:00
|
|
|
y = 1
|
2020-01-07 22:52:22 +00:00
|
|
|
|
2021-02-27 21:24:46 +00:00
|
|
|
self.buttons = []
|
2020-01-07 22:52:22 +00:00
|
|
|
self.buttonwidth = 12
|
2020-12-24 04:07:01 +00:00
|
|
|
shortcuts = load_programs()
|
|
|
|
for (index, shortcut) in enumerate(shortcuts):
|
2020-01-07 22:52:22 +00:00
|
|
|
print(y, x)
|
2021-02-27 21:27:43 +00:00
|
|
|
button = tkinter.ttk.Button(
|
2020-06-17 20:46:22 +00:00
|
|
|
self,
|
2020-12-24 04:07:01 +00:00
|
|
|
text=shortcut.replace_extension('').basename,
|
|
|
|
command=lambda sc=shortcut: self.launch_program(sc),
|
2020-06-17 20:46:22 +00:00
|
|
|
)
|
2021-02-27 21:24:46 +00:00
|
|
|
button.shortcut = shortcut
|
2020-12-24 04:07:01 +00:00
|
|
|
print(f'Creating button for {shortcut.basename}')
|
2021-02-27 21:24:46 +00:00
|
|
|
button.configure(width=self.buttonwidth)
|
|
|
|
button.grid(row=y, column=x)
|
|
|
|
self.buttons.append(button)
|
2020-01-07 22:52:22 +00:00
|
|
|
x += 1
|
2020-12-24 04:07:01 +00:00
|
|
|
if x >= 3 and (index != len(shortcuts)-1):
|
2020-01-07 22:52:22 +00:00
|
|
|
x = 0
|
|
|
|
y += 1
|
|
|
|
print(y, x)
|
|
|
|
|
|
|
|
self.pack()
|
|
|
|
self.update()
|
|
|
|
|
2021-02-27 21:24:46 +00:00
|
|
|
def filter(self, *args):
|
|
|
|
text = self.filter_entry.get().lower()
|
|
|
|
for button in self.buttons:
|
|
|
|
if text == '':
|
|
|
|
button['state'] = 'normal'
|
|
|
|
elif text not in button['text'].lower():
|
|
|
|
button['state'] = 'disabled'
|
|
|
|
|
|
|
|
def launch_filtered(self, *args):
|
|
|
|
enabled = [b for b in self.buttons if b['state'].string == 'normal']
|
|
|
|
if len(enabled) != 1:
|
|
|
|
return
|
|
|
|
|
|
|
|
button = enabled[0]
|
|
|
|
self.launch_program(button.shortcut)
|
|
|
|
|
2020-12-24 04:07:01 +00:00
|
|
|
def launch_program(self, shortcut):
|
|
|
|
print('opening application', shortcut.basename)
|
|
|
|
os.chdir(shortcut.parent.absolute_path)
|
|
|
|
command = f'"{shortcut.absolute_path}"'
|
2020-06-17 20:46:22 +00:00
|
|
|
subprocess.Popen(command, shell=True)
|
|
|
|
self.quit()
|
2020-01-07 22:52:22 +00:00
|
|
|
|
|
|
|
|
2020-06-17 20:46:22 +00:00
|
|
|
def main(argv):
|
2021-02-27 21:27:43 +00:00
|
|
|
root = tkinter.Tk()
|
2020-06-17 20:46:22 +00:00
|
|
|
root.title("PGUI")
|
|
|
|
root.resizable(0,0)
|
|
|
|
|
2020-01-07 22:52:22 +00:00
|
|
|
ex = PGUILauncher(root)
|
2020-06-17 20:46:22 +00:00
|
|
|
|
|
|
|
width = root.winfo_reqwidth()
|
|
|
|
height = root.winfo_reqheight()
|
|
|
|
x_offset = (root.winfo_screenwidth() - width) / 2
|
|
|
|
y_offset = (root.winfo_screenheight() - height) / 2
|
|
|
|
|
|
|
|
root.geometry('%dx%d+%d+%d' % (width, height, x_offset, y_offset-50))
|
2020-01-07 22:52:22 +00:00
|
|
|
root.mainloop()
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2020-06-17 20:46:22 +00:00
|
|
|
raise SystemExit(main(sys.argv[1:]))
|