Skip to content

Commit

Permalink
multitickers support
Browse files Browse the repository at this point in the history
  • Loading branch information
tonymorony committed Mar 5, 2020
1 parent 20cf57e commit 9245519
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 53 deletions.
38 changes: 38 additions & 0 deletions lib/sharelib.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from tkinter.filedialog import askopenfilename
import ttkthemes as tkT
import tkinter as tk
from tkinter import ttk
import pprint


Expand Down Expand Up @@ -147,3 +148,40 @@ def convert_size(size_bytes):
p = math.pow(1024, i)
s = round(size_bytes / p, 2)
return "%s %s" % (s, size_name[i])


def connnection_popup():
connection_popup = tkT.ThemedTk()
ac_name_var = tk.StringVar()
connection_popup.geometry("400x400")
connection_popup.title("DEXP2P fileshare GUI")
connection_popup.set_theme('equilux', themebg=True)
ticker_input_label = ttk.Label(text="Please input chain ticker: ")
ticker_input_entry = ttk.Entry(connection_popup)
ticker_input_entry.insert(tk.END, 'FILET1')
try_to_connect_button = ttk.Button(connection_popup, text="Start GUI",
command= lambda: connect_gui_to_daemon(ticker_input_entry.get(),
down_daemon_message_label, connection_popup, ac_name_var))
down_daemon_message_label = tk.Label(connection_popup, width=100,
height=10, font=("Helvetica", 16))
ticker_input_label.pack()
ticker_input_entry.pack()
try_to_connect_button.pack()
down_daemon_message_label.pack(padx=(10,10), pady=(50,50))
connection_popup.mainloop()
return ac_name_var.get()


def connect_gui_to_daemon(ac_name_ticker, text_label, root_window, ac_name_app_var):
try:
chain_proxy = def_credentials(ac_name_ticker)
file_uploading_proxy = def_credentials(ac_name_ticker, "uploading")
print("Connected to " + ac_name_ticker)
ac_name_app_var.set(ac_name_ticker)
root_window.destroy()
except Exception as e:
print(e)
down_daemon_message = "Can't connect to " + ac_name_ticker + " daemon.\n Please start it with dexp2p param first!"
print(down_daemon_message)
text_label["text"] = down_daemon_message

90 changes: 37 additions & 53 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,59 +6,12 @@
import time
import datetime

# TODO: make it as a setting?
ac_name = "FILET1"

# Trying to connect
try:
chain_proxy = sharelib.def_credentials(ac_name)
file_uploading_proxy = sharelib.def_credentials(ac_name, "uploading")
except Exception as e:
print(e)
connection_popup = tkT.ThemedTk()
connection_popup.geometry("400x400")
connection_popup.title("DEXP2P fileshare GUI")
connection_popup.set_theme('equilux', themebg=True)
down_daemon_message = "Can't connect to " + ac_name + " daemon.\n Please start it with dexp2p param first!"
down_daemon_message_label = tk.Label(connection_popup, text=down_daemon_message, width=100,
height=10, font=("Helvetica", 16))
down_daemon_message_label.pack(padx=(10,10), pady=(50,50))
connection_popup.mainloop()


def update_progress_bar(progress_label):
# separated rpc proxy because first one awaiting response from uploading command
rpc_proxy = sharelib.def_credentials(ac_name)
dex_stats = rpc_proxy.DEX_stats()
# print(dex_stats)
if "progress" in dex_stats.keys():
uploading_progress = float(dex_stats["progress"])
progress_label["text"] = str(round(uploading_progress,2)) + " %"
uploading_delta = uploading_progress - float(previous_uploading_progress.get())
print(uploading_progress)
uploading_progress_bar.step(uploading_delta)
previous_uploading_progress.set(uploading_progress)
else:
pass
# print("no uploading at the moment")
# .after is something like a tkinter "threads"
root.after(100, lambda: update_progress_bar(progress_label))


def update_files_list(files_table, update_status_label):
print("updating files list")
files_table.delete(*files_table.get_children())
rpc_proxy = sharelib.def_credentials(ac_name)
files_list_response = rpc_proxy.DEX_list("0", "0", "files")["matches"]
print(files_list_response)
for file in files_list_response:
file_size = sharelib.convert_size(float(file["amountA"]) * (10**8))
readable_date = datetime.datetime.fromtimestamp(file["timestamp"]).isoformat()
files_table.insert("", "end", text=file["id"], values=[readable_date, file["tagB"],
file["senderpub"], file_size])
update_status_label['text'] = "Last update: " + time.ctime() + " (auto-update each 30s)"
root.after(30000, lambda: update_files_list(files_table, update_status_label))
ac_name = sharelib.connnection_popup()

chain_proxy = sharelib.def_credentials(ac_name)
file_uploading_proxy = sharelib.def_credentials(ac_name, mode="fileuploading")

root = tkT.ThemedTk()
frame = ttk.Frame(root)
Expand Down Expand Up @@ -103,7 +56,6 @@ def update_files_list(files_table, update_status_label):

root.columnconfigure(0, weight=1)
frame.grid(row=0, column=0)

img = ImageTk.PhotoImage(file="kmd_logo_50.png")
img_label = ttk.Label(frame, image=img)
img_label.grid(row=0, column=1, pady=(25,25))
Expand All @@ -112,7 +64,6 @@ def update_files_list(files_table, update_status_label):
file_upload_button.grid(row=2, column=2, sticky="ne", padx=(10,10), pady=(10,10))

uploading_progress_label = ttk.Label(frame, text="")

uploading_progress_bar = ttk.Progressbar(frame, orient="horizontal", mode="determinate")
uploading_progress_bar.grid(row=4, column=0, columnspan=3, sticky="nsew", padx=(10,10), pady=(10,10))
uploading_progress_label.grid(row=5, column=1, pady=(5,5))
Expand All @@ -123,8 +74,41 @@ def update_files_list(files_table, update_status_label):
download_selected_file_button.grid(row=9, column=0, columnspan=3, sticky="nsew", padx=(10,10), pady=(5,5))


def update_progress_bar(progress_label):
# separated rpc proxy because first one awaiting response from uploading command
rpc_proxy = sharelib.def_credentials(ac_name)
dex_stats = rpc_proxy.DEX_stats()
# print(dex_stats)
if "progress" in dex_stats.keys():
uploading_progress = float(dex_stats["progress"])
progress_label["text"] = str(round(uploading_progress,2)) + " %"
uploading_delta = uploading_progress - float(previous_uploading_progress.get())
print(uploading_progress)
uploading_progress_bar.step(uploading_delta)
previous_uploading_progress.set(uploading_progress)
else:
pass
# print("no uploading at the moment")
# .after is something like a tkinter "threads"
root.after(100, lambda: update_progress_bar(progress_label))


def update_files_list(files_table, update_status_label):
print("updating files list")
files_table.delete(*files_table.get_children())
rpc_proxy = sharelib.def_credentials(ac_name, mode="test")
files_list_response = rpc_proxy.DEX_list("0", "0", "files")["matches"]
print(files_list_response)
for file in files_list_response:
file_size = sharelib.convert_size(float(file["amountA"]) * (10**8))
readable_date = datetime.datetime.fromtimestamp(file["timestamp"]).isoformat()
files_table.insert("", "end", text=file["id"], values=[readable_date, file["tagB"],
file["senderpub"], file_size])
update_status_label['text'] = "Last update: " + time.ctime() + " (auto-update each 30s)"
root.after(30000, lambda: update_files_list(files_table, update_status_label))


update_progress_bar(uploading_progress_label)
update_files_list(files_list, last_updated_label)

# TODO: have to check if needed assetchain is started and assist user with it
root.mainloop()

0 comments on commit 9245519

Please sign in to comment.