install

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

commit e7e4fa1279e72103ca5ffa47f8f0e58eeaa44815
parent 5a62573815dcf6ab0359a2591240ee5cb90a941a
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Fri, 21 Oct 2016 17:25:02 +0200

Fix(Window utilisation in Screens class):

Now setting real windows to submodule
Using border from the library

Diffstat:
Mscreen.py | 54+++++++++++++++++++++++++++++++++++++++++++++++-------
Ascreens/config/__init__.py | 0
Ascreens/config/config.py | 43+++++++++++++++++++++++++++++++++++++++++++
Mscreens/main/main.py | 64++++++++++++----------------------------------------------------
4 files changed, 102 insertions(+), 59 deletions(-)

diff --git a/screen.py b/screen.py @@ -30,8 +30,18 @@ class Screen: # Variables stdscr = {} modules = {} - screens = {} + screens = [] curr_screen = {} + title = " __ __ _ \n\ + | \\/ | | | \n\ + | \\ / | ___ _ __ _ __ | |__ _ ___ __\n\ + | |\\/| |/ _ \\| '__| '_ \\| '_ \\| | | \ \\/ /\n\ + | | | | (_) | | | |_) | | | | |_| |> < \n\ + |_| |_|\\___/|_| | .__/|_| |_|\\__,_/_/\\_\\\n\ + | | \n\ + |_| \n\ +" + # Construct function def __init__(self): @@ -72,28 +82,58 @@ class Screen: def get_screens_infos(self): config = {} for name, klass in self.modules.items(): - print("Reading"+ name +"module...") + print("Reading "+ name +" module...") klass = klass() config = klass.init() - self.screens[name] = klass - if config["title"] == "Main": + self.screens.append(klass) + if config["id"] == 0: self.curr_screen = klass print("Done !") + # Colors init def init_colors(self): curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_BLUE, curses.COLOR_BLACK) + # Print morphux title and installer version + def print_title(self, win): + size = win.getmaxyx() + y = size[0] / 7; + x = (size[1] / 2) - (44 / 2) + for c in self.title: + win.addstr(y, x, c, curses.color_pair(2) | curses.A_BOLD) + x = x + 1 + if c == '\n': + y = y + 1 + x = (size[1] / 2) - (44 / 2) + win.addstr(y + 1, (size[1] / 2) - 8, "__Installer v1__", curses.A_REVERSE) + return y + + def change_screen(self, id): + for s in self.screens: + if s.config["id"] == id: + self.curr_screen = s + # Main Loop def loop(self): quit = 0 key = 0 - self.curr_screen.refresh(self.stdscr) + size = self.stdscr.getmaxyx() + win = curses.newwin(size[0] / 4, int(size[1] * 0.75), self.print_title(self.stdscr) + 2, int(size[1] * 0.25 / 2)) + win.border() + win.addstr(0, (int(size[1] * 0.75) / 2) - (len(self.curr_screen.config["title"]) / 2), self.curr_screen.config["title"]) + self.curr_screen.refresh(win) self.stdscr.refresh() + win.refresh() while quit != -1: if self.curr_screen.config["type"] == "menu": key = self.stdscr.getch() self.curr_screen.input(key) - self.stdscr.clear() - quit = self.curr_screen.refresh(self.stdscr) + win.erase() + quit = self.curr_screen.refresh(win) + if (quit != self.curr_screen.config["id"]): + self.change_screen(quit) + win.border() + win.addstr(0, (int(size[1] * 0.75) / 2) - (len(self.curr_screen.config["title"]) / 2), self.curr_screen.config["title"]) self.stdscr.refresh() + win.refresh() diff --git a/screens/config/__init__.py b/screens/config/__init__.py diff --git a/screens/config/config.py b/screens/config/config.py @@ -0,0 +1,43 @@ +################################### LICENSE #################################### +# Copyright 2016 Louis Solofrizzo # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ + +## +# main.py +# Created: 21/10/2016 +# By: Louis Solofrizzo <louis@morphux.org> +## + +import curses + +class Config: + + key = 0 + quit = 1 + + def init(self): + self.config = { + "id": 1, + "title": "Config", + "type": "inputs" + } + return self.config + + def input(self, key): + self.key = key + + def refresh(self, win): + win.addstr(10, 10, "Coucou !"); + return self.quit diff --git a/screens/main/main.py b/screens/main/main.py @@ -25,23 +25,14 @@ import curses class Main: key = 0 - menu_s = ["INSTALL", "INSTALL 64BITS", "OPTIONS", "HELP", "QUIT"] + menu_s = ["INSTALL", "INSTALL 64BITS", "OPTIONS", "QUIT"] menu_choice = 0 quit = 0 - title = " __ __ _ \n\ - | \\/ | | | \n\ - | \\ / | ___ _ __ _ __ | |__ _ ___ __\n\ - | |\\/| |/ _ \\| '__| '_ \\| '_ \\| | | \ \\/ /\n\ - | | | | (_) | | | |_) | | | | |_| |> < \n\ - |_| |_|\\___/|_| | .__/|_| |_|\\__,_/_/\\_\\\n\ - | | \n\ - |_| \n\ -" def init(self): self.config = { "id": 0, - "title": "Main", + "title": "MENU", "type": "menu" } return self.config @@ -56,56 +47,25 @@ class Main: if (self.menu_s[self.menu_choice] == "QUIT"): self.quit = -1 else: - self.quit = self.menu_choice + self.quit = self.menu_choice + 1 - def print_title(self, win): - size = win.getmaxyx() - y = size[0] / 4; - x = (size[1] / 2) - (44 / 2) - for c in self.title: - win.addstr(y, x, c, curses.color_pair(2) | curses.A_BOLD) - x = x + 1 - if c == '\n': - y = y + 1 - x = (size[1] / 2) - (44 / 2) - return y - - def menu(self, y, win): + def menu(self, y, win, lines): size = win.getmaxyx() i = 0 for string in self.menu_s: if i == self.menu_choice: win.addstr(y, (size[1] / 2) - (len(string) / 2), string, curses.color_pair(1) | curses.A_BOLD) else: - win.addstr(y, (size[1] / 2) - (len(string) / 2), string) - y += 1 - i += 1 - - def print_borders(self, win, y, height): - size = win.getmaxyx() - c = "#" - i = 0 - while i < height: - win.addstr(y + i, (size[1] / 2) - (80 / 2), c) - i += 1 - i = 0 - while i < height + 1: - win.addstr(y + i, (size[1] / 2) + (80 / 2), c) - i += 1 - i = 0 - while i < 80: - win.addstr(y, (size[1] / 2) - (80 / 2) + i, c) - i += 1 - i = 0 - y += height - while i < 80: - win.addstr(y, (size[1] / 2) - (80 / 2) + i, c) + win.addstr(y, (size[1] / 2) - (len(string) / 2), string, curses.A_BOLD) + if (lines and string != "QUIT"): + win.addstr(y + 1, (size[1] / 2) - (20 / 2), "--------------------") + y += 2 i += 1 def refresh(self, win): size = win.getmaxyx() - y = self.print_title(win) + 1 - win.addstr(y, (size[1] / 2) - 8, "__Installer v1__", curses.A_REVERSE) - self.print_borders(win, y + 3, len(self.menu_s) + 5) - self.menu(y + 6, win); + if (size[0] > 8): + self.menu((size[0] / 2) - (len(self.menu_s) / 2), win, 1); + else: + self.menu((size[0] / 2) - (len(self.menu_s) / 2), win, 0); return self.quit