Exemplo n.º 1
0
 def drawtext(self):
     textx = self.x+20-1
     texty = self.y-1
     labeltext = self.item.GetLabelText()
     if labeltext:
         id = self.canvas.create_text(textx, texty, anchor="nw",
                                      text=labeltext)
         self.canvas.tag_bind(id, "<1>", self.select)
         self.canvas.tag_bind(id, "<Double-1>", self.flip)
         x0, y0, x1, y1 = self.canvas.bbox(id)
         textx = max(x1, 200) + 10
     text = self.item.GetText() or "<no text>"
     try:
         self.entry
     except AttributeError:
         pass
     else:
         self.edit_finish()
     try:
         label = self.label
     except AttributeError:
         # padding carefully selected (on Windows) to match Entry widget:
         self.label = Label(self.canvas, text=text, bd=0, padx=2, pady=2)
     theme = idleConf.GetOption('main','Theme','name')
     if self.selected:
         self.label.configure(idleConf.GetHighlight(theme, 'hilite'))
     else:
         self.label.configure(idleConf.GetHighlight(theme, 'normal'))
     id = self.canvas.create_window(textx, texty,
                                    anchor="nw", window=self.label)
     self.label.bind("<1>", self.select_or_edit)
     self.label.bind("<Double-1>", self.flip)
     self.text_id = id
Exemplo n.º 2
0
 def LoadTagDefs(self):
     ColorDelegator.LoadTagDefs(self)
     theme = idleConf.GetOption('main', 'Theme', 'name')
     self.tagdefs.update({
         "stdin": {
             'background': None,
             'foreground': None
         },
         "stdout": idleConf.GetHighlight(theme, "stdout"),
         "stderr": idleConf.GetHighlight(theme, "stderr"),
         "console": idleConf.GetHighlight(theme, "console"),
     })
Exemplo n.º 3
0
    def reset_colorizer(self):
        "Update the colour theme"
        # Called from self.filename_change_hook and from configDialog.py
        self.__rmcolorizer()
        self.__addcolorizer()
        theme = idleConf.GetOption('main', 'Theme', 'name')
        normal_colors = idleConf.GetHighlight(theme, 'normal')
        cursor_color = idleConf.GetHighlight(theme, 'cursor', fgBg='fg')
        select_colors = idleConf.GetHighlight(theme, 'hilite')

        self.text.config(foreground=normal_colors['foreground'],
                         background=normal_colors['background'],
                         insertbackground=cursor_color,
                         selectforeground=select_colors['foreground'],
                         selectbackground=select_colors['background'])
Exemplo n.º 4
0
 def showcontents(self):
     listbox = Listbox(self.tipwindow,
                       background=idleConf.GetHighlight(
                           theme, 'tooltip', 'bg'))
     listbox.pack()
     for item in self.items:
         listbox.insert(END, item)
Exemplo n.º 5
0
 def init(self, flist):
     self.flist = flist
     # reset pyclbr
     pyclbr._modules.clear()
     # create top
     self.top = top = ListedToplevel(flist.root)
     top.protocol("WM_DELETE_WINDOW", self.close)
     top.bind("<Escape>", self.close)
     if self._htest:  # place dialog below parent if running htest
         top.geometry(
             "+%d+%d" %
             (flist.root.winfo_rootx(), flist.root.winfo_rooty() + 200))
     self.settitle()
     top.focus_set()
     # create scrolled canvas
     theme = idleConf.CurrentTheme()
     background = idleConf.GetHighlight(theme, 'normal')['background']
     sc = ScrolledCanvas(top,
                         bg=background,
                         highlightthickness=0,
                         takefocus=1)
     sc.frame.pack(expand=1, fill="both")
     item = self.rootnode()
     self.node = node = TreeNode(sc.canvas, None, item)
     node.update()
     node.expand()
Exemplo n.º 6
0
 def showcontents(self, text="Your text here"):
     # Override this in derived class
     label = Label(self.tipwindow,
                   text=text,
                   justify=LEFT,
                   background=idleConf.GetHighlight(theme, 'tooltip', 'bg'),
                   relief=SOLID,
                   borderwidth=1)
     label.pack()
Exemplo n.º 7
0
    def _selection_changed(self):
        """Should be called when the selection of the Listbox has changed.
        Updates the Listbox display and calls _change_start."""
        cursel = int(self.listbox.curselection()[0])

        self.listbox.see(cursel)

        lts = self.lasttypedstart
        selstart = self.completions[cursel]
        if self._binary_search(lts) == cursel:
            newstart = lts
        else:
            min_len = min(len(lts), len(selstart))
            i = 0
            while i < min_len and lts[i] == selstart[i]:
                i += 1
            newstart = selstart[:i]
        self._change_start(newstart)

        # We want to show the small list if the typed text was found in it, or
        # if it was found within some completion and we're showing only containing completions.
        if (self.completions[cursel][:len(self.start)] == self.start or
            (self.onlycontaining
             and self.start.lower() in self.completions[cursel].lower())):
            # start is a prefix of the selected completion
            self.listbox.configure(
                selectbackground=idleConf.GetHighlight(theme, 'acselect',
                                                       'bg'),
                selectforeground=idleConf.GetHighlight(theme, 'acselect',
                                                       'fg'),
                background=idleConf.GetHighlight(theme, 'autocomplete', 'bg'),
                foreground=idleConf.GetHighlight(theme, 'autocomplete', 'fg'))
        else:
            self.listbox.configure(
                selectbackground=idleConf.GetHighlight(theme, 'acselect',
                                                       'bg'),
                selectforeground=idleConf.GetHighlight(theme, 'acselect',
                                                       'fg'),
                background=idleConf.GetHighlight(theme, 'autocomplete', 'bg'),
                foreground=idleConf.GetHighlight(theme, 'autocomplete', 'fg'))
            # If there are more completions, show them, and call me again.
            if self.morecompletions:
                # When moving on to the big list, forget about showing only containing completions.
                self.onlycontaining = False
                self.completions = self.morecompletions
                self.morecompletions = None
                self.listbox.delete(0, END)
                for item in self.completions:
                    self.listbox.insert(END, item)
                self.listbox.select_set(self._binary_search(self.start))
                self._selection_changed()
Exemplo n.º 8
0
 def remote_stack_viewer(self):
     import RemoteObjectBrowser
     oid = self.rpcclt.remotequeue("exec", "stackviewer", ("flist", ), {})
     if oid is None:
         self.tkconsole.root.bell()
         return
     item = RemoteObjectBrowser.StubObjectTreeItem(self.rpcclt, oid)
     from TreeWidget import ScrolledCanvas, TreeNode
     top = Toplevel(self.tkconsole.root)
     theme = idleConf.GetOption('main', 'Theme', 'name')
     background = idleConf.GetHighlight(theme, 'normal')['background']
     sc = ScrolledCanvas(top, bg=background, highlightthickness=0)
     sc.frame.pack(expand=1, fill="both")
     node = TreeNode(sc.canvas, None, item)
     node.expand()
Exemplo n.º 9
0
    def LoadTagDefs(self):
        theme = idleConf.GetOption('main','Theme','name')
        self.tagdefs = {
            "COMMENT": idleConf.GetHighlight(theme, "comment"),
            "KEYWORD": idleConf.GetHighlight(theme, "keyword"),
            "BUILTIN": idleConf.GetHighlight(theme, "builtin"),
            "STRING": idleConf.GetHighlight(theme, "string"),
            "DEFINITION": idleConf.GetHighlight(theme, "definition"),
            "SYNC": {'background':None,'foreground':None},
            "TODO": {'background':None,'foreground':None},
            "BREAK": idleConf.GetHighlight(theme, "break"),
            "ERROR": idleConf.GetHighlight(theme, "error"),
            # The following is used by ReplaceDialog:
            "hit": idleConf.GetHighlight(theme, "hit"),
            }

        if DEBUG: print 'tagdefs',self.tagdefs
Exemplo n.º 10
0
    def __init__(self, top):
        currentTheme = idleConf.CurrentTheme()
        self.history_frame = Frame(top, height=1)
        self.top = top
        fg = idleConf.GetHighlight(currentTheme, 'normal', fgBg='fg')
        bg = idleConf.GetHighlight(currentTheme, 'normal', fgBg='bg')
        self.lst = Listbox(self.history_frame,
                           foreground=fg,
                           background=bg,
                           height=5,
                           selectmode=EXTENDED,
                           exportselection=False)
        self.scroll = Scrollbar(self.history_frame, command=self.lst.yview)

        self.lst['yscrollcommand'] = self.scroll.set
        self.lst.bind('<ButtonRelease-1>', self.click)

        #self.search_box_text = Variable()
        #self.search_box_text.trace('w', self.search_text_changed)
        #self.search_box = Entry(self.history_frame,
        #    foreground=fg, background=bg,
        #    textvariable=self.search_box_text)
        self.history_frame.pack(side=TOP, fill=X)
        self.is_shown = False
Exemplo n.º 11
0
 def init(self, flist):
     self.flist = flist
     # reset pyclbr
     pyclbr._modules.clear()
     # create top
     self.top = top = ListedToplevel(flist.root)
     top.protocol("WM_DELETE_WINDOW", self.close)
     top.bind("<Escape>", self.close)
     self.settitle()
     top.focus_set()
     # create scrolled canvas
     theme = idleConf.GetOption('main','Theme','name')
     background = idleConf.GetHighlight(theme, 'normal')['background']
     sc = ScrolledCanvas(top, bg=background, highlightthickness=0, takefocus=1)
     sc.frame.pack(expand=1, fill="both")
     item = self.rootnode()
     self.node = node = TreeNode(sc.canvas, None, item)
     node.update()
     node.expand()
Exemplo n.º 12
0
class ParenMatch:
    """Highlight matching parentheses

    There are three supported style of paren matching, based loosely
    on the Emacs options.  The style is select based on the
    HILITE_STYLE attribute; it can be changed used the set_style
    method.

    The supported styles are:

    default -- When a right paren is typed, highlight the matching
        left paren for 1/2 sec.

    expression -- When a right paren is typed, highlight the entire
        expression from the left paren to the right paren.

    TODO:
        - extend IDLE with configuration dialog to change options
        - implement rest of Emacs highlight styles (see below)
        - print mismatch warning in IDLE status window

    Note: In Emacs, there are several styles of highlight where the
    matching paren is highlighted whenever the cursor is immediately
    to the right of a right paren.  I don't know how to do that in Tk,
    so I haven't bothered.
    """
    menudefs = [('edit', [
        ("Show surrounding parens", "<<flash-paren>>"),
    ])]
    STYLE = idleConf.GetOption('extensions',
                               'ParenMatch',
                               'style',
                               default='expression')
    FLASH_DELAY = idleConf.GetOption('extensions',
                                     'ParenMatch',
                                     'flash-delay',
                                     type='int',
                                     default=500)
    HILITE_CONFIG = idleConf.GetHighlight(idleConf.CurrentTheme(), 'hilite')
    BELL = idleConf.GetOption('extensions',
                              'ParenMatch',
                              'bell',
                              type='bool',
                              default=1)

    RESTORE_VIRTUAL_EVENT_NAME = "<<parenmatch-check-restore>>"
    # We want the restore event be called before the usual return and
    # backspace events.
    RESTORE_SEQUENCES = ("<KeyPress>", "<ButtonPress>", "<Key-Return>",
                         "<Key-BackSpace>")

    def __init__(self, editwin):
        self.editwin = editwin
        self.text = editwin.text
        # Bind the check-restore event to the function restore_event,
        # so that we can then use activate_restore (which calls event_add)
        # and deactivate_restore (which calls event_delete).
        editwin.text.bind(self.RESTORE_VIRTUAL_EVENT_NAME, self.restore_event)
        self.counter = 0
        self.is_restore_active = 0
        self.set_style(self.STYLE)

    def activate_restore(self):
        if not self.is_restore_active:
            for seq in self.RESTORE_SEQUENCES:
                self.text.event_add(self.RESTORE_VIRTUAL_EVENT_NAME, seq)
            self.is_restore_active = True

    def deactivate_restore(self):
        if self.is_restore_active:
            for seq in self.RESTORE_SEQUENCES:
                self.text.event_delete(self.RESTORE_VIRTUAL_EVENT_NAME, seq)
            self.is_restore_active = False

    def set_style(self, style):
        self.STYLE = style
        if style == "default":
            self.create_tag = self.create_tag_default
            self.set_timeout = self.set_timeout_last
        elif style == "expression":
            self.create_tag = self.create_tag_expression
            self.set_timeout = self.set_timeout_none

    def flash_paren_event(self, event):
        indices = HyperParser(self.editwin,
                              "insert").get_surrounding_brackets()
        if indices is None:
            self.warn_mismatched()
            return
        self.activate_restore()
        self.create_tag(indices)
        self.set_timeout_last()

    def paren_closed_event(self, event):
        # If it was a shortcut and not really a closing paren, quit.
        closer = self.text.get("insert-1c")
        if closer not in _openers:
            return
        hp = HyperParser(self.editwin, "insert-1c")
        if not hp.is_in_code():
            return
        indices = hp.get_surrounding_brackets(_openers[closer], True)
        if indices is None:
            self.warn_mismatched()
            return
        self.activate_restore()
        self.create_tag(indices)
        self.set_timeout()

    def restore_event(self, event=None):
        self.text.tag_delete("paren")
        self.deactivate_restore()
        self.counter += 1  # disable the last timer, if there is one.

    def handle_restore_timer(self, timer_count):
        if timer_count == self.counter:
            self.restore_event()

    def warn_mismatched(self):
        if self.BELL:
            self.text.bell()

    # any one of the create_tag_XXX methods can be used depending on
    # the style

    def create_tag_default(self, indices):
        """Highlight the single paren that matches"""
        self.text.tag_add("paren", indices[0])
        self.text.tag_config("paren", self.HILITE_CONFIG)

    def create_tag_expression(self, indices):
        """Highlight the entire expression"""
        if self.text.get(indices[1]) in (')', ']', '}'):
            rightindex = indices[1] + "+1c"
        else:
            rightindex = indices[1]
        self.text.tag_add("paren", indices[0], rightindex)
        self.text.tag_config("paren", self.HILITE_CONFIG)

    # any one of the set_timeout_XXX methods can be used depending on
    # the style

    def set_timeout_none(self):
        """Highlight will remain until user input turns it off
        or the insert has moved"""
        # After CHECK_DELAY, call a function which disables the "paren" tag
        # if the event is for the most recent timer and the insert has changed,
        # or schedules another call for itself.
        self.counter += 1

        def callme(callme,
                   self=self,
                   c=self.counter,
                   index=self.text.index("insert")):
            if index != self.text.index("insert"):
                self.handle_restore_timer(c)
            else:
                self.editwin.text_frame.after(CHECK_DELAY, callme, callme)

        self.editwin.text_frame.after(CHECK_DELAY, callme, callme)

    def set_timeout_last(self):
        """The last highlight created will be removed after .5 sec"""
        # associate a counter with an event; only disable the "paren"
        # tag if the event is for the most recent timer.
        self.counter += 1
        self.editwin.text_frame.after(self.FLASH_DELAY,
                                      lambda self=self, c=self.counter: \
                                      self.handle_restore_timer(c))
Exemplo n.º 13
0
class ParenMatch:
    """Highlight matching parentheses

    There are three supported style of paren matching, based loosely
    on the Emacs options.  The style is select based on the
    HILITE_STYLE attribute; it can be changed used the set_style
    method.

    The supported styles are:

    default -- When a right paren is typed, highlight the matching
        left paren for 1/2 sec.

    expression -- When a right paren is typed, highlight the entire
        expression from the left paren to the right paren.

    TODO:
        - fix interaction with CallTips
        - extend IDLE with configuration dialog to change options
        - implement rest of Emacs highlight styles (see below)
        - print mismatch warning in IDLE status window

    Note: In Emacs, there are several styles of highlight where the
    matching paren is highlighted whenever the cursor is immediately
    to the right of a right paren.  I don't know how to do that in Tk,
    so I haven't bothered.
    """
    menudefs = []
    STYLE = idleConf.GetOption('extensions','ParenMatch','style',
            default='expression')
    FLASH_DELAY = idleConf.GetOption('extensions','ParenMatch','flash-delay',
            type='int',default=500)
    HILITE_CONFIG = idleConf.GetHighlight(idleConf.CurrentTheme(),'hilite')
    BELL = idleConf.GetOption('extensions','ParenMatch','bell',
            type='bool',default=1)

    def __init__(self, editwin):
        self.editwin = editwin
        self.text = editwin.text
        self.finder = LastOpenBracketFinder(editwin)
        self.counter = 0
        self._restore = None
        self.set_style(self.STYLE)

    def set_style(self, style):
        self.STYLE = style
        if style == "default":
            self.create_tag = self.create_tag_default
            self.set_timeout = self.set_timeout_last
        elif style == "expression":
            self.create_tag = self.create_tag_expression
            self.set_timeout = self.set_timeout_none

    def flash_open_paren_event(self, event):
        index = self.finder.find(keysym_type(event.keysym))
        if index is None:
            self.warn_mismatched()
            return
        self._restore = 1
        self.create_tag(index)
        self.set_timeout()

    def check_restore_event(self, event=None):
        if self._restore:
            self.text.tag_delete("paren")
            self._restore = None

    def handle_restore_timer(self, timer_count):
        if timer_count + 1 == self.counter:
            self.check_restore_event()

    def warn_mismatched(self):
        if self.BELL:
            self.text.bell()

    # any one of the create_tag_XXX methods can be used depending on
    # the style

    def create_tag_default(self, index):
        """Highlight the single paren that matches"""
        self.text.tag_add("paren", index)
        self.text.tag_config("paren", self.HILITE_CONFIG)

    def create_tag_expression(self, index):
        """Highlight the entire expression"""
        self.text.tag_add("paren", index, "insert")
        self.text.tag_config("paren", self.HILITE_CONFIG)

    # any one of the set_timeout_XXX methods can be used depending on
    # the style

    def set_timeout_none(self):
        """Highlight will remain until user input turns it off"""
        pass

    def set_timeout_last(self):
        """The last highlight created will be removed after .5 sec"""
        # associate a counter with an event; only disable the "paren"
        # tag if the event is for the most recent timer.
        self.editwin.text_frame.after(self.FLASH_DELAY,
                                      lambda self=self, c=self.counter: \
                                      self.handle_restore_timer(c))
        self.counter = self.counter + 1