Made the first menu
This commit is contained in:
139
main.py
Normal file → Executable file
139
main.py
Normal file → Executable file
@@ -1,49 +1,126 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import curses
|
||||
from curses import panel
|
||||
from curses import wrapper
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Menu(object):
|
||||
def __init__(self, items, stdscreen):
|
||||
# self.window = stdscreen.subwin(0, 0)
|
||||
self.window = stdscreen
|
||||
self.window.keypad(1)
|
||||
self.panel = panel.new_panel(self.window)
|
||||
self.panel.hide()
|
||||
panel.update_panels()
|
||||
|
||||
self.position = 0
|
||||
self.items = items
|
||||
self.items.append(("exit", "exit"))
|
||||
|
||||
def navigate(self, n):
|
||||
self.position += n
|
||||
if self.position < 0:
|
||||
self.position = 0
|
||||
elif self.position >= len(self.items):
|
||||
self.position = len(self.items) - 1
|
||||
|
||||
def display(self):
|
||||
self.panel.top()
|
||||
self.panel.show()
|
||||
self.window.clear()
|
||||
self.window.box()
|
||||
|
||||
while True:
|
||||
self.window.refresh()
|
||||
curses.doupdate()
|
||||
for index, item in enumerate(self.items):
|
||||
if index == self.position:
|
||||
mode = curses.A_REVERSE
|
||||
else:
|
||||
mode = curses.A_NORMAL
|
||||
|
||||
msg = "%s" % (item[0])
|
||||
self.window.addstr(1 + index, 1, msg, mode)
|
||||
|
||||
key = self.window.getch()
|
||||
|
||||
if key in [curses.KEY_ENTER, ord("\n")]:
|
||||
if self.position == len(self.items) - 1:
|
||||
break
|
||||
else:
|
||||
self.items[self.position][1]()
|
||||
|
||||
elif key == curses.KEY_UP:
|
||||
self.navigate(-1)
|
||||
|
||||
elif key == curses.KEY_DOWN:
|
||||
self.navigate(1)
|
||||
|
||||
self.window.clear()
|
||||
self.panel.hide()
|
||||
panel.update_panels()
|
||||
curses.doupdate()
|
||||
|
||||
|
||||
|
||||
|
||||
class MyApp(object):
|
||||
def __init__(self, screen):
|
||||
curses.curs_set(0)
|
||||
curses.init_color(0,0,0,0)
|
||||
screen.box()
|
||||
|
||||
Cols22 = (curses.COLS - 2) * 0.22
|
||||
Cols22 = int(Cols22)
|
||||
|
||||
Cols56 = (curses.COLS - 2) * 0.56
|
||||
Cols56 = int(Cols56) + 1
|
||||
|
||||
Lines = (curses.LINES -2) * 0.95
|
||||
Lines = int(Lines)
|
||||
|
||||
title = "Sparks-Skraps" + " COLS -> " + str(curses.COLS) + " LINES -> " + str(Cols56)
|
||||
titlePos = (curses.COLS / 2) - (len(title) / 2)
|
||||
|
||||
screen.addstr(1, int(titlePos), title)
|
||||
screen.refresh()
|
||||
def printS(self):
|
||||
print("Yep, works")
|
||||
|
||||
|
||||
components = curses.newwin(Lines,Cols22,3,1)
|
||||
components.box()
|
||||
components.addstr(1, 1, "precious components")
|
||||
components.refresh()
|
||||
def __init__(self, screen):
|
||||
curses.curs_set(0)
|
||||
curses.init_color(0,0,0,0)
|
||||
screen.box()
|
||||
|
||||
parts = curses.newwin(Lines, Cols22, 3, 1+Cols22)
|
||||
parts.box()
|
||||
parts.addstr(1, 1, "My precious parts")
|
||||
parts.refresh()
|
||||
Cols22 = (curses.COLS - 2) * 0.22 # Take 2 characters out from the boarders and then calculate 22%
|
||||
Cols22 = int(Cols22) # Ditch the fractional part
|
||||
|
||||
info = curses.newwin(Lines, Cols56, 3, 1+Cols22*2)
|
||||
info.box()
|
||||
info.addstr(1, 1, "My precious info")
|
||||
info.refresh()
|
||||
Cols56 = (curses.COLS - 2) * 0.56 # Take 2 characters out from the boarders and then calculate 56%
|
||||
Cols56 = int(Cols56) + 1 # Ditch the fractional part and add 1
|
||||
|
||||
Lines = (curses.LINES - 2) * 0.95 # Take 2 characters out from the boarders and then calculate 56%
|
||||
Lines = int(Lines) # Ditch the fractional part
|
||||
|
||||
|
||||
|
||||
# title = "Sparks-Skraps" + " COLS -> " + str(curses.COLS) + " LINES -> " + str(Cols56)
|
||||
title = "Sparks-Skraps"
|
||||
titlePos = (curses.COLS / 2) - (len(title) / 2)
|
||||
|
||||
screen.addstr(1, int(titlePos), title, 2)
|
||||
screen.refresh()
|
||||
|
||||
|
||||
components = curses.newwin(Lines,Cols22,3,1)
|
||||
# components.box()
|
||||
# components.addstr(1, 1, "precious components")
|
||||
components.refresh()
|
||||
|
||||
parts = curses.newwin(Lines, Cols22, 3, 1+Cols22)
|
||||
parts.box()
|
||||
parts.addstr(1, 1, "My precious parts")
|
||||
parts.refresh()
|
||||
|
||||
info = curses.newwin(Lines, Cols56, 3, 1+Cols22*2)
|
||||
info.box()
|
||||
info.addstr(1, 1, "My precious info")
|
||||
info.refresh()
|
||||
|
||||
|
||||
# c = screen.getch()
|
||||
|
||||
submenu_items = [("Resistors", curses.beep), ("Capacitors", curses.beep), ("Coils", curses.flash), ("IC\'s", curses.flash)]
|
||||
submenu = Menu(submenu_items, components)
|
||||
submenu.display()
|
||||
|
||||
|
||||
c = screen.getch()
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user