install

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

commit 6fd0d2166f6f03cccbba5835da98f6550e1b18fa
parent e7e4fa1279e72103ca5ffa47f8f0e58eeaa44815
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Fri, 21 Oct 2016 18:14:28 +0200

Add(input): Beginning of work on text input

Diffstat:
Mscreen.py | 13++++++++++---
Mscreens/config/config.py | 27++++++++++++++++++++++++++-
Mscreens/main/main.py | 6++++--
3 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/screen.py b/screen.py @@ -1,3 +1,4 @@ +#!/usr/bin/python ################################### LICENSE #################################### # Copyright 2016 Louis Solofrizzo # # # @@ -119,21 +120,27 @@ class Screen: quit = 0 key = 0 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)) + height = size[0] / 4 + if height < 10: + height = 10 + win = curses.newwin(height, 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.leaveok(1) self.stdscr.refresh() win.refresh() while quit != -1: - if self.curr_screen.config["type"] == "menu": + if self.curr_screen.config["type"] == "menu" or self.curr_screen.config["type"] == "inputs": key = self.stdscr.getch() self.curr_screen.input(key) win.erase() + win.addstr(0, (int(size[1] * 0.75) / 2) - (len(self.curr_screen.config["title"]) / 2), self.curr_screen.config["title"]) quit = self.curr_screen.refresh(win) if (quit != self.curr_screen.config["id"]): + win.erase() self.change_screen(quit) + self.curr_screen.refresh(win) 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/config.py b/screens/config/config.py @@ -26,6 +26,8 @@ class Config: key = 0 quit = 1 + is_input = 0 + current_string = "" def init(self): self.config = { @@ -37,7 +39,30 @@ class Config: def input(self, key): self.key = key + if (key == curses.KEY_BACKSPACE or key == 127 or key == 0x7f): + self.current_string = self.current_string[:-1] + elif (key > 31 and key < 127): + self.current_string += str(chr(key)) + + def center(self, win, y, x, string, attr = 0): + win.addstr(y, (x / 2) - len(string) / 2, string, attr) + + def input_s(self, win, y, x, default): + if self.is_input == 0: + self.current_string = default + self.is_input = 1 + curses.curs_set(1) + start_x = int((x * 0.25) / 2) + win.addstr(y, start_x, self.current_string, curses.A_REVERSE) + j = start_x + len(self.current_string) + while j < x - start_x: + win.addstr(y, j, " ", curses.A_REVERSE) + j += 1 + win.move(y, start_x + len(self.current_string)) + def refresh(self, win): - win.addstr(10, 10, "Coucou !"); + size = win.getmaxyx() + self.center(win, 2, size[1], "SET YOUR HOSTNAME", curses.A_BOLD) + self.input_s(win, 4, size[1], "morphux") return self.quit diff --git a/screens/main/main.py b/screens/main/main.py @@ -59,12 +59,14 @@ class Main: 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 + y += 2 + else: + y += 1 i += 1 def refresh(self, win): size = win.getmaxyx() - if (size[0] > 8): + if (size[0] > 10): 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);