def initwins(self, filename): self.fullwin = unbedwin(editor.mainwin, 2, 5) self.fullwin.clear() self.fullwin.addstr(0,0, filename) self.boxwin = embedwin(self.fullwin, 1, 0) self.boxwin.box() config = CreateDefaultConfig() self.editpad = EditPad(self.boxwin, 1, config, _plugins) self.fullwin.refresh() self.editpad.refresh() self.textwin = unbedwin(editor.mainwin, 7, 12)
class FileWin(object): def __init__(self, filename): self.f = None self.initwins(filename) try: self.f = open(filename, "r+b") self.editpad.loadfile(self.f) except IOError: self.f = None popup(self.textwin, ["*** ERROR ***: Could not open file", "Push any key to quit to the main menu"]) def process(self): if self.f == None: # Failed to open the file editor.SetActive(editor.mainmenu) return True self.editpad.refresh() char = self.editpad.getch() if char == ord('q'): editor.SetActive(editor.mainmenu) elif char == curses.KEY_UP: self.editpad.scroll(-1) elif char == curses.KEY_DOWN: self.editpad.scroll(1) elif char == ord('g'): t = Textbox(self.textwin, "Goto Line: ") val = t.gettext() self.editpad.goto(val) elif char >= ord('0') and char <= ord('9'): val = char - ord('0') self.editpad.activate_plugin(val) elif char == ord('`'): self.editpad.activate_plugin(-1) elif char == ord('\n'): self.editpad.set_preview() elif char == ord('x'): self.editpad.unset_preview() return True def exit(self): if self.f != None: self.f.close() self.fullwin.clear() self.fullwin.refresh() def initwins(self, filename): self.fullwin = unbedwin(editor.mainwin, 2, 5) self.fullwin.clear() self.fullwin.addstr(0,0, filename) self.boxwin = embedwin(self.fullwin, 1, 0) self.boxwin.box() config = CreateDefaultConfig() self.editpad = EditPad(self.boxwin, 1, config, _plugins) self.fullwin.refresh() self.editpad.refresh() self.textwin = unbedwin(editor.mainwin, 7, 12)