Example #1
0
def setup():
    displayer = WelcomeMessageDisplayer()
    get_tab_manager().bind('<Configure>', displayer.update_wraplen, add=True)
    utils.bind_with_data(get_tab_manager(),
                         '<<NewTab>>',
                         displayer.on_new_tab,
                         add=True)
Example #2
0
def setup():
    # this must run even if loading tabs from states below fails
    get_main_window().bind('<<RBTKQuit>>', save_states, add=True)

    try:
        with open(STATE_FILE, 'rb') as file:
            states = pickle.load(file)
    except FileNotFoundError:
        states = []

    for tab_class, state in states:
        tab = tab_class.from_state(get_tab_manager(), state)
        get_tab_manager().add_tab(tab)
Example #3
0
def save_states(junk_event):
    states = []
    for tab in get_tab_manager().tabs:
        state = tab.get_state()
        if state is not None:
            states.append((type(tab), state))

    with open(STATE_FILE, 'wb') as file:
        pickle.dump(states, file)
Example #4
0
    def edit_it():
        # porcupine/tabs.py imports this file
        # these local imports feel so evil xD  MUHAHAHAA!!!
        from rbtk import tabs

        path = os.path.join(dirs.configdir, 'filetypes.ini')
        manager = rbtk.get_tab_manager()
        manager.add_tab(tabs.FileTab.open_file(manager, path))
        _dialog.withdraw()
Example #5
0
def gotoline():
    tab = rbtk.get_tab_manager().current_tab

    # simpledialog isn't ttk yet, but it's not a huge problem imo
    # TODO: what if lineno is 0 or negative?
    lineno = simpledialog.askinteger("Go to Line",
                                     "Type a line number and press Enter:")
    if lineno is not None:  # not cancelled
        column = tab.textwidget.index('insert').split('.')[1]
        tab.textwidget.mark_set('insert', '%d.%s' % (lineno, column))
        tab.textwidget.see('insert')

    tab.on_focus()
Example #6
0
def start_pasting(pastebin_name):
    tab = rbtk.get_tab_manager().current_tab
    try:
        code = tab.textwidget.get('sel.first', 'sel.last')
    except tkinter.TclError:
        # nothing is selected, pastebin everything
        code = tab.textwidget.get('1.0', 'end - 1 char')

    if isinstance(tab, tabs.FileTab):
        origin = tab.path
    else:
        origin = '>>>'      # FIXME

    Paste(pastebin_name, code, origin).start()
Example #7
0
def on_click():
    widget = rbtk.get_tab_manager().current_tab.textwidget
    before = widget.get('1.0', 'end - 1 char')
    after = run_autopep8(before)
    if after is None:
        # error
        return

    if before != after:
        widget['autoseparators'] = False
        widget.delete('1.0', 'end - 1 char')
        widget.insert('1.0', after)
        widget.edit_separator()
        widget['autoseparators'] = True
Example #8
0
def _dialog(action, last_path):
    # pygments supports so many different kinds of file types that
    # showing them all would be insane
    # TODO: allow configuring which file types are shown
    options = {'filetypes': [("All files", "*")]}

    # the mro thing is there to avoid import cycles (lol)
    tab = rbtk.get_tab_manager().current_tab
    if any(cls.__name__ == 'FileTab' for cls in type(tab).__mro__):
        if tab.filetype.patterns:
            options['filetypes'].insert(
                0, ("%s files" % tab.filetype.name, tab.filetype.patterns))
        elif 'filetypes' in last_options:
            options['filetypes'] = last_options['filetypes']

        if tab.path is not None:
            options['initialdir'] = os.path.dirname(tab.path)
        elif 'initialdir' in last_options:
            options['initialdir'] = last_options['initialdir']

    last_options.clear()
    last_options.update(options)

    if action == 'open':
        assert last_path is None
        options['title'] = "Open Files"

        filenames = [
            os.path.abspath(file)
            for file in filedialog.askopenfilenames(**options)
        ]
        if filenames:
            last_options['initialdir'] = os.path.dirname(filenames[0])
        return filenames

    assert action == 'save'
    options['title'] = "Save As"
    if last_path is not None:
        options['initialdir'] = os.path.dirname(last_path)
        options['initialfile'] = os.path.basename(last_path)

    # filename can be '' if the user cancelled
    filename = filedialog.asksaveasfilename(**options)
    if filename:
        filename = os.path.abspath(filename)
        last_options['defaultdir'] = os.path.dirname(filename)
        return filename
    return None
Example #9
0
def setup():
    utils.bind_with_data(get_tab_manager(), '<<NewTab>>', on_new_tab, add=True)
Example #10
0
def setup():
    rbtk.add_action(find,
                    "Edit/Find and Replace", ("Ctrl+F", '<Control-f>'),
                    tabtypes=[tabs.FileTab])
    utils.bind_with_data(get_tab_manager(), '<<NewTab>>', on_new_tab, add=True)
    get_tab_manager().bind('<<CurrentTabChanged>>', on_tab_changed, add=True)
Example #11
0
def find():
    current_tab = rbtk.get_tab_manager().current_tab
    find_widgets[current_tab].pack(fill='x')
Example #12
0
 def _on_tab_closed(self, event):
     if not get_tab_manager().tabs:
         self._message.place(relx=0.5, rely=0.5, anchor='center')
Example #13
0
 def __init__(self):
     self._message = ttk.Frame(get_tab_manager())
     self._message.place(relx=0.5, rely=0.5, anchor='center')
     ttk.Label(self._message, text="Welcome to RBTK!\n",
               font=('', 16, '')).pack()
     ttk.Label(self._message, text=MESSAGE, font=('', 14, '')).pack()