update gui to talk to the server
This commit is contained in:
132
gui/browser.py
132
gui/browser.py
@@ -19,6 +19,7 @@
|
||||
|
||||
import tkinter as tk
|
||||
|
||||
|
||||
class PathHandle:
|
||||
"""
|
||||
Manage storing path, cache json.
|
||||
@@ -33,26 +34,43 @@ class PathHandle:
|
||||
# list of strings
|
||||
self.path = []
|
||||
|
||||
self.filepath_set("gui.json")
|
||||
#self.filepath_set("gui.json")
|
||||
self.refresh()
|
||||
|
||||
def refresh(self):
|
||||
with open(self.filepath, 'r') as fp:
|
||||
import json
|
||||
self.json = json.load(fp)
|
||||
print(self.json)
|
||||
import json
|
||||
# self.json = json.load(fp)
|
||||
self.json = self.json_from_server(self.path)
|
||||
print(self.json)
|
||||
|
||||
def filepath_set(self, filepath):
|
||||
self.filepath = filepath
|
||||
# def filepath_set(self, filepath):
|
||||
# self.filepath = filepath
|
||||
|
||||
def append_path(self, path_item):
|
||||
if path_item == "..":
|
||||
# maybe we should raise error
|
||||
if self.path:
|
||||
self.path.pop()
|
||||
|
||||
else:
|
||||
self.path.append(path_item)
|
||||
self.refresh()
|
||||
|
||||
@staticmethod
|
||||
def json_from_server(path):
|
||||
def request_url(req_path):
|
||||
# TODO, get from config
|
||||
BAM_SERVER = "http://localhost:5000"
|
||||
result = "%s/%s" % (BAM_SERVER, req_path)
|
||||
print(result)
|
||||
return result
|
||||
|
||||
import requests
|
||||
payload = {"path": "/".join(path)}
|
||||
r = requests.get(request_url("files"), params=payload, auth=("bam", "bam"))
|
||||
print(r.text)
|
||||
return r.json()
|
||||
|
||||
|
||||
|
||||
class Application(tk.Frame):
|
||||
def __init__(self, root):
|
||||
@@ -80,6 +98,11 @@ class Application(tk.Frame):
|
||||
|
||||
self.populate()
|
||||
|
||||
def repopulate(self):
|
||||
for b in self.grid_members:
|
||||
b.destroy()
|
||||
self.grid_members.clear()
|
||||
self.populate()
|
||||
|
||||
def populate(self):
|
||||
'''Put in some fake data'''
|
||||
@@ -100,74 +123,58 @@ class Application(tk.Frame):
|
||||
print(self.path_handle.path)
|
||||
|
||||
but_path.config(text=calc_label_text())
|
||||
# but_path.labelText = calc_label_text()
|
||||
# but_path.configure()
|
||||
|
||||
self.configure()
|
||||
self.frame.configure()
|
||||
self.update()
|
||||
self.frame.update()
|
||||
print(dir(self.frame))
|
||||
# update!
|
||||
self.repopulate()
|
||||
|
||||
|
||||
def exec_path_file(idname):
|
||||
# request the file?
|
||||
for b in self.grid_members:
|
||||
b.destroy()
|
||||
self.grid_members.clear()
|
||||
self.populate()
|
||||
self.repopulate()
|
||||
|
||||
|
||||
js = self.path_handle.json
|
||||
items = js.get("items_list")
|
||||
items.sort()
|
||||
if items is None:
|
||||
tk.Label(self, text="Empty")
|
||||
|
||||
def _():
|
||||
js = self.path_handle.json
|
||||
items = js.get("items_list")
|
||||
items.sort()
|
||||
if items is None:
|
||||
tk.Label(self, text="Empty")
|
||||
but_path = tk.Label(self.frame, text=calc_label_text())
|
||||
but_path.grid(row=0, column=1, sticky="nw")
|
||||
self.grid_members.append(but_path)
|
||||
|
||||
but_path = tk.Label(self.frame, text=calc_label_text())
|
||||
but_path.grid(row=0, column=1, sticky="nw")
|
||||
self.grid_members.append(but_path)
|
||||
row = 1
|
||||
import random
|
||||
random.shuffle(items)
|
||||
for name_short, name_full, item_type in [("..", "", "folder")] + items:
|
||||
print(name_short, name_full, item_type)
|
||||
if item_type == "folder":
|
||||
but = tk.Label(self.frame, text="(/)", width=3, borderwidth="1", relief="solid")
|
||||
but.grid(row=row, column=0)
|
||||
self.grid_members.append(but)
|
||||
|
||||
row = 1
|
||||
import random
|
||||
random.shuffle(items)
|
||||
for name_short, name_full, item_type in [("..", "", "folder")] + items:
|
||||
print(name_short, name_full, item_type)
|
||||
if item_type == "folder":
|
||||
but = tk.Label(self.frame, text="(/)", width=3, borderwidth="1", relief="solid")
|
||||
but.grid(row=row, column=0)
|
||||
self.grid_members.append(but)
|
||||
def fn(idname=name_short, but_path=but_path): exec_path_folder(idname, but_path)
|
||||
|
||||
def fn(idname=name_short, but_path=but_path): exec_path_folder(idname, but_path)
|
||||
but = tk.Button(self.frame, text=name_short + "/", fg="green", command=fn)
|
||||
but.grid(row=row, column=1, sticky="nw")
|
||||
del fn
|
||||
|
||||
but = tk.Button(self.frame, text=name_short + "/", fg="green", command=fn)
|
||||
but.grid(row=row, column=1, sticky="nw")
|
||||
del fn
|
||||
self.grid_members.append(but)
|
||||
row += 1
|
||||
|
||||
self.grid_members.append(but)
|
||||
row += 1
|
||||
del name_short, name_full, item_type
|
||||
for name_short, name_full, item_type in items:
|
||||
print(name_short, name_full, item_type)
|
||||
if item_type == "file":
|
||||
but = tk.Label(self.frame, text="(f)", width=3, borderwidth="1", relief="solid")
|
||||
but.grid(row=row, column=0)
|
||||
def fn(idname=name_short): exec_path_file(idname)
|
||||
self.grid_members.append(but)
|
||||
for name_short, name_full, item_type in items:
|
||||
print(name_short, name_full, item_type)
|
||||
if item_type in {"file", "blendfile"}:
|
||||
but = tk.Label(self.frame, text="(f)", width=3, borderwidth="1", relief="solid")
|
||||
but.grid(row=row, column=0)
|
||||
def fn(idname=name_short): exec_path_file(idname)
|
||||
self.grid_members.append(but)
|
||||
|
||||
|
||||
but = tk.Button(self.frame, text=name_short, fg="blue", command=fn)
|
||||
but.grid(row=row, column=1, sticky="nw")
|
||||
del fn
|
||||
but = tk.Button(self.frame, text=name_short, fg="blue", command=fn)
|
||||
but.grid(row=row, column=1, sticky="nw")
|
||||
del fn
|
||||
|
||||
self.grid_members.append(but)
|
||||
row += 1
|
||||
del name_short, name_full, item_type
|
||||
# import IPython; IPython.embed()
|
||||
|
||||
_(); del _
|
||||
self.grid_members.append(but)
|
||||
row += 1
|
||||
|
||||
|
||||
def OnFrameConfigure(self, event):
|
||||
@@ -176,5 +183,6 @@ class Application(tk.Frame):
|
||||
|
||||
root = tk.Tk()
|
||||
app = Application(root).pack(side="top", fill="both", expand=True)
|
||||
root.title("BAM")
|
||||
root.mainloop()
|
||||
|
||||
|
Reference in New Issue
Block a user