install

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

commit b82b9d7c415a200cc9e04bc5205a208966877bed
parent ea44b4d773f603424bc651043aeeedb6b4dc9812
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Tue, 25 Oct 2016 12:01:57 +0200

Add(Error): Now handling error returns from functions

Diffstat:
Mscreen.py | 26++++++++++++++++++++++++--
Mscreens/config/config.py | 11++++++++++-
Mscreens/main/main.py | 8+++++---
3 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/screen.py b/screen.py @@ -34,6 +34,8 @@ class Screen: screens = [] prev_id = 0 curr_screen = {} + in_error = 0 + error_win = 0 title = " __ __ _ \n\ | \\/ | | | \n\ | \\ / | ___ _ __ _ __ | |__ _ ___ __\n\ @@ -86,7 +88,7 @@ class Screen: for name, klass in self.modules.items(): print("Reading "+ name +" module...") klass = klass() - config = klass.init() + config = klass.init(self) self.screens.append(klass) if config["id"] == 0: self.curr_screen = klass @@ -113,6 +115,9 @@ class Screen: win.addstr(y + 1, (size[1] / 2) - 8, "__Installer v1__", curses.A_REVERSE) return y + def center(self, win, y, x, string, attr = 0): + win.addstr(y, (x / 2) - len(string) / 2, string, attr) + def change_screen(self, id): for s in self.screens: if s.config["id"] == id: @@ -120,6 +125,17 @@ class Screen: self.curr_screen = s s.reset() + def error(self, string): + size = self.stdscr.getmaxyx() + self.error_win = curses.newwin(10, int(size[1] * 0.5), self.print_title(self.stdscr) + 5, int(size[1] * 0.5 / 2)) + self.error_win.attrset(curses.color_pair(1) | curses.A_BOLD); + self.error_win.border() + size = self.error_win.getmaxyx() + self.center(self.error_win, 0, size[1], "ERROR", curses.color_pair(1) | curses.A_BOLD) + self.center(self.error_win, 4, size[1], string) + self.center(self.error_win, 7, size[1], "<OK>", curses.A_REVERSE) + self.in_error = 1 + # Main Loop def loop(self): quit = 0 @@ -138,7 +154,11 @@ class Screen: win.refresh() while quit != -1: key = self.stdscr.getch() - if self.curr_screen.config["type"] == "menu": + if key == 10 and self.in_error == 1: + self.error_win.erase() + self.error_win.refresh() + self.in_error = 0 + elif self.curr_screen.config["type"] == "menu": self.curr_screen.input(key) elif self.curr_screen.config["type"] == "input": c_input += input.input(key) @@ -164,3 +184,5 @@ class Screen: win.border() self.stdscr.refresh() win.refresh() + if (self.in_error): + self.error_win.refresh() diff --git a/screens/config/config.py b/screens/config/config.py @@ -27,8 +27,10 @@ class Config: key = 0 quit = 1 root_p = "" + main = 0 - def init(self): + def init(self, main): + self.main = main self.config = { "id": 1, "title": "Config", @@ -64,14 +66,21 @@ class Config: self.key = key def hostname(self, string): + if len(string) == 0: + self.main.error("Hostname cannot be empty."); + return 0 return 1 def root_p1(self, string): + if len(string) == 0: + self.main.error("Password cannot be empty."); + return 0 self.root_p = string return 1 def root_p2(self, string): if string != self.root_p: + self.main.error("Passwords did not match !"); return -1 self.quit = 0 return 1 diff --git a/screens/main/main.py b/screens/main/main.py @@ -28,8 +28,10 @@ class Main: menu_s = ["INSTALL", "INSTALL 64BITS", "OPTIONS", "QUIT"] menu_choice = 0 quit = 0 + main = 0 - def init(self): + def init(self, main): + self.main = main self.config = { "id": 0, "title": "MENU", @@ -71,7 +73,7 @@ class Main: def refresh(self, win): size = win.getmaxyx() if (size[0] > 10): - self.menu((size[0] / 2) - (len(self.menu_s) / 2), win, 1); + self.menu((size[0] / 2) - (len(self.menu_s) / 2) - 1, win, 1); else: - self.menu((size[0] / 2) - (len(self.menu_s) / 2), win, 0); + self.menu((size[0] / 2) - (len(self.menu_s) / 2) - 1, win, 0); return self.quit