Skip to content

Commit

Permalink
redesign of the main app, with drops tab and advanced tracker as a dr…
Browse files Browse the repository at this point in the history
…opdown caret... :)
  • Loading branch information
oskros committed Sep 23, 2020
1 parent 0064e04 commit 4d20bc9
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 101 deletions.
2 changes: 2 additions & 0 deletions build_exe/directory_exe.spec
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ a.datas += [('d2icon.png', 'C:\\Users\\oskro\\PycharmProjects\\MF_counter_releas
a.datas += [('run_sound.wav', 'C:\\Users\\oskro\\PycharmProjects\\MF_counter_releases\\media\\run_sound.wav', 'Data')]
a.datas += [('icon.ico', 'C:\\Users\\oskro\\PycharmProjects\\MF_counter_releases\\media\\icon.ico', 'Data')]
a.datas += [('item_library.csv', 'C:\\Users\\oskro\\PycharmProjects\\MF_counter_releases\\media\\item_library.csv', 'Data')]
a.datas += [('caret-down.png', 'C:\\Users\\oskro\\PycharmProjects\\MF_counter_releases\\media\\caret-down.png', 'Data')]
a.datas += [('caret-up.png', 'C:\\Users\\oskro\\PycharmProjects\\MF_counter_releases\\media\\caret-up.png', 'Data')]
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
Expand Down
2 changes: 2 additions & 0 deletions build_exe/onefile_exe.spec
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ a.datas += [('d2icon.png', 'C:\\Users\\oskro\\PycharmProjects\\MF_counter_releas
a.datas += [('run_sound.wav', 'C:\\Users\\oskro\\PycharmProjects\\MF_counter_releases\\media\\run_sound.wav', 'Data')]
a.datas += [('icon.ico', 'C:\\Users\\oskro\\PycharmProjects\\MF_counter_releases\\media\\icon.ico', 'Data')]
a.datas += [('item_library.csv', 'C:\\Users\\oskro\\PycharmProjects\\MF_counter_releases\\media\\item_library.csv', 'Data')]
a.datas += [('caret-down.png', 'C:\\Users\\oskro\\PycharmProjects\\MF_counter_releases\\media\\caret-down.png', 'Data')]
a.datas += [('caret-up.png', 'C:\\Users\\oskro\\PycharmProjects\\MF_counter_releases\\media\\caret-up.png', 'Data')]
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
Expand Down
92 changes: 59 additions & 33 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from utils.color_themes import Theme, available_themes
from tkinter import messagebox
import tkinter as tk
from utils import tk_dynamic as tkd, tk_utils, github_releases, other_utils
from utils import tk_dynamic as tkd, tk_utils, github_releases, other_utils, stats_tracker
from tabs.about import About
from tabs.drops import Drops
from tabs.mf_timer import MFRunTimer
Expand Down Expand Up @@ -81,7 +81,6 @@ def __init__(self):
if self.active_theme not in available_themes:
self.active_theme = 'vista'
self.theme = Theme(used_theme=self.active_theme)
self.drop_lab = tkd.Label(self.root, text='Drops', font='helvetica 14', bg=self.theme.label_color, fg=self.theme.text_color)

# Create hotkey queue and initiate process for monitoring the queue
self.queue = queue.Queue(maxsize=1)
Expand All @@ -107,6 +106,7 @@ def __init__(self):
self.clickable = True
self.root.resizable(False, False)
self.root.geometry('+%d+%d' % other_utils.safe_eval(self.cfg['DEFAULT']['window_start_position']))
self.root.config(borderwidth=2, height=439, width=240, relief='raised')
# self.root.wm_attributes("-transparentcolor", "purple")
self.root.wm_attributes("-topmost", self.always_on_top)
self.root.focus_get()
Expand All @@ -122,40 +122,50 @@ def __init__(self):
self.img_panel.bind("<ButtonPress-1>", self.root.start_move)
self.img_panel.bind("<ButtonRelease-1>", self.root.stop_move)
self.img_panel.bind("<B1-Motion>", self.root.on_motion)
self.root.bind("<Delete>", self.delete_selection)
self.root.bind("<Left>", self.root.moveleft)
self.root.bind("<Right>", self.root.moveright)
self.root.bind("<Up>", self.root.moveup)
self.root.bind("<Down>", self.root.movedown)

# Build tabs
self.drops_frame = tkd.Frame(self.root)
self.tabcontrol = tkd.Notebook(self.root)
self.profile_tab = Profile(self, parent=self.tabcontrol)
self.timer_tab = MFRunTimer(self, parent=self.tabcontrol)
self.drops_tab = Drops(self, parent=self)
self.drops_tab = Drops(self, parent=self.drops_frame)
self.options_tab = Options(self, self.timer_tab, self.drops_tab, parent=self.tabcontrol)
self.grail_tab = Grail(self, parent=self.tabcontrol)
self.about_tab = About(parent=self.tabcontrol)

self.tabcontrol.add(self.timer_tab, text='Timer')
self.toggle_drop_tab()
self.tabcontrol.add(self.options_tab, text='Options')
self.tabcontrol.add(self.profile_tab, text='Profile')
self.tabcontrol.add(self.grail_tab, text='Grail')
self.tabcontrol.add(self.about_tab, text='About')

self.tabcontrol.pack(expand=1, fill='both')
self.tabcontrol.pack(expand=False, fill=tk.BOTH)
self.root.bind("<<NotebookTabChanged>>", lambda e: self.notebook_tab_change())
self.profile_tab.update_descriptive_statistics()

# Add buttons to main widget
lf = tkd.LabelFrame(self.root, height=35)
lf.propagate(False) # dont allow buttons to modify label frame size
lf.pack(expand=True, fill=tk.BOTH)
tkd.Button(lf, text='Start\nnew run', command=self.timer_tab.stop_start).pack(side=tk.LEFT, expand=True, fill=tk.BOTH)
tkd.Button(lf, text='End\nthis run', command=self.timer_tab.stop).pack(side=tk.LEFT, expand=True, fill=tk.BOTH)
tkd.Button(lf, text='Add\ndrop', command=self.drops_tab.add_drop).pack(side=tk.LEFT, expand=True, fill=tk.BOTH)
tkd.Button(lf, text='Reset\nlap', command=self.timer_tab.reset_lap).pack(side=tk.LEFT, expand=True, fill=tk.BOTH)
tkd.Button(lf, text='Archive\n& reset', command=self.ArchiveReset).pack(side=tk.LEFT, expand=True, fill=tk.BOTH)
btn_frame = tkd.Frame(self.root)
btn_frame.pack(expand=False, fill=tk.BOTH, side=tk.TOP)
tkd.Button(btn_frame, text='Delete selection', command=self.delete_selection).pack(side=tk.LEFT, expand=True, fill=tk.BOTH, padx=[2, 1], pady=1)
tkd.Button(btn_frame, text='Archive & reset', command=self.ArchiveReset).pack(side=tk.LEFT, expand=True, fill=tk.BOTH, padx=[0,1], pady=1)

self.drops_frame.pack(fill=tk.BOTH, expand=True)
self.toggle_drops_frame(show=self.show_drops_tab_below)
self.drops_caret = tkd.CaretButton(self.drops_frame, active=self.show_drops_tab_below, command=self.toggle_drops_frame, text='Drops', compound=tk.RIGHT, height=13)
self.drops_caret.propagate(False)
self.drops_caret.pack(side=tk.BOTTOM, fill=tk.X, expand=True, padx=[2,1], pady=[0, 1])

self.advanced_stats_tracker = stats_tracker.StatsTracker(self)
self.advanced_stats_caret = tkd.CaretButton(self.root, active=other_utils.safe_eval(self.cfg['AUTOMODE']['advanced_tracker_open']) and self.automode == 2,
text='Advanced stats', compound=tk.RIGHT, height=13, command=self.toggle_advanced_stats_frame)
self.advanced_stats_caret.propagate(False)
self.advanced_stats_caret.pack(side=tk.BOTTOM, fill=tk.X, expand=True, padx=[2, 1], pady=[0, 1])
self.toggle_advanced_stats_frame(show=other_utils.safe_eval(self.cfg['AUTOMODE']['advanced_tracker_open']))

# Register binds for changing tabs
if self.tab_switch_keys_global:
Expand All @@ -177,7 +187,7 @@ def __init__(self):
# Automode
self.toggle_automode()

# A trick to disable windows DPI scaling (the app doesnt work well with scaling, unfortunately)
# A trick to disable windows DPI scaling - the app doesnt work well with scaling, unfortunately
ctypes.windll.shcore.SetProcessDpiAwareness(2)

# Used if auto archive & reset is activated
Expand All @@ -186,6 +196,12 @@ def __init__(self):
# Start the program
self.root.mainloop()

def delete_selection(self, event=None):
if self.timer_tab.m.curselection():
self.timer_tab.delete_selected_run()
elif self.drops_tab.focus_get()._name == 'droplist':
self.drops_tab.delete_selected_drops()

def load_memory_reader(self, show_err=True):
try:
assert self.automode == 2
Expand Down Expand Up @@ -256,27 +272,37 @@ def toggle_tab_keys_global(self):
self.root.bind_all('<Control-Shift-Next>', lambda event: self.tabcontrol.next_tab())
self.root.bind_all('<Control-Shift-Prior>', lambda event: self.tabcontrol.prev_tab())

def toggle_drop_tab(self):
"""
Toggles whether the drop tab should be shown below the main application, or as its own tab. Relies on hard-coded
length and width of the application which means that changing font sizes can mess it up
"""
if self.show_drops_tab_below:
tab_name = next((x for x in self.tabcontrol.tabs() if x.endswith('drops')), '')
if tab_name in self.tabcontrol.tabs():
self.tabcontrol.forget(tab_name)
self.root.config(borderwidth=2, relief='raised', height=605, width=240)
self.drops_tab.pack(side=tk.BOTTOM)
self.drops_tab.m.config(height=8, width=24)
self.drop_lab.pack(side=tk.BOTTOM)
def toggle_drops_frame(self, show=None):
if show is None:
show = self.drops_caret.active
if show:
self.root.config(height=self.root.winfo_height()+174)
self.drops_tab.pack(pady=[0, 2])
else:
if hasattr(self, 'drop_lab'):
self.drop_lab.forget()
if hasattr(self, 'drops_tab') and self.drops_tab.winfo_ismapped():
self.drops_tab.forget()
self.root.config(borderwidth=2, relief='raised', height=405, width=240)
self.tabcontrol.add(self.drops_tab, text='Drops')
self.tabcontrol.insert(1, self.drops_tab)
self.drops_tab.m.config(height=8, width=23)
self.root.config(height=self.root.winfo_height()-174)
self.show_drops_tab_below = show
self.img_panel.focus_force()

def toggle_advanced_stats_frame(self, show=None):
if self.automode != 2:
show = False
self.advanced_stats_caret.toggle_image(active=False)
tracker_height = 300
if show is None:
show = self.advanced_stats_caret.active
if show:
self.root.update()
self.root.config(height=self.root.winfo_height()+tracker_height)
self.advanced_stats_tracker.pack()
self.advanced_stats_tracker.update_loop()
else:
if hasattr(self.advanced_stats_tracker, 'after_updater'):
self.advanced_stats_tracker.forget()
self.root.config(height=self.root.winfo_height()-tracker_height)
self.advanced_stats_tracker.after_cancel(self.advanced_stats_tracker.after_updater)
delattr(self.advanced_stats_tracker, 'after_updater')

def process_queue(self):
"""
Expand Down
Binary file added media/caret-down.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 media/caret-up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 12 additions & 15 deletions tabs/drops.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,25 @@


class Drops(tkd.Frame):
def __init__(self, main_frame, parent=None, **kw):
tkd.Frame.__init__(self, parent.root, kw)
self.parent = parent
def __init__(self, main_frame, parent, **kw):
tkd.Frame.__init__(self, parent, **kw)
self.drops = dict()
self.main_frame = main_frame

self._make_widgets()

def _make_widgets(self):
tkd.Label(self, text='Drops', font='helvetica 14').pack()
lf = tkd.Frame(self)
lf.pack(expand=1, fill=tk.BOTH)
scrollbar = ttk.Scrollbar(lf, orient=tk.VERTICAL)

self.m = tkd.Text(lf, height=5, yscrollcommand=scrollbar.set, font='courier 11', wrap=tk.WORD, state=tk.DISABLED, cursor='', exportselection=1, name='droplist')
self.m = tkd.Text(lf, height=8, width=23, yscrollcommand=scrollbar.set, font='courier 11', wrap=tk.WORD, state=tk.DISABLED, cursor='', exportselection=1, name='droplist', borderwidth=2)

self.m.pack(side=tk.LEFT, fill=tk.BOTH, expand=1, pady=(2, 1), padx=1)
self.m.pack(side=tk.LEFT, fill=tk.BOTH, expand=1, pady=(1, 2), padx=1)
scrollbar.config(command=self.m.yview)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y, pady=(2, 1), padx=0)

btn = tkd.Button(self, text='Delete selection', command=self.delete)
self.m.bind('<Delete>', lambda e: self.delete())
btn.pack(side=tk.BOTTOM, pady=(1, 2))

def add_drop(self):
drop = autocompletion.acbox(enable=True, title='Add drop')
if not drop or drop['input'] == '':
Expand All @@ -36,10 +32,11 @@ def add_drop(self):
if item['Item'] == drop['item_name']:
if item.get('Found', False) is False:
if self.main_frame.auto_upload_herokuapp:
resp = self.main_frame.grail_tab.upload_to_herokuapp(upd_dict={item['Item']: True},
show_confirm=False,
pop_up_msg="Congrats, a new drop! Add it to grail?\n\nHerokuapp login info:",
pop_up_title="Grail item")
resp = self.main_frame.grail_tab.upload_to_herokuapp(
upd_dict={item['Item']: True},
show_confirm=False,
pop_up_msg="Congrats, a new drop! Add it to grail?\n\nHerokuapp login info:",
pop_up_title="Grail item")
else:
resp = tk_utils.mbox(msg="Congrats, a new drop! Add it to local grail?", title="Grail item")
if resp is not None:
Expand All @@ -63,7 +60,7 @@ def display_drop(self, drop, run_no):
self.m.yview_moveto(1)
self.m.config(state=tk.DISABLED)

def delete(self):
def delete_selected_drops(self):
if self.focus_get()._name == 'droplist':
cur_row = self.m.get('insert linestart', 'insert lineend+1c').strip()
resp = tk_utils.mbox(msg='Do you want to delete the row:\n%s' % cur_row, title='Warning')
Expand All @@ -79,7 +76,7 @@ def delete(self):
except StopIteration:
pass

self.parent.img_panel.focus_force()
self.main_frame.img_panel.focus_force()

def save_state(self):
return dict(drops=self.drops)
Expand Down
7 changes: 4 additions & 3 deletions tabs/mf_timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _make_widgets(self):
self.m = tkd.Listbox(lf0, selectmode=tk.BROWSE, height=5, yscrollcommand=scrollbar.set, font='courier 12', activestyle=tk.NONE)
self.m.bind('<FocusOut>', lambda e: self.m.selection_clear(0, tk.END))
self.m.bind('<MouseWheel>', lambda e: self.m.yview_scroll(int(-1 * (e.delta / 120)), "units"))
self.m.bind('<Delete>', lambda e: self.delete_selected_run())
# self.m.bind('<Delete>', lambda e: self.delete_selected_run())
# self.m.bindtags((self.m, self, "all"))
self.m.pack(side=tk.LEFT, fill=tk.BOTH, expand=True, pady=5)
scrollbar.config(command=self.m.yview)
Expand Down Expand Up @@ -199,9 +199,10 @@ def delete_prev(self):
self._set_average()

def delete_selected_run(self):
if not self.m.curselection():
return
sel = self.m.selection_get()
resp = tk_utils.mbox(msg='Do you want to delete the run:\n%s' % sel, title='Warning')
if resp:
if tk_utils.mbox(msg='Do you want to delete the run:\n%s' % sel, title='Warning'):
all_runs = self.m.get(0, tk.END)
sel_idx = all_runs.index(sel)

Expand Down
Loading

0 comments on commit 4d20bc9

Please sign in to comment.