update gui to talk to the server
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
|
|
||||||
|
|
||||||
class PathHandle:
|
class PathHandle:
|
||||||
"""
|
"""
|
||||||
Manage storing path, cache json.
|
Manage storing path, cache json.
|
||||||
@@ -33,26 +34,43 @@ class PathHandle:
|
|||||||
# list of strings
|
# list of strings
|
||||||
self.path = []
|
self.path = []
|
||||||
|
|
||||||
self.filepath_set("gui.json")
|
#self.filepath_set("gui.json")
|
||||||
self.refresh()
|
self.refresh()
|
||||||
|
|
||||||
def refresh(self):
|
def refresh(self):
|
||||||
with open(self.filepath, 'r') as fp:
|
|
||||||
import json
|
import json
|
||||||
self.json = json.load(fp)
|
# self.json = json.load(fp)
|
||||||
|
self.json = self.json_from_server(self.path)
|
||||||
print(self.json)
|
print(self.json)
|
||||||
|
|
||||||
def filepath_set(self, filepath):
|
# def filepath_set(self, filepath):
|
||||||
self.filepath = filepath
|
# self.filepath = filepath
|
||||||
|
|
||||||
def append_path(self, path_item):
|
def append_path(self, path_item):
|
||||||
if path_item == "..":
|
if path_item == "..":
|
||||||
# maybe we should raise error
|
# maybe we should raise error
|
||||||
if self.path:
|
if self.path:
|
||||||
self.path.pop()
|
self.path.pop()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.path.append(path_item)
|
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):
|
class Application(tk.Frame):
|
||||||
def __init__(self, root):
|
def __init__(self, root):
|
||||||
@@ -80,6 +98,11 @@ class Application(tk.Frame):
|
|||||||
|
|
||||||
self.populate()
|
self.populate()
|
||||||
|
|
||||||
|
def repopulate(self):
|
||||||
|
for b in self.grid_members:
|
||||||
|
b.destroy()
|
||||||
|
self.grid_members.clear()
|
||||||
|
self.populate()
|
||||||
|
|
||||||
def populate(self):
|
def populate(self):
|
||||||
'''Put in some fake data'''
|
'''Put in some fake data'''
|
||||||
@@ -100,26 +123,14 @@ class Application(tk.Frame):
|
|||||||
print(self.path_handle.path)
|
print(self.path_handle.path)
|
||||||
|
|
||||||
but_path.config(text=calc_label_text())
|
but_path.config(text=calc_label_text())
|
||||||
# but_path.labelText = calc_label_text()
|
|
||||||
# but_path.configure()
|
|
||||||
|
|
||||||
self.configure()
|
self.repopulate()
|
||||||
self.frame.configure()
|
|
||||||
self.update()
|
|
||||||
self.frame.update()
|
|
||||||
print(dir(self.frame))
|
|
||||||
# update!
|
|
||||||
|
|
||||||
def exec_path_file(idname):
|
def exec_path_file(idname):
|
||||||
# request the file?
|
self.repopulate()
|
||||||
for b in self.grid_members:
|
|
||||||
b.destroy()
|
|
||||||
self.grid_members.clear()
|
|
||||||
self.populate()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _():
|
|
||||||
js = self.path_handle.json
|
js = self.path_handle.json
|
||||||
items = js.get("items_list")
|
items = js.get("items_list")
|
||||||
items.sort()
|
items.sort()
|
||||||
@@ -148,10 +159,10 @@ class Application(tk.Frame):
|
|||||||
|
|
||||||
self.grid_members.append(but)
|
self.grid_members.append(but)
|
||||||
row += 1
|
row += 1
|
||||||
del name_short, name_full, item_type
|
|
||||||
for name_short, name_full, item_type in items:
|
for name_short, name_full, item_type in items:
|
||||||
print(name_short, name_full, item_type)
|
print(name_short, name_full, item_type)
|
||||||
if item_type == "file":
|
if item_type in {"file", "blendfile"}:
|
||||||
but = tk.Label(self.frame, text="(f)", width=3, borderwidth="1", relief="solid")
|
but = tk.Label(self.frame, text="(f)", width=3, borderwidth="1", relief="solid")
|
||||||
but.grid(row=row, column=0)
|
but.grid(row=row, column=0)
|
||||||
def fn(idname=name_short): exec_path_file(idname)
|
def fn(idname=name_short): exec_path_file(idname)
|
||||||
@@ -164,10 +175,6 @@ class Application(tk.Frame):
|
|||||||
|
|
||||||
self.grid_members.append(but)
|
self.grid_members.append(but)
|
||||||
row += 1
|
row += 1
|
||||||
del name_short, name_full, item_type
|
|
||||||
# import IPython; IPython.embed()
|
|
||||||
|
|
||||||
_(); del _
|
|
||||||
|
|
||||||
|
|
||||||
def OnFrameConfigure(self, event):
|
def OnFrameConfigure(self, event):
|
||||||
@@ -176,5 +183,6 @@ class Application(tk.Frame):
|
|||||||
|
|
||||||
root = tk.Tk()
|
root = tk.Tk()
|
||||||
app = Application(root).pack(side="top", fill="both", expand=True)
|
app = Application(root).pack(side="top", fill="both", expand=True)
|
||||||
|
root.title("BAM")
|
||||||
root.mainloop()
|
root.mainloop()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user