def __init__(self, cfg, gui=None): self.cfg = cfg if gui is None: self.standalone_run = True else: self.gui = gui self.standalone_run = False self.machine_api = self.cfg.machine_api if self.standalone_run: self.root = tkinter.Tk(className="EDITOR") self.root.geometry("+%d+%d" % (self.root.winfo_screenwidth() * 0.1, self.root.winfo_screenheight() * 0.1)) else: # As sub window in DragonPy Emulator self.root = tkinter.Toplevel(self.gui.root) self.root.geometry("+%d+%d" % ( self.gui.root.winfo_rootx() + self.gui.root.winfo_width(), self.gui.root.winfo_y() # FIXME: Different on linux. )) self.root.columnconfigure(0, weight=1) self.root.rowconfigure(0, weight=1) self.base_title = "%s - BASIC Editor" % self.cfg.MACHINE_NAME self.root.title(self.base_title) self.text = ScrolledText(master=self.root, height=30, width=80) self.text.config( background="#ffffff", foreground="#000000", highlightthickness=0, font=('courier', 11), ) self.text.grid(row=0, column=0, sticky=tkinter.NSEW) self.highlighting = TkTextHighlighting(self) self.highlight_currentline = TkTextHighlightCurrentLine(self) #self.auto_shift = True # use invert shift for letters? self.menubar = tkinter.Menu(self.root) filemenu = tkinter.Menu(self.menubar, tearoff=0) filemenu.add_command(label="Load", command=self.command_load_file) filemenu.add_command(label="Save", command=self.command_save_file) if self.standalone_run: filemenu.add_command(label="Exit", command=self.root.quit) self.menubar.add_cascade(label="File", menu=filemenu) editmenu = tkinter.Menu(self.menubar, tearoff=0) editmenu.add_command(label="renum", command=self.renumber_listing) editmenu.add_command(label="reformat", command=self.reformat_listing) editmenu.add_command(label="display tokens", command=self.debug_display_tokens) self.menubar.add_cascade(label="tools", menu=editmenu) # help menu helpmenu = tkinter.Menu(self.menubar, tearoff=0) # helpmenu.add_command(label="help", command=self.menu_event_help) # helpmenu.add_command(label="about", command=self.menu_event_about) self.menubar.add_cascade(label="help", menu=helpmenu) # startup directory for file open/save self.current_dir = os.path.abspath( os.path.join( os.path.dirname(dragonlib.__file__), "..", "BASIC examples", )) self.set_status_bar( ) # Create widget, add bindings and after_idle() update self.text.bind("<Key>", self.event_text_key) # self.text.bind("<space>", self.event_syntax_check) # display the menu self.root.config(menu=self.menubar) self.root.update()