class CommandPad(Pad): def __init__(self, stdscr): super(CommandPad, self).__init__(stdscr) self.tb = Titlebar(self.stdscr) self.sb = Statusbar(self.stdscr, "(Status)", "", "") self.usage() def active(self): super(CommandPad, self).active() try: self.tb.draw() self.sb.draw("") except: raise def inactive(self): super(CommandPad, self).inactive() def usage(self): self.dlog.msg(str(self.get_position()) + "\n") self.addstr("__ __ _ _ \n") self.addstr("\ \ / /__| |_| |_ _ _\n") self.addstr(" \ V / _ \ _| _| || |\n") self.addstr(" |_|\___/\__|\__|\_,_|\n") self.addstr("Yottu v.0.1 - https://github.com/yottu/yottu\n", curses.A_BOLD) self.addstr("\n") self.addstr("Set board context: /board <board>\n") self.addstr("Display Threads in current board context: /list <board> [not implemented]\n") self.addstr("Open a thread in current board context: /join <thread number>\n") self.addstr("Show settings: /set\n") self.addstr("Save settings: /save\n")
def __init__(self, stdscr, wl): self.stdscr = stdscr self.wl = wl # WindowLogic self.cfg = self.wl.cfg self.lock = thread.allocate_lock() # Used for concurrent writing by multiple threads self.screensize_y, self.screensize_x = self.stdscr.getmaxyx(); height = self.screensize_y-Pad.reservedscreen width = self.screensize_x self.pheight = height self.pwidth = width self.mypad = curses.newpad(self.pheight+Pad.padbuffersize, self.pwidth) # @UndefinedVariable curses.curs_set(False) # @UndefinedVariable self.padr = 0; self.padu = 0; self.padd = 0 self.mypad.refresh(0, self.padr, self.padu, self.padd, self.pheight, self.pwidth) # count new lines added by this function for autoscrolling (self.pposy, self.pposx) = self.mypad.getyx() (self.pmaxy, self.pmaxx) = self.mypad.getmaxyx() self.actualpmaxy = self.pmaxy-Pad.padbuffersize self.tb = Titlebar(self.stdscr, self.wl, self) self.sb = Statusbar(self.stdscr, self.wl, self, nickname="(<Pad>)") self.dlog = self.wl.dlog #DebugLog("debug.log") self.dlog.msg("pmaxy: " + str(self.pmaxy), 5) self.dlog.msg("actualpmaxy: " + str(self.actualpmaxy), 5) self._active = False # Pad is actively viewed by user self.autoScroll = True self.size = 0 # Number of lines in pad self.position = 0 self.line = ''.encode('utf-8') self.marked_line = None self.nickname = ""
def __init__(self, threadno, stdscr, board, bp, nickname): self.threadno = threadno self.stdscr = stdscr self.board = board self.bp = bp self.nickname = nickname self.sb = Statusbar(self.stdscr, self.nickname, self.board, self.threadno) self.tb = Titlebar(self.stdscr) Thread.__init__(self) self._stop = threading.Event() self._active = False # BoardPad the ThreadFetcher runs in is active
def __init__(self, root): Logo = PhotoImage(file = 'Logo.png') # This will load logo for Quantum IDE Font_data = ("calibri", 11) # This Font data will be used to add font to this IDE # This will add Title and give Quantum a resolution root.title("Quantum") root.geometry("1000x675") root.iconphoto(False, Logo) # These are the global variables self.root = root self.filename = None # This is Text widget in which you can type anything self.Text_area = Text(root, font = Font_data, selectbackground = "#474747", insertbackground = "#ff1269", foreground = "#f9f9f9", background = "#222222", undo = True, wrap = WORD) # This is Scrollbar widget to add a scrollbar in Text widget self.scroll = Scrollbar(root, command = self.Text_area.yview) # This will configure and pack Text_area and scroll objects self.Text_area.configure(yscrollcommand = self.scroll.set) self.Text_area.pack(side = LEFT, fill = BOTH, expand = True) self.scroll.pack(side = RIGHT, fill = Y) # This is a Custom Menu Class in which New and more items are there. self.menu = Menubar(self) self.status = Statusbar(self) self.intellisense = Intellisense(self) self.binding_keys()
def __init__(self, stdscr): super(CommandPad, self).__init__(stdscr) self.tb = Titlebar(self.stdscr) self.sb = Statusbar(self.stdscr, "(Status)", "", "") self.usage()
def __init__(self): # TODO: Set up proper logging (with the logging module) # TODO: Handle window resizing (distributing extra space to columns, probably the columns with treeviews first GlobalValues.root = Tkinter.Tk() GlobalValues.root.title( "Ophidian - MTG Card Searcher and Deck Builder v0.1.1") # 'Ophidian'? It's both the larger snake species, an MTG creature and a D&D snake-like monster # Get it? Snake? Python? Anyway the D&D Ophidian turns creatures it bites into Ophidians, and the # Ophidian MTG creature allows you to draw a card if it attacks unopposed. Both are kind of apt # 'Ophidian 2350' is also a separate collectible card game though # Intercept the 'window close' event, so we can check if there's stuff like unsaved changes before actually closing GlobalValues.root.protocol('WM_DELETE_WINDOW', self.onProgramClose) GlobalValues.settings = Settings() # Set the global data folder to the one from settings GlobalValues.carddatafolder = GlobalValues.settings.getSetting( 'datafolder', os.path.join(GlobalValues.mainfolder, 'data')) # Start with the Status Bar, so other parts can use it right away GlobalValues.statusbar = Statusbar(GlobalValues.root) GlobalValues.statusbar.grid(column=0, row=5, columnspan=2, sticky=Tkinter.W) searchEntryFrame = SearchEntryFrame(GlobalValues.root, width=300, height=250) searchEntryFrame.grid(column=0, row=0, sticky=Tkinter.N) GlobalValues.searchResultsFrame = SearchResultsFrame(GlobalValues.root, width=300, height=400) GlobalValues.searchResultsFrame.grid(column=0, row=1) GlobalValues.cardDisplayFrame = CardDisplayFrame(GlobalValues.root, width=500, height=650) GlobalValues.cardDisplayFrame.grid(column=1, row=0, rowspan=2, sticky=Tkinter.NW) GlobalValues.chosenCardsFrame = ChosenCardsFrame(GlobalValues.root, width=350, height=600) GlobalValues.chosenCardsFrame.grid(column=2, row=0, rowspan=2, sticky=Tkinter.NSEW) # Add a checkbox to toggle card image downloading and display, but only if we can actually show images if GlobalValues.isImageLibraryLoaded: self.showImageCheckbuttonValue = Tkinter.IntVar() toggleImageDisplayCheckbox = Tkinter.Checkbutton( GlobalValues.root, text="Show Card Images") toggleImageDisplayCheckbox.configure( variable=self.showImageCheckbuttonValue, command=self.toggleShowingImages) toggleImageDisplayCheckbox.grid(column=2, row=5, sticky=Tkinter.E) if GlobalValues.settings.getSetting('showImages', True): toggleImageDisplayCheckbox.select() # Check if we need to update the card database cardFileDownloader = CardFileDownloader(GlobalValues.root) updateResult = cardFileDownloader.handleCardFileUpdate(True) # Load the cards if not os.path.exists( os.path.join(GlobalValues.carddatafolder, 'cards.json')): tkMessageBox.showerror( "Cardfile not foun", "The card database\ncould not be found\n\nPlease try restarting the program\nand letting the updater run", parent=GlobalValues.root) GlobalValues.root.quit() else: with open(os.path.join(GlobalValues.carddatafolder, 'cards.json'), 'r') as cardfile: GlobalValues.cards = json.load(cardfile) # Fill out the results list GlobalValues.searchResultsFrame.addCards(GlobalValues.cards.keys()) GlobalValues.root.mainloop()
class Pad(object): reservedscreen = 3 padbuffersize = 8192 def __init__(self, stdscr, wl): self.stdscr = stdscr self.wl = wl # WindowLogic self.cfg = self.wl.cfg self.lock = thread.allocate_lock() # Used for concurrent writing by multiple threads self.screensize_y, self.screensize_x = self.stdscr.getmaxyx(); height = self.screensize_y-Pad.reservedscreen width = self.screensize_x self.pheight = height self.pwidth = width self.mypad = curses.newpad(self.pheight+Pad.padbuffersize, self.pwidth) # @UndefinedVariable curses.curs_set(False) # @UndefinedVariable self.padr = 0; self.padu = 0; self.padd = 0 self.mypad.refresh(0, self.padr, self.padu, self.padd, self.pheight, self.pwidth) # count new lines added by this function for autoscrolling (self.pposy, self.pposx) = self.mypad.getyx() (self.pmaxy, self.pmaxx) = self.mypad.getmaxyx() self.actualpmaxy = self.pmaxy-Pad.padbuffersize self.tb = Titlebar(self.stdscr, self.wl, self) self.sb = Statusbar(self.stdscr, self.wl, self, nickname="(<Pad>)") self.dlog = self.wl.dlog #DebugLog("debug.log") self.dlog.msg("pmaxy: " + str(self.pmaxy), 5) self.dlog.msg("actualpmaxy: " + str(self.actualpmaxy), 5) self._active = False # Pad is actively viewed by user self.autoScroll = True self.size = 0 # Number of lines in pad self.position = 0 self.line = ''.encode('utf-8') self.marked_line = None self.nickname = "" def get_nickname(self): return self.__nickname def set_nickname(self, value): try: self.__nickname = value self.sb.set_nickname(self.nickname) except Exception as e: self.dlog.excpt(e, msg=">>>in Pad.set_nickname()", cn=self.__class__.__name__) def autofocus(self): ''' Raise window on configuration directive ''' try: window_index = self.wl.get_window(self) active_window_index = self.wl.get_active_window() if self.cfg.get('window.board.autofocus') and window_index is not active_window_index: self.wl.set_active_window(window_index) self.autoScroll = True self.auto_scroll() except Exception as e: self.dlog.excpt(e, msg=">>>in Pad.autofocus()", cn=self.__class__.__name__) # Updater polls this method every n seconds def on_update(self): pass def stop(self): self._stop.set() def active(self): self._active = True self.stdscr.clear() try: if self.autoScroll and self.__position is self.size: self.clear_unread_window_elements() self.sb.active() self.tb.active() self.draw() except Exception as e: self.dlog.excpt(e, msg=">>>in Pad.active()", cn=self.__class__.__name__) def clear_unread_window_elements(self): ''' Reset window's unread properties and remove unread status from status bar ''' try: self.wl.set_property(self, 'sb_unread', False) self.wl.windowListProperties[self]['sb_lines'] = 0 self.wl.windowListProperties[self]['sb_mentioned'] = False self.generate_unread_window_element() except Exception as e: self.dlog.excpt(e, msg=">>>in Pad.clear_unread_window_elements()", cn=self.__class__.__name__) def inactive(self): self._active = False self.sb.inactive() self.tb.inactive() def on_resize(self): try: screensize_y, screensize_x = self.stdscr.getmaxyx() curses.resize_term(screensize_y, screensize_x) # @UndefinedVariable height = screensize_y-self.reservedscreen; width = screensize_x self.pheight = height self.pwidth = width self.mypad.resize(self.pheight+Pad.padbuffersize, self.pwidth) (self.pposy, self.pposx) = self.mypad.getyx() (self.pmaxy, self.pmaxx) = self.mypad.getmaxyx() self.actualpmaxy = self.pmaxy-Pad.padbuffersize self.draw() except Exception as e: self.dlog.excpt(e, msg=">>>in Pad.on_resize()", cn=self.__class__.__name__) def addstr(self, string, options=curses.A_NORMAL, indent=0, mentioned=False): # @UndefinedVariable try: # wait until other threads have finished writing self.lock.acquire_lock() # check if comment needs to be line wrapped, indent it if so if indent: # iterate over every character, note that BoardPad sends a string # for every word delimited by a space for stringpos, character in enumerate(string.decode('utf-8')): (self.pposy, self.pposx) = self.mypad.getyx() # FIXME: also == 'F' if (unicodedata.east_asian_width(u''.join(character)) or unicodedata.east_asian_width(u''.join(character)) == 'W') and self.pposx == self.pwidth-1: self.mypad.addstr("\n") (self.pposy, self.pposx) = self.mypad.getyx() self.size = self.pposy # wrap oversized word at the end of the line if stringpos == 0: space_needed = self.pposx + len(string) #indented_space = self.pmaxx - indent if space_needed > self.pwidth: self.mypad.addstr("\n") #self.line += u"\n".decode('utf-8') (self.pposy, self.pposx) = self.mypad.getyx() self.size = self.pposy # indent after line wrap if self.pposx == 0: self.mypad.addstr(" "*indent) # output the character and adjust the pad size self.mypad.addstr(character.encode('utf-8'), options) (self.pposy, self.pposx) = self.mypad.getyx() self.size = self.pposy # add string to current position else: self.mypad.addstr(string, options) (self.pposy, self.pposx) = self.mypad.getyx() self.size = self.pposy if mentioned: self.wl.windowListProperties[self]['sb_mentioned'] = True except Exception as err: self.dlog.excpt(err, msg=">>>in Pad.addstr() - indent != 0", cn=self.__class__.__name__) if str(err) == "addstr() returned ERR": self.dlog.msg("Pad full. Reinitializing..") self.mypad = curses.newpad(self.pheight+Pad.padbuffersize, self.pwidth) # @UndefinedVariable finally: self.lock.release_lock() # Increase unread line counter on inactive windows if re.search(r'\n', string): if not self._active or not self.autoScroll: try: self.wl.set_property(self, 'sb_unread', True) self.wl.windowListProperties[self]['sb_lines'] += 1 self.generate_unread_window_element() except KeyError: pass except Exception as err: self.dlog.excpt(err, msg="Pad.addstr() -> not self._active") self.auto_scroll() def calcline(self, line): ''' returns the width of an unicode string ''' lineLength = 0 try: for letter in line.decode('utf-8'): lineLength += 1 # Wide unicode takes two spaces if unicodedata.east_asian_width(letter) is 'W': lineLength +=1 except Exception as e: self.dlog.excpt(e, msg=">>>in Pad.calcline()", cn=self.__class__.__name__) finally: return lineLength def generate_unread_window_element(self): ''' generate list of tuples with (str, curses attribute) for unread windows this is passed to Statusbar which has no direct access to WindowLogic ''' unread_windows = [] # iterate over all window objects for window in self.wl.windowListProperties: # if the current window has unread messages if self.wl.get_property(window, 'sb_unread'): # get its index number windowNumber = self.wl.get_window_list().index(window) unread_lines = self.wl.get_property(window, 'sb_lines') # and append the index as a tuple with curses attribute to a list if self.wl.get_property(window, 'sb_mentioned'): unread_windows.append((windowNumber, curses.A_BOLD | curses.color_pair(2), # @UndefinedVariable unread_lines)) else: unread_windows.append((windowNumber, curses.A_BOLD | curses.color_pair(1), # @UndefinedVariable unread_lines)) # update the attribute of the current window's status bar active_win = self.wl.get_active_window_ref() active_win.sb.set_unread_windows(unread_windows) def set_auto_scroll(self, value): self.__autoScroll = value def get_position(self): return self.__position def set_position(self, value): self.dlog.msg("set_position: value/actualpmaxy: " + str(value) + "/" + str(self.actualpmaxy) + "\n", 5) self.__position = value if self._active: self.dlog.msg("set_position: moving to " + str(value), 5) self.move(value) # Update position on new line if self.__position is self.size: self.autoScroll = True # Clear unread elements self.clear_unread_window_elements() # # # Don't scroll if user is reading backlog # else: # self.autoScroll = False # self.generate_unread_window_element() def auto_scroll(self): try: if self.autoScroll is True: self.set_position(self.size) # TODO indicate there are new lines in the status bar else: pass except Exception as e: self.dlog.excpt(e, msg=">>>in Pad.auto_scroll()", cn=self.__class__.__name__) # FIXME merge moveup and down into one def def moveup(self, lines=1): newPos = self.get_position()-lines if newPos >= self.actualpmaxy: self.set_position(newPos) else: self.home() if newPos is not self.get_position()-lines: self.autoScroll = False else: self.autoScroll = True def movedown(self, lines=1): newPos = self.get_position()+lines self.dlog.msg("self.size: " + str(self.size), 5) if newPos <= self.size: self.set_position(newPos) self.autoScroll = False else: self.set_position(self.size) self.autoScroll = True def home(self): self.set_position(self.actualpmaxy) def end(self): self.set_position(self.size) # def move(self, pos): try: self.dlog.msg("Pad: in move", 5) self.dlog.msg("pmaxy: " + str(self.pmaxy), 5) self.dlog.msg("pmaxx: " + str(self.pmaxy), 5) self.dlog.msg("actualpmaxy: " + str(self.actualpmaxy), 5) newPos = pos-(self.pmaxy-(Pad.padbuffersize)) self.dlog.msg("newPos: " + str(newPos), 5) self.mypad.refresh(newPos, 0, 1, 0, self.actualpmaxy, self.pmaxx) except Exception as e: self.dlog.excpt(e, msg=">>>in Pad.move()", cn=self.__class__.__name__) raise def get_post_no_of_marked_line(self): y,x = self.save_position() try: if self.marked_line is not None: postno = "" for pos in range(6, 20): char = chr(self.mypad.inch(self.marked_line, pos) & curses.A_CHARTEXT) # @UndefinedVariable if pos == 6 or pos == 7: if char != ">": return None else: try: if int(char): pass postno += char except Exception: if len(postno) > 0: return postno return None except Exception as e: self.dlog.excpt(e, msg=">>>in Pad.get_postno_of_marked_line()", cn=self.__class__.__name__) return None finally: self.restore_postion(y, x) # FIXME reversed line doesn't look right in tmux def reverseline(self, pos_y, mode=curses.A_STANDOUT): # @UndefinedVariable '''Changes background to font and font to background in a pos_y (y-pos)''' try: for x in range (0, self.pwidth): charattr = self.mypad.inch(pos_y, x) # Filter some attributes for preservation attrs = charattr & curses.A_ATTRIBUTES ^ curses.A_STANDOUT ^ curses.A_COLOR # @UndefinedVariable # color = charattr & curses.A_COLOR # @UndefinedVariable # char = chr(charattr & curses.A_CHARTEXT) # @UndefinedVariable # color_pair_number = curses.pair_number(color) # @UndefinedVariable self.mypad.chgat(pos_y, x, 1, attrs | mode) # @UndefinedVariable # self.dlog.msg("Size of char: " + char +" | " + str(len(char)) + " | inch(): " + str(charattr) + " | cpn: " + str(color_pair_number)) except Exception as e: self.dlog.excpt(e, msg=">>>in Pad.reverseline()", cn=self.__class__.__name__) raise # FIXME: resizing messes up the position def markline(self, pos_y): try: self.screensize_y, self.screensize_x = self.stdscr.getmaxyx() y, x = self.save_position() self.unmarkline() previous_marked_line = self.marked_line # pos_y: absolute y-postion on screen, value from curses.get_mouse() # get_position(): position in virtual pad # screensize_y: number of lines on screen # unused_lines: lines the pad does not cover + 1 for command input unused_lines = 2 # Marked line relative to screen not counting pad size marked_line_rel = pos_y - unused_lines self.marked_line = marked_line_rel if self.size > self.screensize_y: self.marked_line += (self.get_position() - self.screensize_y + 3) #self.dlog.msg("ml: " + str(self.marked_line) + " = pos_y: " + str(pos_y) + " + pos(): " + str(self.get_position()) + " - ss_y: " + str(self.screensize_y) + " + 1") # Just unmark the pos_y if clicked twice if previous_marked_line == self.marked_line: self.marked_line = None return self.reverseline(self.marked_line) except Exception as e: self.dlog.excpt(e, msg=">>>in Pad.draw()", cn=self.__class__.__name__) finally: self.restore_postion(y, x) self.draw() def unmarkline(self): try: if self.marked_line is not None: self.reverseline(self.marked_line, curses.A_NORMAL) # @UndefinedVariable except Exception as e: self.dlog.excpt(e, msg=">>>in Pad.unmarkline()", cn=self.__class__.__name__) def save_position(self): y, x = self.mypad.getyx() return y, x def restore_postion(self, y, x): try: self.mypad.move(y, x) except Exception as e: self.dlog.excpt(e, msg=">>>in Pad.restore_position()", cn=self.__class__.__name__) def show_image(self): pass def draw(self): try: self.set_position(self.get_position()) self.stdscr.refresh() except Exception as e: self.dlog.excpt(e, msg=">>>in Pad.draw()", cn=self.__class__.__name__) def download_images(self): pass def query_userinput(self, label="Input: ", input_type="all", input_size=20): # Display query for pass pin and switch to command mode def valid_number(userchar): if 47 < userchar < 58: # 0 - 9 return userchar elif userchar == 263: # Backspace return userchar elif userchar == 10: # Enter return 7 # Ctrl+G (Terminate) else: self.dlog.msg("Invalid user input: " + (str(userchar))) return False def valid_text(userchar): if 47 < userchar < 58: # 0 - 9 return userchar if 64 < userchar < 90: # A - Z return userchar if 96 < userchar < 123: # a - z return userchar elif userchar == 263: # Backspace return userchar elif userchar == 10: # Enter return 7 # Ctrl+G (Terminate) else: self.dlog.msg("Invalid user input: " + (str(userchar))) return False try: total_size = len(label)+int(input_size) self.stdscr.addstr(2, 1, label) editwin = curses.newwin(1, int(input_size), 2, 1+len(label)) # window size(y,x) cursor postion(y,x) rectangle(self.stdscr, 1, 0, 3, 1+total_size+1) # y,x, height, width self.stdscr.refresh() box = Textbox(editwin) if input_type == "number": box.edit(valid_number) elif input_type == "text": box.edit(valid_text) else: box.edit() userinput = box.gather() return userinput[:-1] # strip ctrl+g except Exception as err: self.dlog.excpt(err, msg=">>>in Pad.query_userinput()", cn=self.__class__.__name__) position = property(get_position, set_position, None, None) nickname = property(get_nickname, set_nickname, None, None)
class Quantum: def __init__(self, root): Logo = PhotoImage(file = 'Logo.png') # This will load logo for Quantum IDE Font_data = ("calibri", 11) # This Font data will be used to add font to this IDE # This will add Title and give Quantum a resolution root.title("Quantum") root.geometry("1000x675") root.iconphoto(False, Logo) # These are the global variables self.root = root self.filename = None # This is Text widget in which you can type anything self.Text_area = Text(root, font = Font_data, selectbackground = "#474747", insertbackground = "#ff1269", foreground = "#f9f9f9", background = "#222222", undo = True, wrap = WORD) # This is Scrollbar widget to add a scrollbar in Text widget self.scroll = Scrollbar(root, command = self.Text_area.yview) # This will configure and pack Text_area and scroll objects self.Text_area.configure(yscrollcommand = self.scroll.set) self.Text_area.pack(side = LEFT, fill = BOTH, expand = True) self.scroll.pack(side = RIGHT, fill = Y) # This is a Custom Menu Class in which New and more items are there. self.menu = Menubar(self) self.status = Statusbar(self) self.intellisense = Intellisense(self) self.binding_keys() # This will update title of the window def update_title(self, name = None): if name: self.root.title(f"{name} - Quantum") else: self.root.title("Untitled - Quantum") self.intellisense.Colorcode() # This will create a new file in our IDE def new_file(self, *args): self.Text_area.delete(1.0, END) self.filename = None self.update_title() # This will open a file in our IDE def open_file(self, *args): self.filename = filedialog.askopenfilename( defaultextension = "*.*", filetypes = [("All Files", "*.*"), ("Markdown", ".md"), ("Text Files", ".txt"), ("Glass", ".glass"), ("C", ".c"), ("C#", ".cs"), ("C++", ".cpp"), ("Java", ".java"), ("Python", ".py"), ("Css", ".css"), ("HTML", ".html"), ("JavaScript", ".js")]) self.Text_area.delete(1.0, END) with open(self.filename, "r") as Data: self.Text_area.insert(1.0, Data.read()) self.update_title(self.filename) # This will save a file in our IDE def save_file(self, *args): if self.filename: try: textarea_content = self.Text_area.get(1.0, END) with open(self.filename, "w") as Data: Data.write(textarea_content) self.status.update_status(True) except Exception: pass else: self.save_file_as() # This will save a file with giving more control to the user in our IDE def save_file_as(self, *args): try: new_file = filedialog.asksaveasfilename( initialfile = "Untitled.txt", defaultextension = ".txt", filetypes = [("All Files", "*.*"), ("Markdown", ".md"), ("Text Files", ".txt"), ("Glass", ".glass"), ("C", ".c"), ("C#", ".cs"), ("C++", ".cpp"), ("Java", ".java"), ("Python", ".py"), ("Css", ".css"), ("HTML", ".html"), ("JavaScript", ".js")]) textarea_content = self.Text_area.get(1.0, END) with open(new_file, "w") as Data: Data.write(textarea_content) self.status.update_status(True) self.filename = new_file self.update_title(self.filename) except Exception: pass def do_ctrl_backspace(self, *args): self.Text_area.delete("insert -7 chars", "insert") def binding_keys(self): self.Text_area.bind('<Control-n>', self.new_file) self.Text_area.bind('<Control-o>', self.open_file) self.Text_area.bind('<Control-s>', self.save_file) self.Text_area.bind('<Control-S>', self.save_file_as) self.Text_area.bind('<Control-f>', self.menu.find) self.Text_area.bind('<Control-BackSpace>', self.do_ctrl_backspace) self.Text_area.bind('<Key>', self.status.update_status) self.Text_area.bind('<Alt-i>', self.intellisense.Colorcode)
class ThreadFetcher(threading.Thread): def __init__(self, threadno, stdscr, board, bp, nickname): self.threadno = threadno self.stdscr = stdscr self.board = board self.bp = bp self.nickname = nickname self.sb = Statusbar(self.stdscr, self.nickname, self.board, self.threadno) self.tb = Titlebar(self.stdscr) Thread.__init__(self) self._stop = threading.Event() self._active = False # BoardPad the ThreadFetcher runs in is active def stop(self): self._stop.set() def active(self): self._active = True self.tb.draw() def inactive(self): self._active = False def run(self): dlog = DebugLog() dlog.msg("ThreadFetcher: Running on /" + self.board + "/" + self.threadno + "\n", 3) try: dictOutput = DictOutput(self.bp) getThread = Autism(self.threadno, self.board) except Exception as e: dlog.excpt(e) self.stdscr.addstr(0, 0, str(e), curses.A_REVERSE) self.stdscr.refresh() self.tb.draw() while True: dlog.msg("ThreadFetcher: Fetching for /" + self.board + "/" + self.threadno + "\n", 3) if self._stop.is_set(): dlog.msg("ThreadFetcher: Stop signal for /" + self.board + "/" + self.threadno + "\n", 3) break try: getThread.setstdscr(self.stdscr) getThread.get() thread = getattr(getThread, "threadjson") dictOutput.refresh(thread) self.tb.set_title(dictOutput.getTitle()) except Exception as e: self.sb.setStatus(str(e)) dlog.excpt(e) pass for update_n in range (9, -1, -1): if self._stop.is_set(): break try: if self._active: self.sb.draw(update_n) except Exception as e: dlog.excpt(e) pass time.sleep(1)