def delete(self): """ Delete a submission or comment. """ if not self.reddit.is_logged_in(): show_notification(self.stdscr, ['Not logged in']) return data = self.content.get(self.nav.absolute_index) if data.get('author') != self.reddit.user.name: curses.flash() return prompt = 'Are you sure you want to delete this? (y/n):' char = prompt_input(self.stdscr, prompt) if char != 'y': show_notification(self.stdscr, ['Aborted']) return with self.safe_call as s: with self.loader(message='Deleting', delay=0): data['object'].delete() time.sleep(2.0) s.catch = False self.refresh_content()
def main(self): self.F = npyscreen.Form(name = "Welcome to Npyscreen") self.t = self.F.add(npyscreen.TitleText, name = "Text:") while 1: self.update_values() curses.flash() curses.napms(100)
def __page_duang_before(self, attribute): if "flash" in attribute: self.__clr() curses.flash() if "slip" in attribute: self.__slip_into() self.__clr()
def listenkb(self): if self.firsttime == True: self.firsttime = False self.w.timeout(0) car = self.w.getch() self.w.timeout(self.timeout) else: car = self.w.getch() if car != -1: if car == curses.KEY_F5: curses.flash() if curses.ascii.isgraph(car) and curses.ascii.unctrl(car) in ['q', 'Q']: sys.exit(0) if curses.ascii.isgraph(car) and curses.ascii.unctrl(car) in ['w', 'W']: self.wheelon = not self.wheelon self.initwheel() if self.saving == True: self.listenkbsavemode(car) elif self.searchediting == True: self.listenkbsearcheditmode(car) elif self.helpmode == True: self.listenkbhelpmode(car) else: self.listenkbfilemode(car)
def getkey(self): c = self.stdscr.getch() # normal moving around the screen if c == curses.KEY_LEFT: self.x = (self.x - 1) % self.limitx elif c == curses.KEY_RIGHT: self.x = (self.x + 1) % self.limitx elif c == curses.KEY_UP: self.y = (self.y - 1) % self.limity elif c == curses.KEY_DOWN: self.y = (self.y + 1) % self.limity elif c == curses.KEY_NPAGE: self.pos = (self.pos + self.maxy) % self.limity elif c == curses.KEY_PPAGE: self.pos = (self.pos - self.maxy) % self.limity elif c == curses.KEY_HOME: self.pos = 0 # we need to ignore some keys elif c == curses.KEY_MOUSE: pass elif c < 32 or c == 127 or c > 255: curses.flash() else: # modifying the encryption key try: self.key[self.x] = ord(self.cts[self.y][self.x])^c except: pass
def panel_sample(stdscr): stdscr.clear() stdscr.border() stdscr.refresh() hello_window = Window(curses.newwin(15, 40, 2, 2), "Hello world") hello_window.window.addstr("Hello wolrld " * 20) hello_window.show() spam_window = Window(curses.newwin(12, 40, 10, 30), "Ham Spam Egg") spam_window.window.addstr("Spam! " * 20) spam_window.show() window_queue = queue.Queue() window_queue.put(hello_window) current_window = spam_window while True: c = stdscr.getch() if (c == 0x1b) or (c == ord("q")): break elif c == 0x20: window_queue.put(current_window) current_window = window_queue.get() current_window.panel.top() curses.panel.update_panels() stdscr.refresh() else: curses.flash()
def Display_Crash(self,Game,x_loc,y_loc): """ Display Flashing Effect """ j,flag=3,0 for i in range(5): Game.getch() curses.flash() Game.clear()
def scriptSM(): screen.clear() screen.border(0) screen.addstr(2, 2, "This is Motif Search") screen.addstr(4, 4, "Please enter a input file for Motif Search") screen.addstr(7, 4, "Please name the first output file (WCFS1_glc1)") screen.addstr(10, 4, "Please name the second output file (NC8_glc1)") screen.addstr(13, 4, "Please name the third output file (WCFS1_glc2)") screen.addstr(16, 4, "Please name the last output file (NC8_glc2)") screen.refresh() thirdClass = class3() userInput = screen.getstr(5, 10, 60) userOutput = screen.getstr(8, 10, 60) userOutput2 = screen.getstr(11, 10, 60) userOutput3 = screen.getstr(14, 10, 60) userOutput4 = screen.getstr(17, 10, 60) try: thirdClass.motifSearch(userInput, userOutput, userOutput2, userOutput3, userOutput4) screen.clear() screen.border(0) screen.addstr(2, 4, "Motif Search succes!") screen.refresh() time.sleep(3) except: curses.flash() show_error("Invalid file name. Try again.")
def beep(): """ Does an audible beep sound Reference: http://de3.aminet.net/dev/src/clr.py.txt """ if sys.platform == 'linux2': for dev in ('/dev/audio', '/dev/oss', '/dev/dsp', '/dev/sound'): if os.path.exists(dev): try: audio = file(dev, 'wb') for i in xrange(250): audio.write(chr(32) * 4) audio.write(chr(0) * 4) audio.close() return except: pass try: import curses curses.initscr() curses.beep() curses.flash() curses.endwin() return except: dataToStdout('\a', True) else: dataToStdout('\a', True)
def waitForStatusLineUpdateConfirmation(self, inputHandler = None): if (inputHandler == None): inputHandler = InputHandler.SingletonKeyboardInputHander(self.screen) promptMessage = 'PRESS A KEY' promptMessageLength = len(promptMessage) y = self.getTerminalHeight() - 1 x = self.getTerminalWidth() - self.maxSideBarLen - 1 promptMessageAttr = Colors.BLINK | Colors.getPairNumber('BLACK', 'YELLOW') self.screen.addnstr(y, x, promptMessage, promptMessageAttr) self.draw() curses.flash() #Visual bell keyPressed = inputHandler.waitForKey() Logger.put(' key found: %s' % (str(keyPressed))) self.resetStatusLinesAppended() #erase the prompt message self.screen.addnstr(y, x, ' ' * promptMessageLength, promptMessageAttr) self.draw()
def runmenu(menu, parent, n, h): global screen if parent is None: lastoption = "Exit" else: lastoption = "Return to %s menu" % parent['title'] optioncount = len(menu['options']) # how many options in this menu pos=0 oldpos=None # used to prevent the screen being redrawn every time x = None # Loop until return key is pressed while x !=ord('\n'): if pos != oldpos: oldpos = pos screen.clear() screen.border(0) screen.refresh() screen.addstr(2,2, menu['title'], curses.A_STANDOUT) screen.addstr(4,2, menu['subtitle'], curses.A_BOLD) # Display all the menu items, showing the 'pos' item highlighted for index in range(optioncount): textstyle = n if pos==index: textstyle = h screen.addstr(5+index,4, "%d - %s" % (index+1, menu['options'][index]['title']), textstyle) # Now display Exit/Return at bottom of menu textstyle = n if pos==optioncount: textstyle = h screen.addstr(5+optioncount,4, "%d - %s" % (optioncount+1, lastoption), textstyle) screen.refresh() # finished updating screen x = screen.getch() # Gets user input # What is user input? if x >= ord('1') and x <= ord(str(optioncount+1)): pos = x - ord('0') - 1 elif x == 258: # down arrow if pos < optioncount: pos += 1 else: pos = 0 elif x == 259: # up arrow if pos > 0: pos += -1 else: pos = optioncount elif x != ord('\n'): curses.flash() # return index of the selected item return pos
def main(stdscr): (y,x) = stdscr.getmaxyx() ed = Editor.Editor(y-1,x) if len(sys.argv) > 1: filename = sys.argv[1] ed.buffer.load_from_file(filename) else: filename = "" curses.curs_set(0) update(stdscr,ed) event = -2 while True: if ed.exit: break elif event == curses.KEY_RESIZE: (y,x) = stdscr.getmaxyx() ed.set_win(0,y-1,x) update(stdscr,ed) else: try: ed.handle_key(event2key(event)) except KeyChainError, e: curses.flash() update(stdscr,ed) if not ed.exit: stdscr.addstr(y-2,x-15,"%d: %s" % (event,event2key(event))) stdscr.chgat(ed.cursor.y-ed.win.top,ed.cursor.x,1,curses.A_STANDOUT) stdscr.refresh() event = stdscr.getch()
def display(self): screen = self.screen while True: screen.clear() screen.addstr(2, 2, self.title, curses.A_STANDOUT|curses.A_BOLD) screen.addstr(4, 2, "Please select an option...", curses.A_BOLD) ckey = None func = None while ckey != ord('\n'): for n in range(0, len(self.ordered)): optn = self.ordered[n] if n != self.pos: screen.addstr(6 + n, 4, "%d. %s" % (n, optn), self.n) else: screen.addstr(6 + n, 4, "%d. %s" % (n, optn), self.h) screen.refresh() ckey = screen.getch() if ckey == 258: self.upKey() if ckey == 259: self.downKey() ckey = 0 self.cleanup() if self.pos >= 0 and self.pos < len(self.ordered): self.datum[self.ordered[self.pos]]() self.pos = -1 else: curses.flash()
def game_start(stdscr): """ Houses the game-loop. draws sleeps , calls collide to check """ global birdy curses.flash()#flash the screen curses.curs_set(0)#set the cursor invisible stdscr.nodelay(1) while True: stdscr.erase() draw_border(stdscr,score) draw_bird(stdscr) draw_pipes(stdscr) #if collide()==True: # game_over(stdscr,score) # pass up=stdscr.getch() if up==ord(' '): if birdy<=10: birdy=10 pass else: birdy-=1 pass pass else: y,x=stdscr.getmaxyx() if birdy>=y-10: birdy=y-10 pass else: birdy+=1 pass curses.flushinp() curses.napms(20)
def menu(): import curses from shift import shift screen = curses.initscr() screen.keypad(1) height,width = 25,80 selection = -1 opt_string = [' Option : {} '.format(i) for i in range(5) ] options = [0] * 5 options[0] = curses.A_REVERSE while True: screen.clear() screen.refresh() for i in range(len(opt_string)): screen.addstr(height/2-len(opt_string)+i,width/2-len(opt_string), opt_string[i],options[i]) " print option, options, selection " screen.addstr(23,10, 'Option: {}'.format(options.index(curses.A_REVERSE)) ) screen.addstr(23,25, 'Options: {}'.format(options) ) screen.addstr(23,60, 'Selection: {}'.format(selection) ) ''' key input processing ''' action = screen.getch() if action == ord('k') or action == curses.KEY_UP: shift(options,-1) elif action == ord('j') or action == curses.KEY_DOWN: shift(options,1) elif action == ord('\n') or action == ord(' '): curses.flash() selection = options.index(curses.A_REVERSE)
def main(): pygame.mixer.init(frequency=44100, size=-16, channels=2, buffer=4096) command_list = CommandList() command_list.load_commands() my_screen = curses.initscr() curses.curs_set(0) continue_looping = True while continue_looping: if command_list.pick_command(): for i in range(1,random.randint(15,20)): display_string = command_list.pick_command() command_position = animate_selection(my_screen, display_string) pygame.mixer.Sound('beep.wav').play() sleep(i * 0.05) move_command_to_center(my_screen, display_string, command_position) for i in range(0,3): curses.flash() sleep(0.2) command_list.mark_inactive(display_string) command_list.write_commands() else: continue_looping = False char = my_screen.getkey() if char in 'q': continue_looping = False curses.endwin()
def writer_loop (my_screen, usb_mapper, write_counter, image_file): # Main writer loop - write USB memory sticks until stopped by pressing X # Create new USB path mapper object to resolve device paths to USB paths upm = usb_path_mapper() # This dictionary holds all writer objects writers = {} status_previous = None current_usbs = [] curses.noecho() my_screen.timeout(0) screen.addstr(0, 0, "Image file: %s %d" % (image_file, write_counter.read_counter(image_file)), curses.color_pair(3)) update_message(my_screen, "Insert USB sticks to start write and remove them when finished, X to exit...") continue_writers = True while continue_writers: new_usbs = enum_usbs() update_corner(my_screen, "USBs: % 3d" % len(new_usbs)) added_usbs = list(set(new_usbs) - set(current_usbs)) # Create writers for all newly added USB sticks for this_usb in added_usbs: # Create writers for all USB devices usbcoords = usb_mapper.get_hub_coords_str(upm.get_usb_path(this_usb)) my_log("Creating writer for device %s located at %s (%s)" % (this_usb, usbcoords, upm.get_usb_path(this_usb))) if not os.access(this_usb, os.W_OK): my_exit(1, "You don't have write access to %s. Are you sure you are root?" % this_usb) writers[this_usb] = dd_helper() writers[this_usb].set_usbhub_coords(usbcoords) writers[this_usb].write_image(image_file, this_usb) current_usbs = new_usbs key = screen.getch() if key == ord('x') or key == ord('X'): continue_writers = False # Check status removed_devices = update_writer_status(my_screen, writers, usb_mapper.get_max(), new_usbs) for this_removed_device in removed_devices: upm.changed(this_removed_device['device']) del writers[this_removed_device['device']] my_log("Removed %s with status %d" % (this_removed_device['device'], this_removed_device['status'])) if this_removed_device['status'] == 3: play_file(AUDIO_OK) write_counter.add_counter_by_one(image_file) screen.addstr(0, 0, "Image file: %s %d" % (image_file, write_counter.read_counter(image_file)), curses.color_pair(3)) else: play_file(AUDIO_ERROR) curses.flash() time.sleep(0.3)
def show_notification(stdscr, message): """ Overlay a message box on the center of the screen and wait for user input. Params: message (list): List of strings, one per line. """ n_rows, n_cols = stdscr.getmaxyx() box_width = max(map(len, message)) + 2 box_height = len(message) + 2 # Make sure the window is large enough to fit the message if (box_width > n_cols) or (box_height > n_rows): curses.flash() return s_row = (n_rows - box_height) // 2 s_col = (n_cols - box_width) // 2 window = stdscr.derwin(box_height, box_width, s_row, s_col) window.erase() window.border() for index, line in enumerate(message, start=1): window.addstr(index, 1, line) window.refresh() ch = stdscr.getch() window.clear() window = None stdscr.refresh() return ch
def delete(self): """ Delete a submission or comment. """ if not self.reddit.is_oauth_session(): show_notification(self.stdscr, ["Not logged in"]) return data = self.content.get(self.nav.absolute_index) if data.get("author") != self.reddit.user.name: curses.flash() return prompt = "Are you sure you want to delete this? (y/n): " char = prompt_input(self.stdscr, prompt) if char != "y": show_notification(self.stdscr, ["Aborted"]) return with self.safe_call as s: with self.loader(message="Deleting", delay=0): data["object"].delete() time.sleep(2.0) s.catch = False self.refresh_content()
def main_control(screen, event, inception_level): if event == ord("Q"): curses.endwin() exit(0) if event == ord("D"): window_for_done_task(screen) if event == ord("T"): window_for_undone_task(screen) if event == ord("F"): curses.flash() if event == ord("A"): editwin = curses.newwin(1, screen.getmaxyx()[1]-6, screen.getmaxyx()[0]-4, 1 ) rectangle(screen, screen.getmaxyx()[0]-5, 0, screen.getmaxyx()[0]-3, screen.getmaxyx()[1]-5) screen.refresh() box = Textbox(editwin) # Let the user edit until Ctrl-G is struck. box.edit() # Get resulting contents message = box.gather() Tache().ajouter_tache(message, datetime.now()) screen.clear() print_main_screen(screen) print_taches(screen, Tache().get_tache_undone(), "Taches a faire :") deal_with_selected(screen, 33, 45, Tache().get_tache_undone(), window_for_undone_task)
def delete_comment(self): "Delete a comment as long as it is not the current submission" if self.nav.absolute_index != -1: self.delete() else: curses.flash()
def handle(self, stdscr, window, height, width, key): if key == curses.KEY_UP and ((not self.show_cert and self.selected > -2) or (self.show_cert and self.selected > 0)): self.selected = self.selected-1 elif key == curses.KEY_DOWN and self.selected < len(self.certs)-1: self.selected = self.selected+1 elif key == ord('\n'): if self.selected == -2: window.addstr(1, 0, ' '*(width-2)) path = self.get_editable(1, 0, stdscr, window, self.certspath, curses.color_pair(1), True) if path == '' or path == self.certspath: return(True) self.certspath = path self.certspath_toedit = True self.get() elif self.selected == -1: window.erase() window.addstr('Absolute path: ') path = self.get_editable(0, 15, stdscr, window, '', curses.color_pair(1) | curses.A_REVERSE, True) if path == '': return(True) try: cert = M2Crypto.X509.load_cert(path) except (IOError, M2Crypto.X509.X509Error): messages.append('\"' + path + '\" not a valid certificate', 'error') return(True) prefix = '' if cert.check_ca() and os.path.basename(path)[:3] != 'ca_': prefix = 'ca_' if not cert.check_ca() and os.path.basename(path)[:3] != 'cl_': prefix = 'cl_' if os.path.exists(os.path.join(self.certspath, prefix + os.path.basename(path))): messages.append('Certificate \"' + os.path.basename(path)[:-4] + '\" already in the CA directory', 'error') return(True) cert = self.parse_cert(path, prefix) if cert: self.certs.append(cert) self.certs.sort() self.certs_toadd.append((path, prefix)) else: self.show_cert = not self.show_cert elif key == curses.KEY_DC and self.selected > -1: self.certs_toremove.append(os.path.join(self.certspath, self.certs[self.selected][0]) + '.pem') del self.certs[self.selected] self.selected -= 1; elif key == curses.KEY_NPAGE and self.selected != len(self.certs)-1: if self.selected < 0: self.selected += height-3 else: self.selected += height-2 if self.selected > len(self.certs)-1: self.selected = len(self.certs)-1 elif key == curses.KEY_PPAGE and self.selected != -2: self.selected -= height-2 if self.selected < -2: self.selected = -2 else: curses.flash() return(True)
def menu(): curses.init_pair(1,curses.COLOR_RED, curses.COLOR_WHITE) screen.keypad(1) pos = 1 x = None # I'm going to be lazy and save some typing here. h = curses.color_pair(1) n = curses.A_NORMAL while x != ord('\n'): # Gotta reset the screen from the root or lose the border, window, etc. screen.clear() screen.border(0) screen.addstr(2,2, "Dan's Arcade Cabinet", curses.A_STANDOUT) screen.addstr(4,2, "Please select an option...", curses.A_BOLD) # Detect what is highlighted by the 'pos' variable. if pos == 1: screen.addstr(5,4, "1 - Classic Arcade Games",h) else: screen.addstr(5,4, "1 - Classic Arcade Games",n) if pos == 2: screen.addstr(6,4, "2 - C64 Jumpman",h) else: screen.addstr(6,4, "2 - C64 Jumpman",n) if pos == 3: screen.addstr(7,4, "3 - Restart",h) else: screen.addstr(7,4, "3 - Restart",n) if pos == 4: screen.addstr(8,4, "4 - Turn Off",h) else: screen.addstr(8,4, "4 - Turn Off",n) screen.refresh() x = screen.getch() # Is 'x' 1-4 or arrow up, arrow down? if x == ord('1'): pos = 1 elif x == ord('2'): pos = 2 elif x == ord('3'): pos = 3 elif x == ord('4'): pos = 4 elif x == 258: if pos < 4: pos += 1 else: pos = 1 elif x == 259: if pos > 1: pos += -1 else: pos = 4 elif x != ord('\n'): curses.flash() # show_error() is my custom function for displaying a message: # show_error(str:message, int:line#, int:seconds_to_display) show_error('Invalid Key',11,1) return (pos)
def clear_trick(game, win): curses.flash() if not game.player().hand: #waiting_for_deal = 15 draw_score_sheet(game, win) game.clear_trick() game.render(win) curses.doupdate()
def change_highlight(location, prev=-1): if prev != -1: title = subs[prev/2-1].title[:width] stdscr.addstr(prev, pad, title) title = subs[location/2 -1].title[:width] mainscr.addstr(location, pad, title, curses.A_UNDERLINE) mainscr.refresh() curses.flash()
def handle(*args): global exitmenu curses.flash() #curses.refresh() exitmenu = True size = screen.getmaxyx() #sys.stderr.write("Now %u x %u\n" % (size[1],size[0])) processmenu(menu_data)
def send_signal(signal): """ Send the signal to the selected master gunicorn process and show the given message as the current status. """ if selected_pid in gunicorns: Popen(["kill", "-%s" % signal, selected_pid]) curses.flash()
def selectmenu(title,options): screen = curses.initscr() curses.start_color() curses.init_pair(1,curses.COLOR_RED, curses.COLOR_WHITE) screen.keypad(1) pos = 1 x = None while x != ord('\n'): # Gotta reset the screen from the root or lose the border, window, etc. screen.clear() screen.border(0) screen.addstr(2,2, title, curses.A_BOLD + curses.COLOR_GREEN) screen.addstr(4,2, "Select a command:", curses.A_BOLD) for i in range(0,len(options)): if i == pos - 1: h = curses.color_pair(1) else: h = curses.A_NORMAL screen.addstr(i+6,4, options[i],h) screen.refresh() x = screen.getch() ## Is 'x' 1-5 or arrow up, arrow down? #if x == ord('1'): # pos = 1 #elif x == ord('2'): # pos = 2 #elif x == ord('3'): # pos = 3 #elif x == ord('4'): # pos = 4 #elif x == ord('5'): # pos = 5 # It was a pain in the ass trying to get the arrows working. if x in range(ord('1'), ord(chr(len(options)))): pos = x elif x == 258: if pos < len(options): pos += 1 else: pos = 1 # Since the curses.KEY_* did not work, I used the raw return value. elif x == 259: if pos > 1: pos += -1 else: pos = len(options) elif x != ord('\n'): curses.flash() # show_error() is my custom function for displaying a message: # show_error(str:message, int:line#, int:seconds_to_display) #show_error('Invalid Key',11,1) screen.clear() curses.endwin() return pos
def _move_page(self, direction): self._remove_cursor() valid, redraw = self.nav.move_page(direction, len(self._subwindows)-1) if not valid: curses.flash() # Note: ACS_VLINE doesn't like changing the attribute, so always redraw. self._draw_content() self._add_cursor()
def logout(self): "Prompt to log out of the user's account." ch = prompt_input(self.stdscr, "Log out? (y/n):") if ch == 'y': self.reddit.clear_authentication() show_notification(self.stdscr, ['Logged out']) elif ch != 'n': curses.flash()
def open_link(self): "Open the current submission page with the webbrowser" data = self.content.get(self.nav.absolute_index) url = data.get('permalink') if url: open_browser(url) else: curses.flash()
def main(scrn): box = scrn.subwin(3,5, 0,0) box.box() box.addstr(1,1, "box") border = scrn.subwin(3,8, 0,6) border.border() border.addstr(1,1, "border") background = scrn.subwin(3,14, 0,15) curses.init_pair(7, curses.COLOR_RED, curses.COLOR_GREEN) curses.init_pair(8, curses.COLOR_BLUE, curses.COLOR_WHITE) background.bkgd("#", curses.color_pair(7)) background.addstr(1,2, "background", curses.color_pair(8)) background.refresh background2 = scrn.subwin(4,14, 0,30) background2.bkgdset("#") background2.addstr(" ") background2.addstr(" background ") background2.addstr(" ") lines = scrn.subwin(3,11, 0,45) lines.hline(1,0, curses.ACS_HLINE, 11) lines.vline(0,2, curses.ACS_VLINE, 3) lines.vline(0,8, curses.ACS_VLINE, 3) lines.addstr(0,3, "lines") lines.addch(1,2, curses.ACS_SSSS) lines.addch(1,8, curses.ACS_SSSS) text = scrn.subwin(10,9, 4,0) text.addstr(0,0, "dim", curses.A_DIM) text.addstr(1,0, "normal", curses.A_NORMAL) text.addstr(2,0, "underline", curses.A_UNDERLINE) text.addstr(3,0, "bold", curses.A_BOLD) text.addstr(4,0, "standout", curses.A_STANDOUT) text.addstr(5,0, "reverse", curses.A_REVERSE) text.addstr(6,0, "blink", curses.A_BLINK) text.addstr(7,0, "invisible", curses.A_INVIS) curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_BLUE, curses.COLOR_BLACK) curses.init_pair(3, curses.COLOR_GREEN, curses.COLOR_BLACK) text.move(8,0) text.addch("c", curses.color_pair(1) | curses.A_BOLD) text.addch("o", curses.color_pair(2) | curses.A_BOLD) text.addch("l", curses.color_pair(3) | curses.A_BOLD) text.addch("o", curses.color_pair(2) | curses.A_BOLD) text.addch("r", curses.color_pair(1) | curses.A_BOLD) scrn.addstr(15,0, curses.termname()) scrn.addstr(": " + curses.longname()) scrn.getch() curses.flash() scrn.getch()
def main_menu(self, stdscr): self.page_name = "Main Menu" k = 0 flag_back = False flag_fwd = False self.cursor_x = self.const_maxX self.cursor_y = self.const_maxY self.gui_refresh(stdscr) self.draw_common_elements(stdscr) element_list = self.load_list_elements(self.board_list, final_text=" -->") while (k != ord('q')): self.page_name = "Main Menu" flag_back = False flag_fwd = False if k == curses.KEY_LEFT: #curses.flash() flag_back = True elif k == curses.KEY_RIGHT: flag_fwd = True #stdscr.attron(curses.color_pair(1)) #stdscr.addstr(int((self.height / 2 + 3)), 0, "Right key pressed") #stdscr.attroff(curses.color_pair(1)) elif k == curses.KEY_DOWN: self.cursor_y = self.cursor_y + 1 elif k == curses.KEY_UP: self.cursor_y = self.cursor_y - 1 # check new coordinates against designated max/min values self.cursor_x = max(self.const_maxX, self.cursor_x) self.cursor_x = min(self.volatile_minX, self.cursor_x) self.cursor_y = max(self.const_maxY, self.cursor_y) self.cursor_y = min(self.volatile_minY, self.cursor_y) self.gui_refresh(stdscr) self.draw_menu(element_list, stdscr) self.draw_common_elements(stdscr) if flag_back is True: curses.flash() if flag_fwd is True: self.menu_enter(stdscr, element_list, self.main_menu_enter_handler) """stdscr.attron(curses.color_pair(1)) stdscr.addstr(int((self.height - 3)), 0, "Right key pressed") stdscr.attroff(curses.color_pair(1))""" # Refresh the screen stdscr.refresh() # Wait for next input k = stdscr.getch()
def hardwarenetmenu(): screen.keypad(1) curses.init_pair(1, curses.COLOR_BLUE, curses.COLOR_WHITE) pos = 1 x = None h = curses.color_pair(1) #h is the coloring for a highlighted menu option n = curses.A_NORMAL #n is the coloring for a non highlighted menu option while x != ord('\n'): screen.clear() screen.border(0) screen.addstr(0, 18, "The Raspberry-PI Control Center (RCC)", curses.A_STANDOUT) # Title screen.addstr(4, 2, "Environment / Network Menu", curses.A_STANDOUT) if pos == 1: screen.addstr(5, 4, "1 - Network Service Information", h) else: screen.addstr(5, 4, "1 - Network Service Information", n) if pos == 2: screen.addstr(6, 4, "2 - Wireless Connection Status", h) else: screen.addstr(6, 4, "2 - Wireless Connection Status", n) if pos == 3: screen.addstr(7, 4, "3 - Ethernet Connection Status", h) else: screen.addstr(7, 4, "3 - Ethernet Connection Status", n) if pos == 4: screen.addstr(8, 4, "4 - Return to the menu", h) else: screen.addstr(8, 4, "4 - Return to the menu", n) screen.refresh() x = screen.getch() # Gets user input if x == ord('1'): pos = 1 elif x == ord('2'): pos = 2 elif x == ord('3'): pos = 3 elif x == ord('4'): pos = 4 elif x == 258: if pos < 4: pos += 1 else: pos = 1 elif x == 259: if pos > 1: pos += -1 else: pos = 4 elif x != ord('\n'): curses.flash() return ord(str(pos))
def death(): for i in range(0, 4): curses.flash() sleep(0.08) w.clear() w.addstr(int(hei / 2), int(wei), 'Game Over!', curses.color_pair(2)) w.refresh() sleep(1.5) curses.endwin() quit()
def onClick(self, x, y): ch = self.itemHeight for i in range(0, len(self.buttons)): start = i * (ch + 1) + 1 + self.yOffset end = start + 2 if start <= y <= end: self.doClick(i) curses.flash()
def _retryOrQuit(self, y=1, x=2): while True: self._inputWin.addstr(y, x, "(R)etry or (Q)uit ?") key = self._inputWin.getkey() if key == "r": return True elif key == "q": return False else: curses.flash()
def exit(self): """ Prompt to exit the application. """ ch = prompt_input(self.stdscr, "Do you really want to quit? (y/n): ") if ch == 'y': sys.exit() elif ch != 'n': curses.flash()
def __exit__(self, type, value, traceback): """ Terminates the curses application and returns control to the terminal :return: None """ curses.flash() curses.nocbreak() self.stdscr.keypad(False) curses.echo() curses.endwin()
def terminate_curses(self): """ Terminates the curses application and returns control to the terminal :return: None """ curses.flash() curses.nocbreak() self.stdscr.keypad(False) curses.echo() curses.endwin()
def refresh_content(self, order=None): "Re-download all subscriptions and reset the page index" if order: # reddit.get_my_subreddits() does not support sorting by order curses.flash() else: self.content = SubscriptionContent.from_user( self.reddit, self.loader) self.nav = Navigator(self.content.get)
def runmenu(menu, parent): # work out what text to display as the last menu option if parent is None: lastoption = "Exit" else: lastoption = "Return to %s menu" % parent['title'] optioncount = len(menu['options']) # how many options in this menu pos=0 #pos is the zero-based index of the hightlighted menu option. Every time runmenu is called, position returns to 0, when runmenu ends the position is returned and tells the program what option has been selected oldpos=None # used to prevent the screen being redrawn every time x = None #control for while loop, let's you scroll through options until return key is pressed then returns pos to program # Loop until return key is pressed while x !=ord('\n'): if pos != oldpos: oldpos = pos screen.clear() #clears previous screen on key press and updates display based on pos screen.border(0) screen.addstr(2,2, menu['title'], curses.A_STANDOUT) # Title for this menu screen.addstr(4,2, menu['subtitle'], curses.A_BOLD) #Subtitle for this menu # Display all the menu items, showing the 'pos' item highlighted for index in range(optioncount): textstyle = n if pos==index: textstyle = h screen.addstr(5+index,4, "%d - %s" % (index+1, menu['options'][index]['title']), textstyle) # Now display Exit/Return at bottom of menu textstyle = n if pos==optioncount: textstyle = h screen.addstr(5+optioncount,4, "%d - %s" % (optioncount+1, lastoption), textstyle) screen.refresh() # finished updating screen x = screen.getch() # Gets user input # What is user input? if x >= ord('1') and x <= ord(str(optioncount+1)): pos = x - ord('0') - 1 # convert keypress back to a number, then subtract 1 to get index elif x == 258: # down arrow if pos < optioncount: pos += 1 else: pos = 0 elif x == 259: # up arrow if pos > 0: pos += -1 else: pos = optioncount elif x != ord('\n'): curses.flash() # return index of the selected item return pos
def StartSearch(self): if self.search: self.engine.stop() self.state['forcemove'] = False if not self.state['engine']: return if (self.state['board'].is_checkmate() or self.state['board'].is_stalemate()): logging.info("Terminal position, not searching") return logging.info("Starting search") self.SaveState() self.state['info'] = [None] + self.state['info'][:27] board = self.state['board'] idx = 0 if board.turn else 1 self.engine.position(board) params = {} if self.state['timedsearch'][idx]: if self.opening_book: try: entry = self.opening_book.weighted_choice( self.state['board']) logging.info("Opening book hit: %s" % str(entry.move())) idx = 0 if self.state['board'].turn else 1 self.state['board'].push(entry.move()) self.state['timer'][idx] += INCREMENT_MS self.state['movetimer'][1 - idx] = 0 self.state['nextmove'] = '' curses.flash() curses.beep() self.state['moveready'] = True self.StartSearch() return except IndexError: pass params['wtime'] = self.state['timer'][0] params['btime'] = self.state['timer'][1] params['winc'] = INCREMENT_MS params['binc'] = INCREMENT_MS self.state['enginestatus'] = "go wtime %d btime %d" % tuple( self.state['timer']) else: params['infinite'] = True self.state['enginestatus'] = "go infinite" logging.info("Starting search, params: %s" % repr(params)) self.search = self.engine.go(async_callback=True, **params)
def edit(self): self.text_win.clear() try: self.text_win.addstr(self.pages[self.pagenum]) except curses.error: pass textbox = Textbox(self.text_win, insert_mode=True) if not self.istest: textbox.edit() self.pages[self.pagenum] = collect(textbox) curses.flash()
def processcommand(cmd): global band, mode, power, quit cmd = cmd[1:].upper() if cmd == "Q": # Quit quit = True return if cmd[:1] == "B": # Change Band setband(cmd[1:]) return if cmd[:1] == "M": # Change Mode if cmd[1:] == "CW" or cmd[1:] == "PH" or cmd[1:] == "DI": setmode(cmd[1:]) else: curses.flash() curses.beep() return if cmd[:1] == "P": # Change Power setpower(cmd[1:]) return if cmd[:1] == "D": # Delete Contact delete_contact(cmd[1:]) return if cmd[:1] == "E": # Edit QSO editQSO(cmd[1:]) return if cmd[:1] == "H": # Print Help displayHelp() return if cmd[:1] == "K": # Set your Call Sign setcallsign(cmd[1:]) return if cmd[:1] == "C": # Set your class setclass(cmd[1:]) return if cmd[:1] == "S": # Set your section setsection(cmd[1:]) return if cmd[:1] == "L": # Generate Cabrillo Log cabrillo() return if cmd[:1] == "1": # Claim Alt Power Bonus claimAltPower() return if cmd[:1] == "2": # Claim Outdoor Bonus claimOutdoors() return if cmd[:1] == "3": # Claim Not Home Bonus claimNotHome() return if cmd[:1] == "4": # Claim Satellite Bonus claimSatellite() return curses.flash() curses.beep()
def handle(self, stdscr, window, height, width, key): if key == curses.KEY_UP and self.selected > 0: self.selected = self.selected-1 elif key == curses.KEY_DOWN and self.selected < len(self.modules)-1: self.selected = self.selected+1 elif key == ord('\n'): if self.selected >= 0: self.modules[self.selected].enabled = not self.modules[self.selected].enabled else: curses.flash() return(True)
def handle(self, stdscr, window, height, width, key): if key == ord('\n'): self.new_commented = False if self.new_commented or not self.new_setting or self.new_setting == 'yes': self.new_setting = 'no' else: self.new_setting = 'yes' else: curses.flash() return(True)
def stop(self): curses.flash() win = curses.newwin(5, 75, 18, 35) win.border() win.addstr(2, 1, " You have enough codes to defuse the bomb...!!", curses.color_pair(1)) win.refresh() time.sleep(1) win = curses.newwin(5, 75, 18, 35) win.refresh()
def _screen_height(self) -> int: """Return the screen height, or notify if too small. :returns: the current screen height """ while True: if self._screen.getmaxyx()[0] >= self._screen_min_height: return self._screen.getmaxyx()[0] curses.flash() curses.beep() self._screen.refresh()
def main(stdscr): stdscr.clear() stdscr.refresh() win = curses.newwin(5, 60, 5, 10) tb = curses.textpad.Textbox(win, insert_mode=True) text = tb.edit() curses.flash() win.clear() win.addstr(0, 0, text.encode('utf-8')) win.refresh() win.getch()
def _move_page(self, direction): self._remove_cursor() valid, redraw = self.nav.move_page(direction, len(self._subwindows)-1) if not valid: curses.flash() self._draw_content() # Don't allow the cursor to go over the subwindow number if self.nav.cursor_index >= len(self._subwindows): self.nav.cursor_index = len(self._subwindows)-1 self._add_cursor()
def my_exit (code, message): screen.clear() curses.flash() screen.addstr(1,1,message, curses.A_BOLD) screen.addstr(3,1,"Press SPACE to exit") screen.refresh() while screen.getch() != ord(' '): screen.refresh() curses.endwin() sys.exit(code)
def submenu1(): screen.keypad(1) curses.init_pair(1,curses.COLOR_BLACK, curses.COLOR_WHITE) pos=1 x = None h = curses.color_pair(1) n = curses.A_NORMAL while x !=ord('\n'): screen.clear() screen.border(0) screen.addstr(2,2, "Dosbox Games", curses.A_STANDOUT) screen.addstr(4,2, "Please selection an option...", curses.A_BOLD) #Detect what is higlighted if pos==1: screen.addstr(5,4, "1 - Midnight Resuce", h) else: screen.addstr(5,4, "1 - Midnight Rescue", n) if pos==2: screen.addstr(6,4, "2 - Treasure Mountain", h) else: screen.addstr(6,4, "2 - Treasure Mountain", n) if pos==3: screen.addstr(7,4, "3 - Return to Top Menu", h) else: screen.addstr(7,4, "3 - Return to Top Menu", n) screen.refresh() x = screen.getch() # What is user input? if x == ord('1'): pos = 1 elif x == ord('2'): pos = 2 elif x == ord('3'): pos = 3 elif x == 258: # This needs to be updated on changes to equal the total number of entries in the menu if pos < 3: # This doesn't need to be changed no matter how many entries you have pos += 1 else: pos = 1 elif x == 259: if pos > 1: pos += -1 # This needs to be updated on changes to equal the total number of entries in the menu else: pos = 3 elif x != ord('\n'): curses.flash() return ord(str(pos))
def listener(): global imuwin, maxx, maxy global alarm, alarm_count, alarm_interval global rec_enable rospy.init_node('asctec_monitor') rospy.Subscriber("asctec/LL_STATUS", LLStatus, callback) rospy.Subscriber("asctec/IMU_CALCDATA", IMUCalcData, imu_callback) rospy.Subscriber("asctec/GPS_DATA", GPSData, gps_callback) curses.init_pair(1, curses.COLOR_MAGENTA, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(3, curses.COLOR_GREEN, curses.COLOR_BLACK) curses.init_pair(4, curses.COLOR_BLACK, curses.COLOR_WHITE) curses.init_pair(5, curses.COLOR_BLACK, curses.COLOR_RED) r = rospy.Rate(10) # Hz (maxx, maxy) = myscreen.getmaxyx() while not rospy.is_shutdown(): c = myscreen.getch() if c == ord('f'): curses.flash() elif c == ord('b'): curses.beep() elif c == ord('r'): rec_enable = not rec_enable elif c == ord('q'): break # Exit the while() elif c == curses.KEY_HOME: x = y = 0 (current_maxx, current_maxy) = myscreen.getmaxyx() if (current_maxx != maxx or current_maxy != maxy): (maxx, maxy) = myscreen.getmaxyx() gpswin.mvwin(maxx - 14, 0) llwin.mvwin(maxx - 11, 0) imuwin = curses.newwin(maxx - 14, maxy, 0, 0) #imuwin.refresh() #llwin.refresh() #gpswin.refresh() if (alarm): alarm_count = alarm_count + 1 if (alarm_count == alarm_interval): alarm_count = 0 curses.flash() curses.beep() if (not gps_lock): gpswin.refresh() if (not imu_lock): imuwin.refresh() if (not ll_lock): llwin.refresh() record_update() recwin.refresh() r.sleep() curses.nocbreak() myscreen.keypad(0) curses.echo() curses.curs_set(1) curses.endwin()
def draw(self): p = 0 book = Book(self.poems) padding = 1 y = 0 x = padding def col_count(poem): count = (self.width - (padding * 2)) / (poem.line_length + self.gutter) return count try: while True: if (y >= self.rows): y = 0 col_width = book.poems[p].max_line_length + self.gutter x = x + col_width if x + col_width > self.cols: self.screen.clear() x = 0 line = book.poems[p].read_line() if line == None: curses.flash() time.sleep(self.poempause) curses.flash() self.screen.clear() if p == book.poem_count - 1: p = 0 else: p = p + 1 y = 0 x = 1 line = book.poems[p].read_line() step = 0 for char in line: self.screen.addstr(y, x + step, char) self.screen.refresh() time.sleep(self.charpause) step = step + 1 step = 0 self.screen.refresh() time.sleep(self.linepause) y = y + 1 except: self._restore() self._restore()
def _alert(self, text): '''perform program alert''' if not self._curAlert: self._curAlert = True curses.flash() self._screen.addstr( self._screensize[0] - 1, 0, ' {0:{width}}'.format(text, width=self._screensize[1] - 2), curses.color_pair(self.COLOR_ERROR)) self._screen.refresh() self._setTimer('alert', 1, self._redrawMenu) else: self._alertStack.append(text)
def add_comment(self): """ Add a comment on the submission if a header is selected. Reply to a comment if the comment is selected. """ if not self.reddit.is_logged_in(): show_notification(self.stdscr, ["Login to reply"]) return data = self.content.get(self.nav.absolute_index) if data['type'] not in ('Comment', 'Submission'): curses.flash() return # Fill the bottom half of the screen with the comment box n_rows, n_cols = self.stdscr.getmaxyx() box_height = n_rows // 2 attr = curses.A_BOLD | Color.CYAN for x in range(n_cols): y = box_height - 1 # http://bugs.python.org/issue21088 if (sys.version_info.major, sys.version_info.minor, sys.version_info.micro) == (3, 4, 0): x, y = y, x self.stdscr.addch(y, x, curses.ACS_HLINE, attr) prompt = 'Enter comment: ESC to cancel, Ctrl+g to submit' scol = max(0, (n_cols // 2) - (len(prompt) // 2)) self.stdscr.addnstr(box_height - 1, scol, prompt, n_cols - scol, attr) self.stdscr.refresh() window = self.stdscr.derwin(n_rows - box_height, n_cols, box_height, 0) window.attrset(Color.CYAN) comment_text = text_input(window, allow_resize=False) if comment_text is None: return try: if data['type'] == 'Submission': data['object'].add_comment(comment_text) else: data['object'].reply(comment_text) except praw.errors.APIException as e: show_notification(self.stdscr, [e.message]) else: time.sleep(0.5) self.refresh_content()
def cars_func(): global race_cars car_id = "" owners_name = "" s = curses.newwin(6, 25, 2, 1) s.box() s.addstr(1, 2, "A", hotkey_attr) s.addstr(1, 3, "dd a Racer", menu_attr) s.addstr(2, 2, "L", hotkey_attr) s.addstr(2, 3, "ist Racers", menu_attr) s.addstr(3, 2, "G", hotkey_attr) s.addstr(3, 3, "et Cars From File", menu_attr) s.addstr(1, 2, "", hotkey_attr) #Reset Cursor Locaton s.refresh() c = s.getch() if c in (ord('A'), ord('a')): s1 = curses.newwin(6, 35, 3, 3) s1.box() curses.echo() curses.curs_set(1) s1.addstr(1, 1, "Add New Race Car Owner:") correct = False while not correct: s1.addstr(2, 1, " Car ID:" + " " * 20) s1.addstr(3, 1, "Owners Name:" + " " * 20) s1.addstr(4, 1, " " * 20) s1.refresh() car_id = byte_to_str(s1.getstr(2, 14, 3)) owners_name = byte_to_str(s1.getstr(3, 14, 20)) s1.addstr(4, 1, "OK (Y/N)") c = s1.getch() if c in (ord('N'), ord('n')): correct = False else: correct = True race_cars[car_id] = Awana_Car(car_id, owners_name) save_car_to_file(race_cars[car_id]) curses.noecho() curses.curs_set(0) s1.erase() elif c in (ord('L'), ord('l')): list_the_cars() elif c in (ord('G'), ord('g')): if get_cars_from_file(): list_the_cars() else: curses.beep() curses.flash() s.erase() return CONTINUE
def explanation(title, text1, text2, stdscr): """Outputs explanation of a specific data structure :param title: title of DS :param text: explanation :param stdscr: curses background """ curses.flash() textkey = curses.newwin(10, 76, 13, 2) textkey.border() textkey.refresh() stdscr.addstr(14, 4, title) stdscr.addstr(16, 4, text1) stdscr.addstr(18, 4, text2)