示例#1
0
    def __init__(self, s, tags, numoflines, squeezer):
        self.s = s
        self.tags = tags
        self.numoflines = numoflines
        self.squeezer = squeezer
        self.editwin = editwin = squeezer.editwin
        self.text = text = editwin.text
        # The base Text widget is needed to change text before iomark.
        self.base_text = editwin.per.bottom

        line_plurality = "lines" if numoflines != 1 else "line"
        button_text = f"Squeezed text ({numoflines} {line_plurality})."
        tk.Button.__init__(self,
                           text,
                           text=button_text,
                           background="#FFFFC0",
                           activebackground="#FFFFE0")

        button_tooltip_text = (
            "Double-click to expand, right-click for more options.")
        Hovertip(self, button_tooltip_text, hover_delay=80)

        self.bind("<Double-Button-1>", self.expand)
        if macosx.isAquaTk():
            # AquaTk defines <2> as the right button, not <3>.
            self.bind("<Button-2>", self.context_menu_event)
        else:
            self.bind("<Button-3>", self.context_menu_event)
        self.selection_handle(  # X windows only.
            lambda offset, length: s[int(offset):int(offset) + int(length)])

        self.is_dangerous = None
        self.after_idle(self.set_is_dangerous)
示例#2
0
def zoom_height(top):
    geom = top.wm_geometry()
    m = re.match(r"(\d+)x(\d+)\+(-?\d+)\+(-?\d+)", geom)
    if not m:
        top.bell()
        return
    width, height, x, y = map(int, m.groups())
    newheight = top.winfo_screenheight()
    if sys.platform == 'win32':
        newy = 0
        newheight = newheight - 72

    elif macosx.isAquaTk():
        # The '88' below is a magic number that avoids placing the bottom
        # of the window below the panel on my machine. I don't know how
        # to calculate the correct value for this with tkinter.
        newy = 22
        newheight = newheight - newy - 88

    else:
        #newy = 24
        newy = 0
        #newheight = newheight - 96
        newheight = newheight - 88
    if height >= newheight:
        newgeom = ""
    else:
        newgeom = "%dx%d+%d+%d" % (width, newheight, x, newy)
    top.wm_geometry(newgeom)
示例#3
0
    def __init__(self, s, tags, numoflines, squeezer):
        self.s = s
        self.tags = tags
        self.numoflines = numoflines
        self.squeezer = squeezer
        self.editwin = editwin = squeezer.editwin
        self.text = text = editwin.text

        # the base Text widget of the PyShell object, used to change text
        # before the iomark
        self.base_text = editwin.per.bottom

        button_text = "Squeezed text (%d lines)." % self.numoflines
        tk.Button.__init__(self, text, text=button_text,
                           background="#FFFFC0", activebackground="#FFFFE0")

        button_tooltip_text = (
            "Double-click to expand, right-click for more options."
        )
        Hovertip(self, button_tooltip_text, hover_delay=80)

        self.bind("<Double-Button-1>", self.expand)
        if macosx.isAquaTk():
            # AquaTk defines <2> as the right button, not <3>.
            self.bind("<Button-2>", self.context_menu_event)
        else:
            self.bind("<Button-3>", self.context_menu_event)
        self.selection_handle(
            lambda offset, length: s[int(offset):int(offset) + int(length)])

        self.is_dangerous = None
        self.after_idle(self.set_is_dangerous)
示例#4
0
def zoom_height(top):
    geom = top.wm_geometry()
    m = re.match(r"(\d+)x(\d+)\+(-?\d+)\+(-?\d+)", geom)
    if not m:
        top.bell()
        return
    width, height, x, y = map(int, m.groups())
    newheight = top.winfo_screenheight()
    if sys.platform == 'win32':
        newy = 0
        newheight = newheight - 72

    elif macosx.isAquaTk():
        # The '88' below is a magic number that avoids placing the bottom
        # of the window below the panel on my machine. I don't know how
        # to calculate the correct value for this with tkinter.
        newy = 22
        newheight = newheight - newy - 88

    else:
        #newy = 24
        newy = 0
        #newheight = newheight - 96
        newheight = newheight - 88
    if height >= newheight:
        newgeom = ""
    else:
        newgeom = "%dx%d+%d+%d" % (width, newheight, x, newy)
    top.wm_geometry(newgeom)
示例#5
0
    def __init__(self, s, tags, numoflines, squeezer):
        self.s = s
        self.tags = tags
        self.numoflines = numoflines
        self.squeezer = squeezer
        self.editwin = editwin = squeezer.editwin
        self.text = text = editwin.text
        # The base Text widget is needed to change text before iomark.
        self.base_text = editwin.per.bottom

        line_plurality = "lines" if numoflines != 1 else "line"
        button_text = f"Squeezed text ({numoflines} {line_plurality})."
        tk.Button.__init__(self, text, text=button_text,
                           background="#FFFFC0", activebackground="#FFFFE0")

        button_tooltip_text = (
            "Double-click to expand, right-click for more options."
        )
        Hovertip(self, button_tooltip_text, hover_delay=80)

        self.bind("<Double-Button-1>", self.expand)
        if macosx.isAquaTk():
            # AquaTk defines <2> as the right button, not <3>.
            self.bind("<Button-2>", self.context_menu_event)
        else:
            self.bind("<Button-3>", self.context_menu_event)
        self.selection_handle(  # X windows only.
            lambda offset, length: s[int(offset):int(offset) + int(length)])

        self.is_dangerous = None
        self.after_idle(self.set_is_dangerous)
示例#6
0
    def test_init(self, MockHovertip):
        """Test the simplest creation of an ExpandingButton."""
        squeezer = self.make_mock_squeezer()
        text_widget = squeezer.editwin.text

        expandingbutton = ExpandingButton('TEXT', 'TAGS', 50, squeezer)
        self.assertEqual(expandingbutton.s, 'TEXT')

        # check that the underlying tkinter.Button is properly configured
        self.assertEqual(expandingbutton.master, text_widget)
        self.assertTrue('50 lines' in expandingbutton.cget('text'))

        # check that the text widget still contains no text
        self.assertEqual(text_widget.get('1.0', 'end'), '\n')

        # check that the mouse events are bound
        self.assertIn('<Double-Button-1>', expandingbutton.bind())
        right_button_code = '<Button-%s>' % ('2' if macosx.isAquaTk() else '3')
        self.assertIn(right_button_code, expandingbutton.bind())

        # check that ToolTip was called once, with appropriate values
        self.assertEqual(MockHovertip.call_count, 1)
        MockHovertip.assert_called_with(expandingbutton, ANY, hover_delay=ANY)

        # check that 'right-click' appears in the tooltip text
        tooltip_text = MockHovertip.call_args[0][1]
        self.assertIn('right-click', tooltip_text.lower())
示例#7
0
文件: squeezer.py 项目: iYassr/Share
    def __init__(self, s, tags, numoflines, squeezer):
        self.s = s
        self.tags = tags
        self.numoflines = numoflines
        self.squeezer = squeezer
        self.editwin = editwin = squeezer.editwin
        self.text = text = editwin.text

        # the base Text widget of the PyShell object, used to change text
        # before the iomark
        self.base_text = editwin.per.bottom

        button_text = "Squeezed text (%d lines)." % self.numoflines
        tk.Button.__init__(self,
                           text,
                           text=button_text,
                           background="#FFFFC0",
                           activebackground="#FFFFE0")

        button_tooltip_text = (
            "Double-click to expand, right-click for more options.")
        Hovertip(self, button_tooltip_text, hover_delay=80)

        self.bind("<Double-Button-1>", self.expand)
        if macosx.isAquaTk():
            # AquaTk defines <2> as the right button, not <3>.
            self.bind("<Button-2>", self.context_menu_event)
        else:
            self.bind("<Button-3>", self.context_menu_event)
        self.selection_handle(
            lambda offset, length: s[int(offset):int(offset) + int(length)])

        self.is_dangerous = None
        self.after_idle(self.set_is_dangerous)
示例#8
0
 def __init__(self, master, **options):
     # Create top frame, with scrollbar and listbox
     self.master = master
     self.frame = frame = Frame(master)
     self.frame.pack(fill="both", expand=1)
     self.vbar = vbar = Scrollbar(frame, name="vbar")
     self.vbar.pack(side="right", fill="y")
     self.listbox = listbox = Listbox(frame, exportselection=0,
         background="white")
     if options:
         listbox.configure(options)
     listbox.pack(expand=1, fill="both")
     # Tie listbox and scrollbar together
     vbar["command"] = listbox.yview
     listbox["yscrollcommand"] = vbar.set
     # Bind events to the list box
     listbox.bind("<ButtonRelease-1>", self.click_event)
     listbox.bind("<Double-ButtonRelease-1>", self.double_click_event)
     if macosx.isAquaTk():
         listbox.bind("<ButtonPress-2>", self.popup_event)
         listbox.bind("<Control-Button-1>", self.popup_event)
     else:
         listbox.bind("<ButtonPress-3>", self.popup_event)
     listbox.bind("<Key-Up>", self.up_event)
     listbox.bind("<Key-Down>", self.down_event)
     # Mark as empty
     self.clear()
示例#9
0
    def test_init(self, MockHovertip):
        """Test the simplest creation of an ExpandingButton."""
        squeezer = self.make_mock_squeezer()
        text_widget = squeezer.editwin.text

        expandingbutton = ExpandingButton('TEXT', 'TAGS', 50, squeezer)
        self.assertEqual(expandingbutton.s, 'TEXT')

        # Check that the underlying tkinter.Button is properly configured.
        self.assertEqual(expandingbutton.master, text_widget)
        self.assertTrue('50 lines' in expandingbutton.cget('text'))

        # Check that the text widget still contains no text.
        self.assertEqual(text_widget.get('1.0', 'end'), '\n')

        # Check that the mouse events are bound.
        self.assertIn('<Double-Button-1>', expandingbutton.bind())
        right_button_code = '<Button-%s>' % ('2' if macosx.isAquaTk() else '3')
        self.assertIn(right_button_code, expandingbutton.bind())

        # Check that ToolTip was called once, with appropriate values.
        self.assertEqual(MockHovertip.call_count, 1)
        MockHovertip.assert_called_with(expandingbutton, ANY, hover_delay=ANY)

        # Check that 'right-click' appears in the tooltip text.
        tooltip_text = MockHovertip.call_args[0][1]
        self.assertIn('right-click', tooltip_text.lower())
示例#10
0
    def bind_events(self):
        super().bind_events()

        self.main_widget.bind(
            # AquaTk defines <2> as the right button, not <3>.
            "<Button-2>" if macosx.isAquaTk() else "<Button-3>",
            self.context_menu_event,
        )
示例#11
0
 def __init__(self, master, flist, gui):
     if macosx.isAquaTk():
         ScrolledList.__init__(self, master)
     else:
         ScrolledList.__init__(self, master, width=80)
     self.flist = flist
     self.gui = gui
     self.stack = []
示例#12
0
 def __init__(self, master, flist, gui):
     if macosx.isAquaTk():
         # At least on with the stock AquaTk version on OSX 10.4 you'll
         # get a shaking GUI that eventually kills IDLE if the width
         # argument is specified.
         ScrolledList.__init__(self, master)
     else:
         ScrolledList.__init__(self, master, width=80)
     self.flist = flist
     self.gui = gui
     self.stack = []
示例#13
0
文件: debugger.py 项目: JSMSC/cpython
 def __init__(self, master, flist, gui):
     if macosx.isAquaTk():
         # At least on with the stock AquaTk version on OSX 10.4 you'll
         # get a shaking GUI that eventually kills IDLE if the width
         # argument is specified.
         ScrolledList.__init__(self, master)
     else:
         ScrolledList.__init__(self, master, width=80)
     self.flist = flist
     self.gui = gui
     self.stack = []
示例#14
0
def zoom_height(top):
    geom = top.wm_geometry()
    m = re.match(r"(\d+)x(\d+)\+(-?\d+)\+(-?\d+)", geom)
    if not m:
        top.bell()
        return
    width, height, x, y = map(int, m.groups())
    newheight = top.winfo_screenheight()

    # The constants below for Windows and Mac Aqua are visually determined
    # to avoid taskbar or menubar and app icons.
    newy, bot_y = ((0, 72) if sys.platform == 'win32' else
                   (22, 88) if macosx.isAquaTk() else
                   (0, 88))  # Guess for anything else.
    newheight = newheight - newy - bot_y
    newgeom = '' if height >= newheight else f"{width}x{newheight}+{x}+{newy}"
    top.wm_geometry(newgeom)
    return newgeom != ""
示例#15
0
def zoom_height(top):
    geom = top.wm_geometry()
    m = re.match('(\\d+)x(\\d+)\\+(-?\\d+)\\+(-?\\d+)', geom)
    if not m:
        top.bell()
        return
    width, height, x, y = map(int, m.groups())
    newheight = top.winfo_screenheight()
    if sys.platform == 'win32':
        newy = 0
        newheight = newheight - 72
    elif macosx.isAquaTk():
        newy = 22
        newheight = newheight - newy - 88
    else:
        newy = 0
        newheight = newheight - 88
    if height >= newheight:
        newgeom = ''
    else:
        newgeom = '%dx%d+%d+%d' % (width, newheight, x, newy)
    top.wm_geometry(newgeom)
示例#16
0
 def __init__(self, master, **options):
     self.master = master
     self.frame = frame = Frame(master)
     self.frame.pack(fill='both', expand=1)
     self.vbar = vbar = Scrollbar(frame, name='vbar')
     self.vbar.pack(side='right', fill='y')
     self.listbox = listbox = Listbox(frame,
                                      exportselection=0,
                                      background='white')
     if options:
         listbox.configure(options)
     listbox.pack(expand=1, fill='both')
     vbar['command'] = listbox.yview
     listbox['yscrollcommand'] = vbar.set
     listbox.bind('<ButtonRelease-1>', self.click_event)
     listbox.bind('<Double-ButtonRelease-1>', self.double_click_event)
     if macosx.isAquaTk():
         listbox.bind('<ButtonPress-2>', self.popup_event)
         listbox.bind('<Control-Button-1>', self.popup_event)
     else:
         listbox.bind('<ButtonPress-3>', self.popup_event)
     listbox.bind('<Key-Up>', self.up_event)
     listbox.bind('<Key-Down>', self.down_event)
     self.clear()
示例#17
0
def main():
    import getopt
    from platform import system
    from idlelib import testing
    from idlelib import macosx
    global flist, root, use_subprocess
    capture_warnings(True)
    use_subprocess = True
    enable_shell = False
    enable_edit = False
    debug = False
    cmd = None
    script = None
    startup = False
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'c:deihnr:st:')
    except getopt.error as msg:
        print('Error: %s\n%s' % (msg, usage_msg), file=sys.stderr)
        sys.exit(2)
    for o, a in opts:
        if o == '-c':
            cmd = a
            enable_shell = True
        if o == '-d':
            debug = True
            enable_shell = True
        if o == '-e':
            enable_edit = True
        if o == '-h':
            sys.stdout.write(usage_msg)
            sys.exit()
        if o == '-i':
            enable_shell = True
        if o == '-n':
            print(' Warning: running IDLE without a subprocess is deprecated.',
                  file=sys.stderr)
            use_subprocess = False
        if o == '-r':
            script = a
            if os.path.isfile(script):
                pass
            else:
                print('No script file: ', script)
                sys.exit()
            enable_shell = True
        if o == '-s':
            startup = True
            enable_shell = True
        if o == '-t':
            PyShell.shell_title = a
            enable_shell = True
    if args and args[0] == '-':
        cmd = sys.stdin.read()
        enable_shell = True
    for i in range(len(sys.path)):
        sys.path[i] = os.path.abspath(sys.path[i])
    if args and args[0] == '-':
        sys.argv = [''] + args[1:]
    elif cmd:
        sys.argv = ['-c'] + args
    elif script:
        sys.argv = [script] + args
    elif args:
        enable_edit = True
        pathx = []
        for filename in args:
            pathx.append(os.path.dirname(filename))
        for dir in pathx:
            dir = os.path.abspath(dir)
            if not dir in sys.path:
                sys.path.insert(0, dir)
    else:
        dir = os.getcwd()
        if dir not in sys.path:
            sys.path.insert(0, dir)
    edit_start = idleConf.GetOption('main',
                                    'General',
                                    'editor-on-startup',
                                    type='bool')
    enable_edit = enable_edit or edit_start
    enable_shell = enable_shell or not enable_edit
    if use_subprocess and not testing:
        NoDefaultRoot()
    root = Tk(className='Idle')
    root.withdraw()
    icondir = os.path.join(os.path.dirname(__file__), 'Icons')
    if system() == 'Windows':
        iconfile = os.path.join(icondir, 'idle.ico')
        root.wm_iconbitmap(default=iconfile)
    else:
        ext = '.png' if TkVersion >= 8.6 else '.gif'
        iconfiles = [
            os.path.join(icondir, 'idle_%d%s' % (size, ext))
            for size in (16, 32, 48)
        ]
        icons = [
            PhotoImage(master=root, file=iconfile) for iconfile in iconfiles
        ]
        root.wm_iconphoto(True, *icons)
    fixwordbreaks(root)
    fix_x11_paste(root)
    flist = PyShellFileList(root)
    macosx.setupApp(root, flist)
    if enable_edit:
        if not (cmd or script):
            for filename in args[:]:
                if flist.open(filename) is None:
                    args.remove(filename)
            if not args:
                flist.new()
    if enable_shell:
        shell = flist.open_shell()
        if not shell:
            return
        if macosx.isAquaTk() and flist.dict:
            shell.top.lower()
    else:
        shell = flist.pyshell
    if debug:
        shell.open_debugger()
    if startup:
        filename = os.environ.get('IDLESTARTUP') or os.environ.get(
            'PYTHONSTARTUP')
        if filename and os.path.isfile(filename):
            shell.interp.execfile(filename)
    if cmd or script:
        shell.interp.runcommand("""if 1:
            import sys as _sys
            _sys.argv = %r
            del _sys
            
""" % (sys.argv, ))
        if cmd:
            shell.interp.execsource(cmd)
        elif script:
            shell.interp.prepend_syspath(script)
            shell.interp.execfile(script)
    elif shell:
        tkversionwarning = macosx.tkVersionWarning(root)
        if tkversionwarning:
            shell.interp.runcommand("print('%s')" % tkversionwarning)
    while flist.inversedict:
        root.mainloop()
    root.destroy()
    capture_warnings(False)