install

installer
Log | Files | Refs | README | LICENSE | git clone https://git.ne02ptzero.me/git/install

commit ea44b4d773f603424bc651043aeeedb6b4dc9812
parent 3b0f1300f504453add966bae05607e9c7fe687bc
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Tue, 25 Oct 2016 11:05:14 +0200

Work(Inputs): Better code structure

Diffstat:
Minput.py | 18+++++++++++++++---
Mscreen.py | 23+++++++++++++++++------
Mscreens/config/config.py | 32++++++++++++++++++++++++++++++--
Mscreens/main/main.py | 4++++
4 files changed, 66 insertions(+), 11 deletions(-)

diff --git a/input.py b/input.py @@ -29,14 +29,16 @@ class Input: current_string = "" current_f_callback = 0 in_input = 0 + entry_type = "" - def s_input(self, win, title, s_def, f_callback): + def s_input(self, win, title, s_def, f_callback, type): size = win.getmaxyx() if self.in_input == 0: self.current_f_callback = f_callback self.current_string = s_def self.in_input = 1 self.current_choice = 0 + self.entry_type = type if self.current_choice == 0: curses.curs_set(1) self.center(win, 2, size[1], title, curses.A_BOLD) @@ -73,7 +75,10 @@ class Input: start_x = int((x * 0.25) / 2) if (self.current_choice == 0): flag |= curses.color_pair(4) - win.addstr(y, start_x, self.current_string, curses.A_REVERSE | flag) + if self.entry_type == "text": + win.addstr(y, start_x, self.current_string, curses.A_REVERSE | flag) + elif self.entry_type == "password": + win.addstr(y, start_x, '*' * len(self.current_string), curses.A_REVERSE | flag) j = start_x + len(self.current_string) while j < x - start_x: win.addstr(y, j, " ", curses.A_REVERSE | flag) @@ -98,4 +103,11 @@ class Input: self.current_choice = 0; elif (key == curses.KEY_ENTER or key == 10 or key == 13): if (self.current_choice == 1): - self.current_f_callback(self.current_string) + self.in_input = 0 + curses.curs_set(0) + return self.current_f_callback(self.current_string) + elif (self.current_choice == 2): + curses.curs_set(0) + self.in_input = 0 + return -1 + return 0 diff --git a/screen.py b/screen.py @@ -32,6 +32,7 @@ class Screen: stdscr = {} modules = {} screens = [] + prev_id = 0 curr_screen = {} title = " __ __ _ \n\ | \\/ | | | \n\ @@ -115,12 +116,15 @@ class Screen: def change_screen(self, id): for s in self.screens: if s.config["id"] == id: + self.prev_id = self.curr_screen.config["id"] self.curr_screen = s + s.reset() # Main Loop def loop(self): quit = 0 key = 0 + c_input = 0 input = Input() size = self.stdscr.getmaxyx() height = size[0] / 4 @@ -137,18 +141,25 @@ class Screen: if self.curr_screen.config["type"] == "menu": self.curr_screen.input(key) elif self.curr_screen.config["type"] == "input": - input.input(key) + c_input += input.input(key) + if c_input >= len(self.curr_screen.config["input"]): + c_input = -1 + elif c_input < 0: + self.change_screen(self.prev_id) + c_input = 0 win.erase() - if self.curr_screen.config["type"] == "input": - conf = self.curr_screen.config["input"][0] - input.s_input(win, conf["title"], conf["default"], conf["function"]) + if self.curr_screen.config["type"] == "input" and c_input >= 0: + conf = self.curr_screen.config["input"][c_input] + input.s_input(win, conf["title"], conf["default"], conf["function"], conf["type"]) quit = self.curr_screen.refresh(win) if (quit != self.curr_screen.config["id"]): win.erase() self.change_screen(quit) if self.curr_screen.config["type"] == "input": - conf = self.curr_screen.config["input"][0] - input.s_input(win, conf["title"], conf["default"], conf["function"]) + conf = self.curr_screen.config["input"][c_input] + input.s_input(win, conf["title"], conf["default"], conf["function"], conf["type"]) + else: + c_input = 0 self.curr_screen.refresh(win) win.border() self.stdscr.refresh() diff --git a/screens/config/config.py b/screens/config/config.py @@ -26,6 +26,7 @@ class Config: key = 0 quit = 1 + root_p = "" def init(self): self.config = { @@ -37,10 +38,24 @@ class Config: "name": "hostname", "title": "SET YOUR HOSTNAME", "default": "morphux", - "config": "system.hostname", "type": "text", "function": self.hostname }, + { + "name": "root1", + "title": "ROOT PASSWORD", + "default": "", + "type": "password", + "function": self.root_p1 + }, + { + "name": "root2", + "title": "CONFIRM ROOT PASSWORD", + "default": "", + "type": "password", + "function": self.root_p2 + } + ] } return self.config @@ -49,7 +64,20 @@ class Config: self.key = key def hostname(self, string): - print "Okay !" + return 1 + + def root_p1(self, string): + self.root_p = string + return 1 + + def root_p2(self, string): + if string != self.root_p: + return -1 + self.quit = 0 + return 1 + + def reset(self): + self.quit = 1 def refresh(self, win): return self.quit diff --git a/screens/main/main.py b/screens/main/main.py @@ -64,6 +64,10 @@ class Main: y += 1 i += 1 + def reset(self): + self.menu_choice = 0 + self.quit = 0 + def refresh(self, win): size = win.getmaxyx() if (size[0] > 10):