-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUI.py
144 lines (101 loc) · 5.1 KB
/
GUI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import tkinter as tk
import tkinter.messagebox
import tkinter.simpledialog
from utils import keys, responses_path
from tkinter import ttk, filedialog, messagebox
def ask_confirmation():
result = tkinter.messagebox.askyesno("Confirmation", "Are you sure you would like to get this data?"
" This is an API call")
return result
def load_file():
path = filedialog.askopenfilename(initialdir=responses_path, filetypes=[('JSON files', "*.json")])
return path
def prompt_for_number():
number = tkinter.simpledialog.askinteger("New stake", "Enter new stake value $", minvalue=1, maxvalue=1000000000)
return number
def show_error_message(error_title, message):
messagebox.showerror(error_title, message)
class GUI:
def __init__(self):
apis = list(keys.keys())
self.controller = None
self.window = tk.Tk()
self.window.title("Arbitrage finder")
self.window.geometry("800x600")
self.window.resizable(width=False, height=False)
top_bar = tk.Frame(self.window)
top_bar.columnconfigure(4, weight=1)
top_bar.pack()
self.api_selection = tk.StringVar(self.window)
self.api_selection.set(apis[0])
self.market_selection = tk.StringVar(self.window)
self.market_selection.set(list(keys.get(apis[0]))[0])
self.api_dropdown = tk.OptionMenu(top_bar, self.api_selection, *apis,
command=self.update_dropdowns)
self.market_dropdown = ttk.Combobox(top_bar, values=list(keys.get(apis[0])), state='readonly')
self.market_dropdown.configure(width=35)
self.market_dropdown.current(0)
self.button1 = tk.Button(top_bar, text="Get data")
self.button2 = tk.Button(top_bar, text="Clear list")
self.button3 = tk.Button(top_bar, text="Set stake")
self.button4 = tk.Button(top_bar, text="Load from JSON")
self.api_dropdown.grid(row=0, column=0)
self.market_dropdown.grid(row=0, column=1)
self.button1.grid(row=0, column=2)
self.button2.grid(row=0, column=3)
self.button3.grid(row=0, column=4)
self.button4.grid(row=0, column=5)
self.scrollable_info_canvas = tk.Canvas(self.window)
self.main_info_scrollbar = tk.Scrollbar(self.window, orient="vertical", command=self.scrollable_info_canvas.yview)
self.scrollable_info_canvas.configure(yscrollcommand=self.main_info_scrollbar.set)
self.scrollable_info_canvas.pack(side="left", fill="both", expand=True)
self.main_info_scrollbar.pack(side="right", fill="y")
self.scroll_frame = tk.Frame(self.scrollable_info_canvas)
self.items = []
self.market_dropdown.bind("<Enter>", self.disable_main_info_scrolling)
self.market_dropdown.bind("<Leave>", self.enable_main_info_scrolling)
def set_controller(self, controller):
self.controller = controller
self.button1.configure(command=controller.get_data_and_update_info)
self.button2.configure(command=controller.clear_list)
self.button3.configure(command=controller.update_stake)
self.button4.configure(command=controller.load_json)
def disable_main_info_scrolling(self, event):
pass
def enable_main_info_scrolling(self, event):
pass
def start_gui(self):
self.window.mainloop()
def update_scrollable_info(self, new_info_list):
self.scroll_frame.destroy()
self.scroll_frame = tk.Frame(self.scrollable_info_canvas)
self.scroll_frame.pack()
self.items = new_info_list
self.scroll_frame.columnconfigure(len(self.items), weight=1)
self.scroll_frame.rowconfigure(len(self.items), weight=1)
for i, item in enumerate(self.items):
split_by_dollar_sign = item.split("$")
profit = float(split_by_dollar_sign[len(split_by_dollar_sign) - 1])
color = "black"
if profit > 0.0:
color = "green"
elif profit < 0.0:
color = "red"
label = tk.Label(self.scroll_frame, text=item, foreground=color,
relief="groove", width=109, height=2, wraplength=720)
label.grid(row=i, column=0, stick="nsew")
self.scrollable_info_canvas.create_window((0, 0), window=self.scroll_frame, anchor="nw")
self.scrollable_info_canvas.bind_all("<MouseWheel>",
lambda event: self.scrollable_info_canvas.yview_scroll
(int(-1 * (event.delta / 120)), "units"))
self.scroll_frame.update_idletasks()
self.scrollable_info_canvas.configure(scrollregion=self.scrollable_info_canvas.bbox("all"))
def update_dropdowns(self, event=None):
selected_api = self.api_selection.get()
self.market_dropdown.configure(values=list(keys.get(selected_api)))
self.market_dropdown.current(0)
def get_api_market(self):
return self.api_selection.get(), self.market_dropdown.get()
if __name__ == '__main__':
gui = GUI()
gui.start_gui()