예제 #1
0
 def display_chat(self):
     window = self.chat
     msg = self.chat_msg
     h, w = getwindowyx(window)
     div = self.DIV_CHAR * (
         w / len(self.DIV_CHAR)) + self.DIV_CHAR[:w % len(self.DIV_CHAR)]
     self.addstr(window, 0, 0, div)
     row = 1
     entry = ""
     for entry in parse_entry_to_fit(msg, w)[-h:]:
         self.addstr(window, row, 0, entry)
         row += 1
         if row >= h - 1:
             break
     if len(entry) >= w:
         x = 0
         y = row + 1
     elif row >= h - 1:
         x = 0
         y = h - 1
     elif len(msg) == 0:
         x = 0
         y = 1
     else:
         x = len(entry)
         y = row
     curses.setsyx(y, x)
예제 #2
0
def reset_screen_size():
	global rows, columns
	rows, columns = os.popen('stty size', 'r').read().split()
	rows = int(rows)
	columns = int(columns)
	scr.addstr(rows - 1, 0, ":")
	curses.setsyx(rows - 1, 1)
예제 #3
0
 def get_symbol_size(self, symbol):
     curses.curs_set(2)
     curses.setsyx(0, 0)
     self.stdscr.addstr(symbol)
     self.stdscr.refresh()
     curses.curs_set(0)
     return curses.getsyx()[1]
예제 #4
0
 def _draw_lines(self):
     lines = self.lines
     skip = self.highlight_index - self.height + 2 if self.highlight_index + 2 - self.height >= 0 else 0
     irange = min(len(lines) - skip, self.height)
     if not self.focused or (self.focused and skip > 0):
         self.screen.erase()
     for i in range(irange):
         i = i + skip
         line = lines[i]
         if self.focused:
             if self.highlight_index > 0 and abs(
                     i - self.highlight_index) > 1 and skip == 0:
                 continue
             curses.setsyx(i, self.x)
             self.screen.clrtoeol()
         style = 0
         line = line[0:(self.width - self.padding - 1)] if (
             len(line) > self.width - self.padding - 1) else line
         if i == self.highlight_index:
             style = self.highlight_style_not_focus
             if self.focused:
                 line = line + ' ' * max(
                     self.width - len(line) - self.padding, 0)
                 style = self.highlight_style
         self.screen.addnstr(i - skip, self.padding, line,
                             self.width - self.padding, style)
예제 #5
0
파일: pymusic.py 프로젝트: jhand2/pymusic
    def draw_ui(self, songs, refresh_only):
        """
        Draws the UI. Basically called every time any interaction happens

        args:
            songs -- list of currently playable song objects
            refresh_only -- boolean, if True only refreshes the screen
                                     if False inits screen and refreshes
        """
        self.max_y, self.max_x = self.scr.getmaxyx()
        if not refresh_only:
            self.scr.addstr(0, 0, "PYMusic Music Player")

            self.pad = curses.newpad(self.max_y, self.max_x)
            index = 0
            self.pad_pos = 1
            self.curs_pos = self.pad_pos

            for s in songs:
                index += 1
                self.pad.addstr(index, 2, s.name)
            curses.curs_set(1)
            self.scr.refresh()

        self.pad.refresh(self.pad_pos, 0, 1, 0, self.max_y, self.max_x - 1)
        curses.setsyx(self.curs_pos, 2)
        curses.doupdate()
예제 #6
0
파일: ui.py 프로젝트: anmitsu/pyful
 def draw_and_update(self):
     try:
         self.draw()
     except curses.error:
         pass
     curses.setsyx(*self.screen.getmaxyx())
     curses.doupdate()
예제 #7
0
def InitWindows(screen, args):
    # reset curses
    logger.handlers = []
    curses.endwin()

    # set up screen
    curses.initscr()
    screen.nodelay(1)
    curses.start_color()
    curses.cbreak()
    curses.setsyx(-1, -1)
    screen.addstr("Quake Live rcon: %s" % args.host)
    screen.refresh()
    maxy, maxx = screen.getmaxyx()

    # set up colors
    for i in range(1,7):
        curses.init_pair(i, i, 0)

    # bugfix: 5 and 6 are swapped in Quake from the standard terminal colours
    curses.init_pair(5, 6, 0)
    curses.init_pair(6, 5, 0)

    # this window holds the log and server output
    begin_x = 2; width = maxx - 4
    begin_y = 2; height = maxy - 5
    output_window = curses.newwin(height, width, begin_y, begin_x)
    screen.refresh()
    output_window.scrollok(True)
    output_window.idlok(True)
    output_window.leaveok(True)
    output_window.refresh()

    # this window takes the user commands
    begin_x = 4; width = maxx - 6
    begin_y = maxy - 2; height = 1
    input_window = curses.newwin(height, width, begin_y, begin_x)
    screen.addstr(begin_y, begin_x - 2, '>')
    screen.refresh()
    input_window.idlok(True)
    input_window.leaveok(False)
    input_window.refresh()

    # solid divider line between input and output
    begin_x = 2; width = maxx - 4
    begin_y = maxy - 3; height = 1
    divider_window = curses.newwin(height, width, begin_y, begin_x)
    screen.refresh()
    divider_window.hline(curses.ACS_HLINE, width)
    divider_window.refresh()

    # redirect logging to the log window
    mh = CursesHandler(output_window)
    formatterDisplay = logging.Formatter('%(asctime)-8s|%(name)-12s|%(levelname)-6s|%(message)-s', '%H:%M:%S')
    logger.addHandler(mh)

    # finalize layout
    screen.refresh()

    return input_window, output_window
예제 #8
0
파일: display.py 프로젝트: joeyuan19/PyChat
 def display_chat(self):
     window = self.chat
     msg = self.chat_msg
     h,w = getwindowyx(window)
     div = self.DIV_CHAR*(w/len(self.DIV_CHAR)) + self.DIV_CHAR[:w%len(self.DIV_CHAR)]
     self.addstr(window,0,0,div)
     row = 1
     entry = ""
     for entry in parse_entry_to_fit(msg,w)[-h:]:
         self.addstr(window,row,0,entry)
         row += 1
         if row >= h-1:
             break
     if len(entry) >= w:
         x = 0
         y = row + 1
     elif row >= h-1:
         x = 0
         y = h - 1
     elif len(msg) == 0:
         x = 0
         y = 1
     else:
         x = len(entry)
         y = row
     curses.setsyx(y,x)
예제 #9
0
파일: gui.py 프로젝트: Guiomuh/arsenal
 def draw(self, stdscr):
     """
     Draw the arguments menu to ask them
     :param stdscr: screen
     """
     # init vars and set margins values
     self.height, self.width = stdscr.getmaxyx()
     self.AB_TOP = (self.height - 6 - Gui.cmd.nb_args) // 2
     self.AB_SIDE = 5
     self.max_preview_size = self.width - (2 * self.AB_SIDE) - 7
     # draw backgroud cheatslist menu (clean resize)
     self.previous_menu.draw(stdscr)
     # draw argslist menu popup
     self.draw_args_preview()
     self.draw_args_list()
     self.draw_selected_arg()
     # init cursor postion (if first draw)
     if self.x_init == None or self.y_init == None or self.xcursor == None:
         self.y_init, self.x_init = curses.getsyx()
         # prefill compatibility
         self.x_init -= len(Gui.cmd.args[self.current_arg][1])
         self.xcursor = self.x_init + len(Gui.cmd.args[self.current_arg][1])
     # set cursor position
     curses.setsyx(self.y_init, self.xcursor)
     curses.doupdate()
예제 #10
0
    def print_confirm(self, selected="Yes"):
        # clear yes/no line
        curses.setsyx(self.screen_height // 2 + 1, 0)
        self.stdscr.clrtoeol()

        y = self.screen_height // 2 + 1
        options_width = 10

        # print yes
        option = "Yes"
        x = self.screen_width // 2 - options_width // 2 + len(option)
        if selected == option:
            self.color_print(y, x, option, 1)
        else:
            self.stdscr.addstr(y, x, option)

        # print no
        option = "No"
        x = self.screen_width // 2 + options_width // 2 - len(option)
        if selected == option:
            self.color_print(y, x, option, 1)
        else:
            self.stdscr.addstr(y, x, option)

        self.stdscr.refresh()
예제 #11
0
 def RenderStatus(self, inWindow, inText):
     (cursY, cursX) = curses.getsyx() # Store cursor position
     inWindow.Win().erase()
     inWindow.AddText(inText, 0, 0)
     inWindow.Refresh()
     if cursX != -1 and cursY != -1:
         curses.setsyx(cursY, cursX) # Restore cursor position
예제 #12
0
 def doupdate(self):
     if self.scroll or not self.active:
         curses.curs_set(0)
     else:
         curses.curs_set(1)
     curses.setsyx(self.terminal.cursor_y, self.terminal.cursor_x)
     curses.doupdate()
예제 #13
0
파일: main.py 프로젝트: tubesandlube/pareto
def initialize():
    curses.initscr()
    win = curses.newwin(24, 80, 0, 0)
    win.keypad(1)
    curses.noecho()
    curses.curs_set(0)
    win.border(0)
    win.nodelay(1)

    key = KEY_RIGHT
    git_handle = []

    win.addstr(0, 2, ' Login ')
    win.addstr(0, 36, ' PARETO ')
    win.addstr(12, 31, ' GitHub Username: '******'\n'):
        y,x=curses.getsyx()
        #win.addstr(12, 48+len(git_handle), curses.A_REVERSE)
        event = win.getch()
        if event != -1:
            prevKey = key
            try:
                git_handle.append(chr(prevKey))
            except:
                # not a printable ascii character
                pass
            key = event
            curses.setsyx(y,x+1)
            curses.doupdate()

    #if key == 27:
    #    curses.endwin()
    curses.endwin()
    print "git handle:", "".join(git_handle)
예제 #14
0
 def RenderStatus(self, inWindow, inText):
     (cursY, cursX) = curses.getsyx()  # Store cursor position
     inWindow.Win().erase()
     inWindow.AddText(inText, 0, 0)
     inWindow.Refresh()
     if cursX != -1 and cursY != -1:
         curses.setsyx(cursY, cursX)  # Restore cursor position
예제 #15
0
def setup_terminal_logging():
    logger.setLevel(logging.DEBUG)
    global panel
    screen = curses.initscr()
    screen.nodelay(1)
    screen.border(0)

    maxy, maxx = screen.getmaxyx()

    height = 20
    # height, width, begin_y, begin_x
    window = curses.newwin(height, maxx - 4, maxy - (height + 1), 2)

    panel = curses.newwin(25, maxx - 4, 2, 2)
    panel.refresh()

    curses.setsyx(-1, -1)

    screen.refresh()
    window.refresh()
    window.scrollok(True)
    window.idlok(True)
    window.leaveok(True)

    terminal_handler = log.CursesHandler(window)
    formatterDisplay = logging.Formatter(
        '[%(asctime)s] %(levelname)-0s: %(message)s', '%H:%M:%S')
    terminal_handler.setFormatter(formatterDisplay)
    logger.addHandler(terminal_handler)
예제 #16
0
파일: gui.py 프로젝트: Guiomuh/arsenal
 def draw(self, stdscr):
     """
     Draw the main menu to select a cheatsheet
     :param stdscr: screen
     """
     self.height, self.width = stdscr.getmaxyx()
     self.max_visible_cheats = self.height - 7
     # create prompt windows
     self.draw_prompt()
     # create info windows
     self.draw_infobox()
     # create cheatslist box
     self.draw_cheatslistbox()
     # draw footer
     info = "> %d / %d " % (self.position + 1, len(self.cheats))
     self.draw_footbox(info)
     # create edit windows
     self.draw_editbox()
     # init cursor postion (if first draw)
     if self.x_init == None or self.y_init == None or self.xcursor == None:
         self.y_init, self.x_init = curses.getsyx()
         self.xcursor = self.x_init
     # set cursor position
     curses.setsyx(self.y_init, self.xcursor)
     curses.doupdate()
예제 #17
0
파일: app.py 프로젝트: davidhalter/lyrics
    def draw(self):
        self.draw_lock.acquire()
        self.height, self.width = self.win_curses.getmaxyx()

        self.win_curses.bkgd(' ')

        self.resize_sub_windows(self.head, 0, 0, None, 1)
        if state.split_screen:
            golden = 0.382
            self.resize_sub_windows(self.song_list, 0, 1, golden, -3)
            self.resize_sub_windows(self.lyrics, golden, 1, 1 - golden, -3)
        else:
            self.resize_sub_windows(self.song_list, 0, 1, None, -3)
        self.resize_sub_windows(self.status_line, 0, -2, None, 1)
        self.resize_sub_windows(self.footer, 0, -1, None, 1)

        # setup cursor
        if state.search_mode:
            curses.setsyx(0, state.search_cursor + 1)
        try:
            curses.curs_set(2 if state.search_mode else 0)
        except:
            pass

        curses.doupdate()
        self.draw_lock.release()
예제 #18
0
        def putline(self, message, color = "NORM", scroll = True):
            """Scroll the window and write the message on the bottom line.

            Positional parameters:
            message -- The message (a string)
            color   -- The color of the message("NORM", "ALERT", "WARN", "GREEN")
            scroll  -- Scroll window before writing
            """
            self.__logger.debug("subwin %s: writing \"%s\"", self.name, message)
            cy, cx = curses.getsyx()
            target = self.window
            if scroll:
                target.scroll()
            try:
                target.addnstr(
                    self.bottomline,
                    self.firstcol,
                    message,
                    self.winwidth,
                    curses.color_pair(self.colors[color]))
            except:
                self.__logger.error(
                    "subwin %s: addnstr(%s, %s, %s, %s, %s) failed",
                    self.name,
                    self.bottomline,
                    self.firstcol,
                    message,
                    self.winwidth,
                    curses.color_pair(self.colors[color]))
                sys.exit(1)
            target.noutrefresh()
            curses.setsyx(cy, cx)
            curses.doupdate()
예제 #19
0
 def write(self, text, i, start=0):
     middle = int(self.height / 2)
     if len(self.center) > middle and i > middle:
         shift = middle
         self.scroll(i - shift - 1)
     else:
         shift = i - 1
         self.scroll(i - shift - 1)
     self.screen.move(0 + shift, 0)
     curses.setsyx(0 + shift, 0)
     if start:
         self.center[0] = '{}{}{}'.format(self.center[0][:start], text,
                                          self.center[0][start:])
     else:
         self.screen.insdelln(1)
         self.center.insert(0 + shift, text)
         if len(self.center) == self.height:
             self.bottom.insert(0, self.center.pop())
     for j, c in enumerate(text):
         if j > 0:
             curses.curs_set(1)
         if start:
             self.screen.insstr(0 + shift, start + j, c,
                                curses.color_pair(1))
         else:
             self.screen.addstr(0 + shift, j, c, curses.color_pair(1))
         time.sleep(random.random() * 10.0 / (self.slow and 50 or 400))
         self.screen.refresh()
         curses.curs_set(0)
예제 #20
0
파일: pymusic.py 프로젝트: jhand2/pymusic
    def draw_ui(self, songs, refresh_only):
        """
        Draws the UI. Basically called every time any interaction happens

        args:
            songs -- list of currently playable song objects
            refresh_only -- boolean, if True only refreshes the screen
                                     if False inits screen and refreshes
        """
        self.max_y, self.max_x = self.scr.getmaxyx()
        if not refresh_only:
            self.scr.addstr(0, 0, "PYMusic Music Player")

            self.pad = curses.newpad(self.max_y, self.max_x)
            index = 0
            self.pad_pos = 1
            self.curs_pos = self.pad_pos

            for s in songs:
                index += 1
                self.pad.addstr(index, 2, s.name)
            curses.curs_set(1)
            self.scr.refresh()

        self.pad.refresh(self.pad_pos, 0, 1, 0, self.max_y, self.max_x - 1)
        curses.setsyx(self.curs_pos, 2)
        curses.doupdate()
예제 #21
0
def findAddr():
    global screenCenter
    global matches
    global selected
    startI = screenCenter
    searchStr = ""
    # matches = list(stk)
    matches = list(range(len(stk)))
    dispH = wd.getmaxyx()[0]
    while True:
        curses.setsyx(dispH, 0)
        wd.deleteln()
        wd.addstr(dispH-1, 0, "/" + searchStr)
        nextChar = chr(wd.getch())
    
        if nextChar == '\n':
            # break
            return
        # elif nextChar == chr(23): # enter
            # screenCenter = startI
            # return
        elif nextChar == chr(263): # backspace
            searchStr = searchStr[:-1]
            matches = list(range(len(stk)))# TODO find a better way of doing this
        else:
            searchStr += nextChar
    
        matches = findMatchingAddrsIndicies(matches, searchStr)
        if len(matches) == 0:
            screenCenter = startI
        else:
            screenCenter = matches[0]
            selected = matches[0]
            # stk[matches[0]].selected = True
        drawMemRegion()
예제 #22
0
    def draw_header(self):
        """Set the header text"""
        self.header.erase()
        separator = self.get_header_separator()

        # Store the cursor location
        loc = curses.getsyx()

        display_text = (f"{self.name} {separator} {self.__header_title}"
                        f" {separator} {self.__user_name}")

        if self.event_manager.insert_mode:
            display_text += f" {separator} INSERT"
        elif self.event_manager.mark_mode:
            display_text += f" {separator} VISUAL"

        bookend = self.get_header_bookends()
        display_text = f'{bookend} {display_text} {bookend}'

        # Centered header
        row = self.cols // 2 - len(display_text) // 2
        add_str(self.header, 0, row, display_text)

        color_a = curses.color_pair(colors.COLOR_PAIR_HEADER)
        color_b = curses.color_pair(colors.COLOR_PAIR_HEADER_ALT)
        for row in range(self.cols):
            if (row // 2) % 2 == 0:
                self.header.chgat(0, row, color_a | curses.A_BOLD)
            else:
                self.header.chgat(0, row, color_b | curses.A_BOLD)

        self.header.noutrefresh()
        self.__header_dirty = False

        curses.setsyx(*loc)
예제 #23
0
 def start(self):
     self.stdscr = curses.initscr()
     curses.noecho()
     curses.cbreak()
     self.stdscr.keypad(True)
     self.stdscr.clear()
     self.stdscr.nodelay(True)
     curses.curs_set(False)
     self.stdscr.leaveok(False)
     curses.setsyx(*self.stdscr.getmaxyx())
     self.threadwindow = curses.newwin(self.nb_proc + 2, 70, 0, 3)
     self.threadwindow.border()
     self.threadwindow.refresh()
     self.titlewindow = curses.newwin(3, 52, self.nb_proc + 3, 28)
     self.titlewindow.border()
     self.update_titlewindow()
     self.titlewindow.refresh()
     self.threadwindow.border()
     for i, key in enumerate(self.keyboardwindows):
         self.keyboardwindows[key] = curses.newwin(
             12, 26, self.nb_proc + 5, i * 26 + 2)
         self.keyboardwindows[key].border()
         self.keyboardwindows[key].addstr(1, 1, key.title().center(24),
                                          curses.A_BOLD)
         self.keyboardwindows[key].refresh()
예제 #24
0
파일: utils.py 프로젝트: VT-SailBOT/sailbot
def setup_terminal_logging():
    logger.setLevel(logging.DEBUG)
    global panel
    screen = curses.initscr()
    screen.nodelay(1)
    screen.border(0)

    maxy, maxx = screen.getmaxyx()

    height = 20
    # height, width, begin_y, begin_x
    window = curses.newwin(height, maxx-4, maxy-(height + 1), 2)

    panel = curses.newwin(25, maxx-4, 2, 2)
    panel.refresh()

    curses.setsyx(-1, -1)

    screen.refresh()
    window.refresh()
    window.scrollok(True)
    window.idlok(True)
    window.leaveok(True)

    terminal_handler = modules.log.CursesHandler(window)
    formatterDisplay = logging.Formatter('[%(asctime)s] %(levelname)-0s: %(message)s', '%H:%M:%S')
    terminal_handler.setFormatter(formatterDisplay)
    logger.addHandler(terminal_handler)
예제 #25
0
 def refresh_thread(self):
     while True:
         time.sleep(1.0)
         cur_pos = curses.getsyx()
         self.feedback.draw()
         curses.setsyx(*cur_pos)
         curses.doupdate()
예제 #26
0
파일: rc.py 프로젝트: PHSCRC/NotHotBot
def main():
    atexit.register(curses.endwin)
    scr = curses.initscr()
    curses.cbreak()
    curses.setsyx(-1, -1)
    # scr.keypad(1)
    scr.addstr(0, 10, 'debug_control.py: the ultimate boxbot controller')
    scr.addstr(2, 10, 'Press Q to exit.')
    scr.refresh()
    speed = 100

    while True:
        key = scr.getch()

        if key == Q:
            turnOffMotors()
            with open('ultra_out.txt', 'w') as f:
                for i in ul:
                    f.write(i)
                    f.write('\n')
            break
        elif key == W:
            forward(speed)
        elif key == S:
            backward(speed)
        elif key == V:
            turnleft(speed)
        elif key == B:
            turnright(speed)
        elif key == Z:
            smallLeft()
        elif key == X:
            smallForward()
        elif key == C:
            smallRight()
        elif key == F:
            forleft(speed)
        elif key == G:
            forright(speed)
        elif key == A:
            for2left(speed)
        elif key == D:
            for2right(speed)
        elif key == E:
            stop()
        elif key == ONE:
            speed = 51
        elif key == TWO:
            speed = 51 * 2
        elif key == THREE:
            speed = 51 * 3
        elif key == FOUR:
            speed = 51 * 4
        elif key == U:
            ultra(scr)
        else:
            print("not a valid key")

    curses.endwin()
예제 #27
0
 def write(self, line, col, msg, mode, offset = 3):
     y, x = self.window.getmaxyx()
     if len(msg.rstrip()) > x-col and x-col > 3:
         msg = msg[0:x-col-3] + "..."
     if 0 <= line < y:
         curses.setsyx(line, 0)
         self.window.clrtoeol()
         self.window.addstr(line, col, msg, mode)
예제 #28
0
def atbprnt(usrStr, attr):
    global prints
    pad.addstr(prints, 4, usrStr, attr)
    pad.addstr(prints, width, 'l')
    pad.refresh(0 + height * (prints / height), 0, 0, 0, height, width)
    prints += 1
    curses.setsyx(prints % height, 0)
    stdscr.refresh()
예제 #29
0
 def set_cursor(self, y, x):
     curses.setsyx(y, x)
     cursor_pos = curses.getsyx()
     current_character = self.get_character(
         cursor_pos[0] + self.actual_offset, cursor_pos[1])
     self.pad.addch(cursor_pos[0] + self.actual_offset, cursor_pos[1],
                    current_character, self.styles['highlighted'])
     self.refresh()
예제 #30
0
def status(win, msg):
    curses.setsyx(10, 0)
    win.deleteln()
    win.clrtoeol()
    win.refresh()
    win.addstr(10, 0, msg)
    win.refresh()
    time.sleep(0.2)
예제 #31
0
    def display(self):
        curses.setsyx(self._y, self._x)
        self._view.scr.clrtoeol()
        self._view.string(self._text, 0, 0)
        curses.echo()
        curses.curs_set(1)
        self._view.scr.refresh()

        return self
예제 #32
0
 def set_curs_pos(self, y=None, x=None):
     self.window.refresh()
     pos = self.get_curs_pos()
     if y is None:
         y = pos[0]
     if x is None:
         x = pos[1]
     curses.setsyx(y, x)
     curses.doupdate()
예제 #33
0
 def start(self):
     """Initialize curses with defaults"""
     self.stdscr = curses.initscr()
     curses.noecho()
     curses.cbreak()
     curses.curs_set(0)
     self.try_colors()
     self.stdscr.keypad(True)
     curses.setsyx(-1, -1)
예제 #34
0
    def UpdateDisplay(self, useDisplay=False):
        self.Win.erase()

        if self.Boxed:
            self.Win.box()

        elif self.VertBorder:
            self.Win.border(" ", " ", 0, 0, " ", " ", " ", " ")

        elif self.HorizBorder:
            self.Win.border(0, 0, " ", " ", " ", " ", " ", " ")

        elif self.NoCornerBorder:
            self.Win.border(0, 0, 0, 0, " ", " ", " ", " ")

        elif self.BottomBorder:
            self.Win.border(" ", " ", " ", 0, " ", " ", " ", " ")

        self.Win.bkgd(" ", self.BkgdColor)

        if self.TextYCenter:
            num_lines = self.Text.count("\n")
            YOffset = (self.Height - num_lines) / 2
        else:
            YOffset = self.YOffset

        # Ensure that text attribute is never larger than what can be written to the window!
        if useDisplay:
            text = self.DisplayText
        else:
            text = self.Text

        if self.TextXCenter:
            for line, substr in enumerate(text.split("\n")):
                if len(substr) >= self.Width:
                    XOffset = 0
                else:
                    XOffset = (self.Width - len(substr)) / 2

                text = substr[: self.Width - XOffset - 1]

                self.Win.addnstr(
                    YOffset + line, XOffset, substr, self.Width - XOffset - 1, self.TextMode | self.TextColor
                )
        else:
            for line, substr in enumerate(text.split("\n")):
                text = substr[: self.Width - self.XOffset - 1]

                self.Win.addnstr(
                    YOffset + line, self.XOffset, text, self.Width - self.XOffset - 1, self.TextMode | self.TextColor
                )

        if self.SetSyx:
            curses.setsyx(self.SetSyx[0], self.SetSyx[1])

        self.Refresh()
예제 #35
0
	def refresh(self):
		self.refresh_lock.acquire()
		self.display.clear()
		for lineno,line in enumerate(self.screen.scr_list()):
			self.display.addstr(lineno,0,line)
		# display cursor
		curses.setsyx(self.screen.input_cursor[0] + 1 ,self.screen.input_cursor[1] + self.screen.output_width + 3)

		self.display.refresh()
		self.refresh_lock.release()
예제 #36
0
파일: ClientAscii.py 프로젝트: isnok/mpmf
    def update(self, data):
        self.points = data['data']
        engine = IDrawingEngine(self)
        engine.screen.clear()
        engine.screen.addstr(5, 5, "Idle points: %s" % self.points)

        engine.screen.refresh()
        # move the cursor to the player
        curses.setsyx(engine.y, engine.x)
        curses.doupdate()
예제 #37
0
 def search(self, strict=False):
     search_size = 50
     b_starty = 0
     b_startx = self.width - search_size - 2
     b_width = search_size
     b_height = 3
     cursor_pos = curses.getsyx()
     search = SearchModal(b_startx, b_starty, b_width, b_height)
     text = search.edit()
     curses.setsyx(cursor_pos[0], cursor_pos[1])
     self.pad.filter(text, strict)
예제 #38
0
 def check_position(self):
     curr_choice = self.choice()
     curses.setsyx(1,5)
     pos = curses.getsyx()
     self.shapes(pos, curr_choice)
     self.win.refresh()
     while True:
         self.win.move(np.add(pos[0], 1), pos[1])
         fall_pos = curses.getsyx()
         self.shapes(fall_pos, curr_choice)
         self.win.refresh()
예제 #39
0
    def update(self, data):
        data = data['data']
        self.games = data
        engine = IDrawingEngine(self)
        for cnt, game in enumerate(data):
            engine.screen.addstr(2 + cnt, 5, game)

        engine.screen.refresh()
        # move the cursor to the player
        curses.setsyx(engine.y, engine.x)
        curses.doupdate()
예제 #40
0
    def __init__(self, commander, screen, daemon=True):
        super(CursesUI, self).__init__(daemon=daemon)
        self.alive = True
        self.screen = screen
        self.commander = commander
        curses.start_color()
        curses.use_default_colors()
        num_colors = min(16, curses.COLORS)
        for i in range(0, num_colors):
            curses.init_pair(i + 1, i, -1)
        curses.curs_set(0)
        curses.setsyx(-1, -1)
        self.screen.nodelay(1)

        maxy, maxx = self.screen.getmaxyx()
        self.width = maxx - 1
        begin_x = 0

        # Title Bar
        tbw_height = 2
        self.tb_window = curses.newwin(tbw_height, self.width, 0, begin_x)
        self.tb_window.scrollok(True)
        self.tb_window.idlok(True)
        self.tb_window.leaveok(True)
        title_str = "Commander Teensy v" + VERSION
        self.tb_window.addstr(0, (self.width - len(title_str)) // 2, title_str,
                              curses.color_pair(3))

        # Main Window
        mw_height = 10
        self.main_window = curses.newwin(8, self.width, tbw_height, begin_x)
        self.main_window.scrollok(True)
        self.main_window.idlok(True)
        self.main_window.leaveok(True)
        # for i in range(num_colors):
        #     self.main_window.addstr(3, i, str(i), curses.color_pair(i))

        # Logging Window
        self.lw_height = maxy - mw_height - tbw_height
        self.log_window = curses.newwin(self.lw_height, self.width,
                                        tbw_height + mw_height, begin_x)
        self.log_window.scrollok(True)
        self.log_window.idlok(True)
        self.log_window.leaveok(True)
        mh = CursesHandler(self.log_window)

        mh.setFormatter(
            logging.Formatter(
                '|%(asctime)-8s|%(name)-10s|%(levelname)-7s|%(message)-s',
                '%H:%M:%S'))
        self.logger = logging.getLogger("")
        self.logger.addHandler(mh)

        self.start()
예제 #41
0
파일: screen.py 프로젝트: stsdc/svs
 def init_screen(self, stdscr):
     self.stdscr = stdscr
     curses.curs_set(0)
     curses.flushinp()
     stdscr.nodelay(1)
     stdscr.keypad(1)
     self.maxy, self.maxx = stdscr.getmaxyx()
     curses.setsyx(-1, -1)
     stdscr.refresh()
     self.init_colors()
     curses.noecho()
예제 #42
0
def ctrprnt(usrStr, attr):
    global prints
    if len(usrStr) < width:
        pad.addstr(prints, width / 2 - len(usrStr) / 2, usrStr, attr)
    else:
        pad.addstr(prints, 0, usrStr, attr)
    pad.addstr(prints, width, 'l')
    pad.refresh(0, 0, 0, 0, height, width)
    prints += 1
    curses.setsyx(prints % height, 0)
    stdscr.refresh()
예제 #43
0
파일: ClientAscii.py 프로젝트: isnok/mpmf
    def update(self, data):
        data = data['data']
        self.games = data
        engine = IDrawingEngine(self)
        for cnt, game in enumerate(data):
            engine.screen.addstr(2+cnt, 5, game)

        engine.screen.refresh()
        # move the cursor to the player
        curses.setsyx(engine.y, engine.x)
        curses.doupdate()
예제 #44
0
def main(win):
    result = Standard2048Game(
        MonteCarloVizStrategy(win, 300, parallel=True,
                              n_proc=10)).setup_and_play()
    win.clear()
    win.refresh()
    curses.setsyx(0, 0)
    for x in ['points', 'max', 'turns', 'endstr']:
        win.addstr("%s : %s\n" % (x, str(result[x])))
    win.addstr("Press 'l' to leave")
    while win.getch() != ord('l'):
        continue
예제 #45
0
    def update(self, data):
        self.games = data['data']
        engine = IDrawingEngine(self)
        engine.screen.clear()
        engine.screen.addstr(0, 3, "name: %(you)s - score: %(your_score)s" % data)
        for cnt, game in enumerate(self.games):
            engine.screen.addstr(2+cnt, 5, game)

        engine.screen.refresh()
        # move the cursor to the player
        curses.setsyx(engine.y, engine.x)
        curses.doupdate()
예제 #46
0
    def write(self, line, col, msg, mode, offset = 3, typer = False):
        y, x = self.window.getmaxyx()
	if len(msg) > x-col and x-col > 3 and not typer:
            msg = msg[0:x-col-3] + "..."
        if typer and len(msg) + col > x - 5 and x - col > 5:
            msg = "..."+msg[len(msg)-(x-col-5):]
        if 0 <= line < y:
            curses.setsyx(line, 0)
            self.window.clrtoeol()
            self.window.addstr(line, col, msg, mode)
            if typer:
                self.window.addstr(line, len(msg), "_", curses.A_BLINK)# | curses.A_REVERSE)
예제 #47
0
 def setCursorPosition(self,x,y):
     self._height,self._width = self._screen.getmaxyx();
     self._height=self._height-1-self._menu.getHeigh()
     self._width=self._width-1
     if x>=self._width or y>=self._height:
         return
     if x<0 or y<0:
         return
     self._xpos=x
     self._ypos=y
     curses.setsyx(y,x)
     self._screen.move(y,x)
예제 #48
0
 def clear_err(self):
     '''Clear error text and mark this window inactive
     
     Restores cursor location after updating
     '''
     if self.visible:
         cursor_loc = curses.getsyx()
         self.clear()
         self.make_inactive()
         curses.setsyx(cursor_loc[0], cursor_loc[1])
         curses.doupdate()
         self.visible = False
 def clear_err(self):
     '''Clear error text and mark this window inactive
     
     Restores cursor location after updating
     '''
     if self.visible:
         cursor_loc = curses.getsyx()
         self.clear()
         self.make_inactive()
         curses.setsyx(cursor_loc[0], cursor_loc[1])
         curses.doupdate()
         self.visible = False
예제 #50
0
 def update_load_bar(self, actual, maxi):
     import math
     max_len = curses.COLS - 15
     actual_len = int(actual * max_len / maxi)
     percent = str(math.floor(actual_len * 100 / max_len))
     message = sfill(actual_len, '█')
     currenty, currentx = curses.getsyx()
     self.statscr.move(1, 7)
     self.statscr.clrtoeol()
     self.statscr.addstr(1, 8, percent + " %")  # Show percentage
     self.statscr.addstr(1, 14, message)  # Show load bar
     self.statscr.refresh()
     curses.setsyx(currenty, currentx)
예제 #51
0
 def update_load_bar(self, actual, maxi):
     max_len = curses.COLS - 20
     actual_len = int(actual * max_len / maxi)
     percent = str(math.floor(actual_len * 100 / max_len))
     message = sfill(actual_len, '█')
     currenty, currentx = curses.getsyx()  # Save current cursor position
     self.statscr.move(1, 7)
     self.statscr.clrtoeol()  # Clear line
     # Show percentage then load bar
     self.statscr.addstr(1, 8, percent + "%" + " [" + str(actual) + "]")
     self.statscr.addstr(1, 19, message)
     self.statscr.refresh()
     curses.setsyx(currenty, currentx)  # Restore cursor position
예제 #52
0
    def update(self, data):
        self.games = data['data']
        engine = IDrawingEngine(self)
        engine.screen.clear()
        engine.screen.addstr(0, 3,
                             "name: %(you)s - score: %(your_score)s" % data)
        for cnt, game in enumerate(self.games):
            engine.screen.addstr(2 + cnt, 5, game)

        engine.screen.refresh()
        # move the cursor to the player
        curses.setsyx(engine.y, engine.x)
        curses.doupdate()
예제 #53
0
 def update_status(self, value):
     """Update the status window content"""
     currenty, currentx = curses.getsyx()
     self.statscr.move(1, 1)
     self.statscr.clrtoeol()
     if self.connected:
         self.statscr.addstr("-O-")
     else:
         self.statscr.addstr("-||-")
     self.statscr.addch(0, 6, curses.ACS_TTEE)
     self.statscr.addch(1, 6, curses.ACS_VLINE)
     self.statscr.addstr(1, 8, value)
     self.statscr.refresh()
     curses.setsyx(currenty, currentx)
 def flash(self):
     '''Flash this error window'''
     if self.visible:
         cursor_loc = curses.getsyx()
         flash_color = self.highlight_color ^ curses.A_REVERSE
         self.set_color(flash_color)
         curses.setsyx(cursor_loc[0], cursor_loc[1])
         curses.doupdate()
         gotch = self.window.getch()
         if gotch != -1:
             curses.ungetch(gotch)
         self.set_color(self.highlight_color)
         curses.setsyx(cursor_loc[0], cursor_loc[1])
         curses.doupdate()
예제 #55
0
    def on_redraw(self):
        while self.connected:
            if len(self.buffer):
                with self.output_lock:
                    self.stream.feed(self.buffer.decode('utf-8'))
                    for i in self.screen.dirty:
                        self.window.addstr(i, 0, self.screen.display[i])

                    self.screen.dirty.clear()
                    curses.setsyx(self.screen.cursor.y + 1, self.screen.cursor.x)
                    curses.doupdate()
                    self.buffer = bytearray()

            time.sleep(0.05)
예제 #56
0
def smartCommand(stdscr, MainSession, Appdata, event):
    (maxY,maxX) = stdscr.getmaxyx()
    curses.raw(); curses.cbreak(); curses.curs_set(1); curses.setsyx(0,0)
    stdscr.erase(); stdscr.refresh(); curses.reset_shell_mode()
    SmartModeInstruct(maxX)
    command = raw_input(">> ")
    while True:
        if command.lower() in Q_LIST:   break
        elif command.lower() in H_LIST: SmartModeInstruct(maxX)
        elif command.lower() in I_LIST: displayInbox(MainSession, stdscr)
        elif command.lower() in S_LIST: searchMailApp(MainSession, stdscr)
        elif command.lower() in N_LIST: sendMailApp(MainSession)
        elif command != "": parseSmart(MainSession, command, stdscr)
        command = raw_input(">> ")
    exitApp(stdscr)
예제 #57
0
    def refresh(self):
        syx = curses.getsyx()
        self.wname.clear()
        self.wtext.clear()
        
        (my, mx) = self.wtext.getmaxyx()
        my -= 1
        
        y = 0
        for i, s in enumerate(self.timeline[self.offset:]):
            # escape illegal character
            text = ctools.delete_notprintable(s.text)
            
            cnt = ctools.cw_count(text)
            row = int(math.ceil(float(cnt) / float(mx)))
            rem = my - y
            xmod = cnt % mx
            
            if row > rem:
                s = copy.copy(s)
                text = ctools.split_text(text, (rem * mx) - 1)[0]
            
            attr = ctools.attr_select(s, self.twitter.my_name)
            
            if self.selected == i:
                attr |= curses.A_STANDOUT
                if xmod != 0:
                    text += " " * (mx - xmod)
            
            try:
                self.wname.addstr(y, 0, s.user.screen_name[:9], attr)
                self.wtext.addstr(y, 0, text.encode(self.CENCODING), attr)
            except:
                curses.endwin()
                print s.user.screen_name, text
                print ["%x %s" % (ord(c), c)
                       for c in text]

            y += row
            if y >= my: 
                self.last = i
                break
        
        self.wname.refresh()
        self.wtext.refresh(*self.wtext_refp)
        
        curses.setsyx(*syx)
        self.on_refresh()
예제 #58
0
파일: base.py 프로젝트: BitCrane/Tool_Box
 def update(self):
   # save cursor
   cy,cx = curses.getsyx()
   try:
     self.update_log()
     # run updates
     self.update_ui()
   except Exception as ex:
     self.log(str(ex))
   except:
     self.log("Unexpected Error")
   finally:
     self.refresh()
     # return cursor
     curses.setsyx(cy,cx)
     self.winput.refresh()
예제 #59
0
def menu(stdscr):
    ch_menu = stdscr.getch()
    ch_chr = chr(ch_menu)        
    
    if ch_menu == ord('q'):
        stdscr.addstr(ch_chr)
        sys.exit()
    
    if ch_menu == ord('w'):
        stdscr.addstr(ch_chr)

    if ch_menu == ord('t'):
        stdscr.addstr(ch_chr)
        stdscr.addstr("lol")
    
    curses.setsyx(csr_pos[0],csr_pos[1])
예제 #60
0
 def move_cursor(self, direction):
     maxx, maxy = self.screen.getmaxyx()
     x, y = curses.getsyx()
     if direction[0] == 1 and x < maxx:
         curses.setsyx(x+1, y)
     elif direction[0] == -1 and x > 0:
         curses.setsyx(x-1, y)
     elif direction[1] == 1 and y < maxy:
         curses.setsyx(x, y+1)
     elif direction[1] == -1 and y > 0:
         curses.setsyx(x, y-1)