-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuni-nav
More file actions
executable file
·126 lines (104 loc) · 4.27 KB
/
uni-nav
File metadata and controls
executable file
·126 lines (104 loc) · 4.27 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (c) 2020-2024 Jared Daniel Carbonell Recomendable.
import wx
from subprocess import Popen
'''
DEPENDENCIES
* `cdl` in .local/bin
* wxPython
'''
# [row_type, label, cdl_command, keycode_binding] OR
# [row_type, label, cdl_command, keycode_binding, keycode_binding_book]
DIRS = [
[-1, 'TEACHING ASSISTANT'],
[0, 'COMPSYS 201', 'u-w201', '1'],
[0, 'SOFTENG 281', 'u-w281', '2'],
[0, 'SOFTENG 350', 'u-w350', '3'],
[0, 'SOFTENG 701', 'u-w701', '4'],
[0, 'SOFTENG 770', 'u-w770', '5'],
[-1, '\nRESEARCH ASSISTANT'],
[0, 'MECHENG 270', 'u-wra270', '6'],
[0, 'POLYGLOT PROJECT', 'u-wrapoly', '7'],
[0, 'PROGRAM SYNTHESIS', 'u-wraps', '8'],
[-1, '\nMISC'],
[0, 'ENGTA', 'u-ta', '9'],
[0, 'ADMIN', 'u-admin', '0'],
[0, 'BESTCODER', 'bc', '-'],
]
COMMAND = '~/.local/bin/cdl {}'
COMMAND_BOOK_DIR = '~/.local/bin/cdl {}b'
# 1920x1080
WIN_SIZE = (640, 920)
WIN_ORIGIN = (640, 108)
# 1440x900
#WIN_SIZE = (400, 720)
#WIN_ORIGIN = (520, 90)
class MainFrame(wx.Frame):
def __init__(self):
# Define main window
super().__init__(parent=None, title='Directory Main Menu')
panel = wx.Panel(self)
panel.SetBackgroundColour((0, 0, 0))
panel.SetForegroundColour((255, 255, 255))
panel.SetFont(wx.Font(16, wx.MODERN, wx.NORMAL, wx.BOLD))
container_main = wx.BoxSizer(wx.VERTICAL)
# Set up GUI components and layout for the directories
for directory in DIRS:
# List each directory option
container = wx.BoxSizer(wx.HORIZONTAL)
label = wx.StaticText(panel, label=directory[1])
# Add label for each directory option
container.Add(label, 1, wx.ALIGN_LEFT | wx.ALIGN_CENTRE_VERTICAL, 0)
# Add buttons if row represents a directory option (row_type > -1)
if directory[0] > -1:
# Add button for each directory option
button_dir = wx.Button(panel, label='OPEN [{}]'.format(directory[3]))
button_dir.Bind(wx.EVT_BUTTON, self.button_press(code=directory[3]))
button_dir.SetBackgroundColour((0, 128, 0))
button_dir.SetForegroundColour((255, 255, 255))
# Button also listens for keyboard events if focussed
button_dir.Bind(wx.EVT_CHAR, self.key_press)
# Add the button for the corresponding books directory, if present
if directory[0] == 1:
button_books = wx.Button(panel, label='BOOK [⇧{}]'.format(directory[3]))
button_books.Bind(wx.EVT_BUTTON, self.button_press(code=directory[4]))
button_books.Bind(wx.EVT_CHAR, self.key_press)
button_books.SetBackgroundColour((128, 64, 0))
button_books.SetForegroundColour((255, 255, 255))
container.Add(button_books, 0, wx.LEFT | wx.ALIGN_CENTRE_VERTICAL, 8)
# Add the button for directory
container.Add(button_dir, 0, wx.LEFT | wx.ALIGN_CENTRE_VERTICAL, 8)
# Add row to window
container_main.Add(container, 1, wx.EXPAND | wx.ALL, 8)
# Listen to keyboard events
panel.Bind(wx.EVT_CHAR, self.key_press)
# Finally prepare to show the window
panel.SetSizer(container_main)
panel.SetFocus()
self.SetSize(WIN_ORIGIN[0], WIN_ORIGIN[1], WIN_SIZE[0], WIN_SIZE[1])
self.Show()
def button_press(self, code):
def on_click(event):
self.goto_dir(ord(code))
return on_click
def key_press(self, event):
code = event.GetKeyCode()
self.goto_dir(code)
def goto_dir(self, code):
'''Open the intended directory using cdl.'''
for dir in DIRS:
if dir[0] < 0:
continue
if code == ord(dir[3]):
Popen(['bash', '-c', COMMAND.format(dir[2])])
self.Destroy()
if dir[0] and code == ord(dir[4]):
Popen(['bash', '-c', COMMAND_BOOK_DIR.format(dir[2])])
self.Destroy()
if code == ord('Q') or code == ord('q'):
self.Destroy()
if __name__ == '__main__':
app = wx.App()
frame = MainFrame()
app.MainLoop()