Skip to content

Commit

Permalink
Start enhancing file browser
Browse files Browse the repository at this point in the history
  • Loading branch information
aivarannamaa committed Feb 7, 2019
1 parent 1c16fe1 commit e485c73
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ encoding//thonny/plugins/ast_view.py=utf-8
encoding//thonny/plugins/cells.py=utf-8
encoding//thonny/plugins/common_editing_commands.py=utf-8
encoding//thonny/plugins/debugger.py=utf-8
encoding//thonny/plugins/files.py=utf-8
encoding//thonny/plugins/find_replace.py=utf-8
encoding//thonny/plugins/heap.py=utf-8
encoding//thonny/plugins/main_file_browser.py=utf-8
encoding//thonny/plugins/pip_gui.py=utf-8
encoding//thonny/plugins/system_shell/__init__.py=utf-8
encoding//thonny/plugins/thonny_folders.py=utf-8
Expand Down
54 changes: 44 additions & 10 deletions thonny/base_file_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,40 @@
from tkinter import ttk

from thonny import get_workbench, misc_utils
from thonny.ui_utils import TreeFrame
from thonny.ui_utils import scrollbar_style

_dummy_node_text = "..."


class BaseFileBrowser(TreeFrame):
class BaseFileBrowser(ttk.Frame):
def __init__(self, master, show_hidden_files=False, last_folder_setting_name=None):
TreeFrame.__init__(self, master, ["#0", "kind", "path"], displaycolumns=(0,))
# print(self.get_toplevel_items())
ttk.Frame.__init__(self, master, borderwidth=0, relief="flat")
self.vert_scrollbar = ttk.Scrollbar(self, orient=tk.VERTICAL,
style=scrollbar_style("Vertical"))
self.vert_scrollbar.grid(row=0, column=1, sticky=tk.NSEW, rowspan=3)

self.toolbar = ttk.Frame(self, style="ViewToolbar.TFrame")
self.toolbar.grid(row=0, sticky="nsew")
self.toolbar.grid(row=1, sticky="nsew")
self.init_toolbar()

self.path_bar = ttk.Frame(self)

self.tree = ttk.Treeview(
self,
columns=["#0", "kind", "path"],
displaycolumns=(0,),
yscrollcommand=self.vert_scrollbar.set,
)
self.tree["show"] = "headings"
self.tree.grid(row=2, column=0, sticky=tk.NSEW)
self.vert_scrollbar["command"] = self.tree.yview
self.columnconfigure(0, weight=1)
self.rowconfigure(2, weight=1)

self.show_hidden_files = show_hidden_files
self.tree["show"] = ("tree",)

self.hor_scrollbar = ttk.Scrollbar(self, orient=tk.HORIZONTAL)
self.tree.config(xscrollcommand=self.hor_scrollbar.set)
self.hor_scrollbar["command"] = self.tree.xview
self.hor_scrollbar.grid(row=1, column=0, sticky="nsew")

wb = get_workbench()
self.folder_icon = wb.get_image("folder")
self.python_file_icon = wb.get_image("python-file")
Expand All @@ -39,7 +55,25 @@ def __init__(self, master, show_hidden_files=False, last_folder_setting_name=Non

self._last_folder_setting_name = last_folder_setting_name
self.open_initial_folder()


def init_toolbar(self):
self.title_label = ttk.Label(self.toolbar, text=self.get_title(), anchor="w",
style="ViewToolbar.TLabel")
self.title_label.grid(row=0, column=1, sticky="nw", padx=2, pady=(2,4))

self.menu_label = ttk.Button(self.toolbar, text=" ≡ ",
style="ViewToolbar.Toolbutton")
self.menu_label.grid(row=0, column=2, padx=4, pady=(2,4))

self.toolbar.columnconfigure(1, weight=1)


#self.star_label = ttk.Label(self.toolbar, image=get_workbench().get_image("031"), text="s")
#self.star_label.grid(row=0, column=2)

def get_title(self):
return "This computer"

def open_initial_folder(self):
if self._last_folder_setting_name:
path = get_workbench().get_option(self._last_folder_setting_name)
Expand Down
30 changes: 28 additions & 2 deletions thonny/plugins/main_file_browser.py → thonny/plugins/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,28 @@

import os
import tkinter as tk
from tkinter import ttk
from tkinter.messagebox import showerror

# from thonny.ui_utils import askstring TODO: doesn't work
from tkinter.simpledialog import askstring

from thonny import get_workbench, misc_utils
from thonny.base_file_browser import BaseFileBrowser

from thonny.ui_utils import lookup_style_option

class FilesView(tk.PanedWindow):
def __init__(self, master=None):
tk.PanedWindow.__init__(self, master, orient="vertical", borderwidth=0)
self.configure(sashwidth=lookup_style_option("Sash", "sashthickness", 10))
self.configure(background=lookup_style_option("TPanedWindow", "background"))

self.local_files = MainFileBrowser(self)
self.add(self.local_files)

self.remote_files = RemoteFileBrowser(self)
self.add(self.remote_files)


class MainFileBrowser(BaseFileBrowser):
def __init__(self, master, show_hidden_files=False):
Expand Down Expand Up @@ -90,6 +104,18 @@ def on_double_click(self, event):
self.refresh_tree(self.get_selected_node(), True)



class RemoteFileBrowser(BaseFileBrowser):
def __init__(self, master, show_hidden_files=False):
BaseFileBrowser.__init__(
self, master, show_hidden_files, "device.last_browser_folder"
)

def get_title(self):
return "Connected device"



def load_plugin() -> None:
get_workbench().set_default("file.last_browser_folder", None)
get_workbench().add_view(MainFileBrowser, "Files", "nw")
get_workbench().add_view(FilesView, "Files", "nw")
Binary file added thonny/res/star.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added thonny/res/star_2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion thonny/workbench.py
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,6 @@ def add_backend(
)

# assing names to related classes
assert proxy_class.backend_name is None
proxy_class.backend_name = name # type: ignore
if not isinstance(config_page_constructor, str):
if not getattr(config_page_constructor, "backend_name", None):
Expand Down Expand Up @@ -1377,6 +1376,10 @@ def show_view(self, view_id: str, set_focus: bool = True) -> Union[bool, tk.Widg
Args:
view_id: View class name
without package name (eg. 'ShellView') """

if view_id == "MainFileBrowser":
# Was renamed in 3.1.1
view_id = "FilesView"

# NB! Don't forget that view.home_widget is added to notebook, not view directly
# get or create
Expand Down

0 comments on commit e485c73

Please sign in to comment.