Esempio n. 1
0
    def __init__(self):

        self.n=0

        # Set up master widget  

        self.root = Tk()
        self.root.title("FoxDot - Live Coding with Python and SuperCollider")
        self.root.columnconfigure(0, weight=1)
        self.root.rowconfigure(0, weight=2)
        self.root.protocol("WM_DELETE_WINDOW", self.kill )

        # Set FoxDot icon
        try:
            # Use .ico file by default
            self.root.iconbitmap(FOXDOT_ICON)
            
        except:

            # Use .gif if necessary
            self.root.tk.call('wm', 'iconphoto', self.root._w, PhotoImage(file=FOXDOT_ICON))

        # set font

        self.font = tkFont.Font(font=(self.default_font, 12), name="CodeFont")
        self.font.configure(**tkFont.nametofont("CodeFont").configure())

        # Create Y scrollbar

        self.Yscroll = Scrollbar(self.root)
        self.Yscroll.grid(row=0, column=1, sticky='nsew')

        # Create text box for code

        self.text = ThreadedText(self.root,
                                 padx=5, pady=5,
                                 bg=colour_map['background'],
                                 fg=colour_map['plaintext'],
                                 insertbackground="White",
                                 font = "CodeFont",
                                 yscrollcommand=self.Yscroll.set,
                                 width=120, height=20,
                                 maxundo=50 )

        self.text.grid(row=0, column=0, sticky="nsew")
        self.Yscroll.config(command=self.text.yview)
        self.text.focus_set()

        # Docstring prompt label

        self.prompt = TextPrompt(self.text)        

        # Key bindings
        
        self.text.bind("<Return>",          self.newline)
        self.text.bind("<BackSpace>",       self.delete)
        self.text.bind("<Delete>",          self.delete2)
        self.text.bind("<Tab>",             self.tab)
        self.text.bind("<Key>",             self.keypress)
        
        # Use command key on Mac (Temporary)
        
        ctrl = "Command" if SYSTEM == MAC_OS else "Control"
            
        self.text.bind("<{}-Return>".format(ctrl),          self.exec_block)
        self.text.bind("<Alt-Return>",                      self.exec_line)
        self.text.bind("<Alt_L>",                           lambda event: "break")
        self.text.bind("<{}-a>".format(ctrl),               self.selectall)
        self.text.bind("<{}-period>".format(ctrl),          self.killall)
        self.text.bind("<{}-v>".format(ctrl),               self.paste)
        self.text.bind("<{}-bracketright>".format(ctrl),    self.indent)
        self.text.bind("<{}-bracketleft>".format(ctrl),     self.unindent)
        self.text.bind("<{}-equal>".format(ctrl),           self.zoom_in)
        self.text.bind("<{}-minus>".format(ctrl),           self.zoom_out)
        self.text.bind("<{}-z>".format(ctrl),               self.undo)
        self.text.bind("<{}-s>".format(ctrl),               self.save)
        self.text.bind("<{}-o>".format(ctrl),               self.openfile)

        # Change ctrl+h on Mac (is used to close)

        if SYSTEM == MAC_OS:
                       
            self.text.bind("<{}-k>".format(ctrl), self.help)
            self.help_key = "K"

        else:

            self.text.bind("<{}-h>".format(ctrl), self.help)
            self.help_key = "H"

        # Toggle console button keybind

        try:
            
            self.text.bind("<{}-#>".format(ctrl), self.toggle_console)
            self.toggle_key = "#"
            
        except:
            
            self.text.bind("<{}-t>".format(ctrl), self.toggle_console)
            self.toggle_key = "T" 

        # Save feature variabes

        self.saved    = False
        self.file     = None
        self.filename = None

        self.bracketHandler = BracketHandler(self)

        # Set tag names and config for specific colours

        for tier in tag_weights:

            for tag_name in tier:

                self.text.tag_config(tag_name, foreground=colour_map[tag_name])

        # Create undo-stack

        self.undo_stack = UndoStack(self.text)

        # Create lable for console

        self.console = console(self.root, self.default_font)
        self.console_visible = True
        sys.stdout = self.console

        # Store original location of cursor
        self.origin = "origin"
        self.text.mark_set(self.origin, INSERT)
        self.text.mark_gravity(self.origin, LEFT)

        # Say Hello to the user

        print "Welcome to FoxDot! Press Ctrl+{} for help.".format(self.help_key)
        print "-----------------------------------------"
Esempio n. 2
0
File: Editor.py Progetto: lvm/FoxDot
    def __init__(self, CodeClass):

        # Configure FoxDot's namespace to include the editor

        CodeClass.namespace['FoxDot'] = self
        #CodeClass.namespace['Player'].widget = self
        #CodeClass.namespace['Ghost'].widget = self

        # Used for docstring prompt

        self.namespace = CodeClass.namespace

        # Set up master widget

        self.root = Tk()
        self.root.title("FoxDot - Live Coding with Python and SuperCollider")
        self.root.columnconfigure(1, weight=1)
        self.root.rowconfigure(0, weight=1)
        self.root.rowconfigure(1, weight=0)
        self.root.grid_columnconfigure(0, weight=0)
        self.root.protocol("WM_DELETE_WINDOW", self.kill)

        # --- Set icon

        try:

            # Use .ico file by default
            self.root.iconbitmap(FOXDOT_ICON)

        except:

            # Use .gif if necessary
            self.root.tk.call('wm', 'iconphoto', self.root._w,
                              PhotoImage(file=FOXDOT_ICON))

        # --- Setup font

        if self.default_font not in tkFont.families():

            if SYSTEM == WINDOWS:

                self.default_font = "Consolas"

            elif SYSTEM == MAC_OS:

                self.default_font = "Monaco"

            else:

                self.default_font = "Courier New"

        self.font = tkFont.Font(font=(self.default_font, 12), name="CodeFont")
        self.font.configure(family=self.default_font)

        # --- start create menu

        self.menu = MenuBar(self, visible=True)

        # End menu setup ---

        # --- init main text box

        # Create y-axis scrollbar

        self.y_scroll = Scrollbar(self.root)
        self.y_scroll.grid(row=0, column=2, sticky='nsew')

        # Create text box for code

        self.text = ThreadedText(self.root,
                                 padx=5,
                                 pady=5,
                                 bg=colour_map['background'],
                                 fg=colour_map['plaintext'],
                                 insertbackground="White",
                                 font="CodeFont",
                                 yscrollcommand=self.y_scroll.set,
                                 width=100,
                                 height=20,
                                 bd=0,
                                 undo=True,
                                 autoseparators=True,
                                 maxundo=50)

        self.text.grid(row=0, column=1, sticky="nsew")
        self.y_scroll.config(command=self.text.yview)
        self.text.focus_set()

        # Create box for line numbers

        self.linenumbers = LineNumbers(self.text,
                                       width=25,
                                       bg=colour_map['background'],
                                       bd=0,
                                       highlightthickness=0)

        self.linenumbers.grid(row=0, column=0, sticky='nsew')

        # Docstring prompt label

        self.prompt = TextPrompt(self.text)

        # Key bindings

        self.text.bind("<Return>", self.newline)
        self.text.bind("<BackSpace>", self.delete)
        self.text.bind("<Delete>", self.delete2)
        self.text.bind("<Tab>", self.tab)
        self.text.bind("<Key>", self.keypress)

        # Use command key on Mac (Temporary)

        ctrl = "Command" if SYSTEM == MAC_OS else "Control"

        self.text.bind("<{}-Return>".format(ctrl), self.exec_block)
        self.text.bind("<Alt-Return>", self.exec_line)
        self.text.bind("<Alt_L>", lambda event: "break")
        self.text.bind("<{}-a>".format(ctrl), self.selectall)
        self.text.bind("<{}-period>".format(ctrl), self.killall)
        self.text.bind("<Alt-period>".format(ctrl), self.releaseNodes)
        self.text.bind("<{}-v>".format(ctrl), self.edit_paste)
        self.text.bind("<{}-bracketright>".format(ctrl), self.indent)
        self.text.bind("<{}-bracketleft>".format(ctrl), self.unindent)
        self.text.bind("<{}-equal>".format(ctrl), self.zoom_in)
        self.text.bind("<{}-minus>".format(ctrl), self.zoom_out)
        self.text.bind("<{}-z>".format(ctrl), self.undo)
        self.text.bind("<{}-y>".format(ctrl), self.redo)
        self.text.bind("<{}-s>".format(ctrl), self.save)
        self.text.bind("<{}-o>".format(ctrl), self.openfile)
        self.text.bind("<{}-n>".format(ctrl), self.newfile)
        self.text.bind("<{}-m>".format(ctrl), self.toggle_menu)

        # Change ctrl+h on Mac (is used to close)

        if SYSTEM == MAC_OS:

            self.text.bind("<{}-k>".format(ctrl), self.help)
            self.help_key = "K"

        else:

            self.text.bind("<{}-h>".format(ctrl), self.help)
            self.help_key = "H"

        # Toggle console button keybind

        try:

            self.text.bind("<{}-#>".format(ctrl), self.toggle_console)
            self.toggle_key = "#"

        except:

            self.text.bind("<{}-t>".format(ctrl), self.toggle_console)
            self.toggle_key = "T"

        # Save feature variabes

        self.saved = False
        self.file = None
        self.filename = None

        # --- define bracket behaviour

        self.bracketHandler = BracketHandler(self)

        # Set tag names and config for specific colours

        for tier in tag_weights:

            for tag_name in tier:

                self.text.tag_config(tag_name, foreground=colour_map[tag_name])

        # --- Create console

        self.console = console(self.root, self.default_font)
        self.console_visible = True
        sys.stdout = self.console

        # Store original location of cursor
        self.origin = "origin"
        self.text.mark_set(self.origin, INSERT)
        self.text.mark_gravity(self.origin, LEFT)

        # Say Hello to the user

        print "Welcome to FoxDot! Press Ctrl+{} for help.".format(
            self.help_key)
        print "-----------------------------------------"
Esempio n. 3
0
    def __init__(self):

        # Set up master widget

        self.root = Tk()
        self.root.title("FoxDot - Live Coding with Python and SuperCollider")
        self.root.columnconfigure(0, weight=1)
        self.root.rowconfigure(0, weight=2)
        self.root.protocol("WM_DELETE_WINDOW", self.kill)
        self.root.iconbitmap(FOXDOT_ICON)

        # Set font

        if self.default_font not in tkFont.families():

            self.default_font = 'Courier New'

        self.font = tkFont.Font(font=(self.default_font, 12), name="CodeFont")
        self.font.configure(**tkFont.nametofont("CodeFont").configure())

        # Create Y scrollbar

        self.Yscroll = Scrollbar(self.root)
        self.Yscroll.grid(row=0, column=1, sticky='nsew')

        # Create text box for code

        self.text = Text(self.root,
                         padx=5,
                         pady=5,
                         bg=colour_map['background'],
                         fg=colour_map['plaintext'],
                         insertbackground="White",
                         font="CodeFont",
                         yscrollcommand=self.Yscroll.set,
                         width=120,
                         height=20)

        self.text.grid(row=0, column=0, sticky="nsew")
        self.Yscroll.config(command=self.text.yview)
        self.text.focus_set()

        # Docstring prompt label

        self.prompt = StringVar()
        self.promptlbl = Label(self.text, textvariable=self.prompt)
        self.promptlbl.place(x=9999, y=9999)
        self.last_word = ""
        self.prompt.set("")

        # Key bindings

        self.text.bind("<Return>", self.newline)
        self.text.bind("<BackSpace>", self.delete)
        self.text.bind("<Delete>", self.delete2)
        self.text.bind("<Tab>", self.tab)
        self.text.bind("<Key>", self.keypress)

        # Use command key on Mac (Temporary)

        ctrl = "Command" if SYSTEM == MAC_OS else "Control"

        self.text.bind("<{}-Return>".format(ctrl), self.get_code)
        self.text.bind("<{}-a>".format(ctrl), self.selectall)
        self.text.bind("<{}-period>".format(ctrl), self.killall)
        self.text.bind("<{}-v>".format(ctrl), self.paste)
        self.text.bind("<{}-bracketright>".format(ctrl), self.indent)
        self.text.bind("<{}-bracketleft>".format(ctrl), self.unindent)
        self.text.bind("<{}-equal>".format(ctrl), self.zoom_in)
        self.text.bind("<{}-minus>".format(ctrl), self.zoom_out)
        self.text.bind("<{}-z>".format(ctrl), self.undo)
        self.text.bind("<{}-s>".format(ctrl), self.save)
        self.text.bind("<{}-o>".format(ctrl), self.openfile)

        # Change ctrl+h on Mac (is used to close)

        if SYSTEM == MAC_OS:

            self.text.bind("<{}-k>".format(ctrl), self.help)
            self.help_key = "K"

        else:

            self.text.bind("<{}-h>".format(ctrl), self.help)
            self.help_key = "H"

        # Toggle console button keybind

        try:

            self.text.bind("<{}-#>".format(ctrl), self.toggle_console)
            self.toggle_key = "#"

        except:

            self.text.bind("<{}-t>".format(ctrl), self.toggle_console)
            self.toggle_key = "T"

        # Save feature variabes

        self.saved = False
        self.file = None
        self.filename = None

        # Automatic brackets

        self.inbrackets = False
        self.separators = py_separators
        self.left_brackets = left_b
        self.right_brackets = right_b
        self.all_brackets = dict(zip(self.left_brackets, self.right_brackets))
        self.bracket_q = []
        for char in self.left_brackets + self.right_brackets:
            self.text.bind(char, self.brackets)

        # Set tag names and config for specific colours

        for tier in tag_weights:

            for tag_name in tier:

                self.text.tag_config(tag_name, foreground=colour_map[tag_name])

        # Create undo-stack

        self.undo_stack = UndoStack(self.text)

        # Create lable for console

        self.console = console(self.root, self.default_font)
        self.console_visible = True
        sys.stdout = self.console

        # Say Hello to the user

        print "Welcome to FoxDot! Press Ctrl+{} for help.".format(
            self.help_key)
        print "-----------------------------------------"