Skip to content

Commit fb159dd

Browse files
committed
Moar Reeefactor
1 parent 77fb241 commit fb159dd

File tree

1 file changed

+63
-61
lines changed

1 file changed

+63
-61
lines changed

src/tauon/t_modules/t_main.py

Lines changed: 63 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,15 +1577,17 @@ class PlayerCtl:
15771577

15781578
# C-PC
15791579
def __init__(self, tauon: Tauon):
1580-
self.tauon = tauon
1581-
self.gui = self.tauon.gui
1582-
self.bag = self.tauon.bag
1583-
self.smtc: bool = self.tauon.bag.smtc
1584-
self.radiobox = self.tauon.radiobox
1585-
self.running: bool = True
1586-
self.prefs: Prefs = self.bag.prefs
1587-
self.lfm_scrobbler = LastScrob(tauon=self.tauon, pctl=self)
1588-
self.install_directory: Path = self.bag.dirs.install_directory
1580+
self.tauon = tauon
1581+
self.gui = self.tauon.gui
1582+
self.bag = self.tauon.bag
1583+
self.smtc: bool = self.tauon.bag.smtc
1584+
self.radiobox = self.tauon.radiobox
1585+
self.running: bool = True
1586+
self.prefs: Prefs = self.bag.prefs
1587+
self.lfm_scrobbler = LastScrob(tauon=self.tauon, pctl=self)
1588+
self.install_directory: Path = self.bag.dirs.install_directory
1589+
self.loading_in_progress: bool = False
1590+
15891591

15901592
# Database
15911593

@@ -5065,6 +5067,7 @@ def __init__(self, holder: Holder, bag: Bag, strings: Strings, gui: GuiVar):
50655067
self.move_jobs: list = []
50665068
self.to_scan: list = []
50675069
self.after_scan: list[TrackClass] = []
5070+
self.move_in_progress: bool = False
50685071
self.worker2_lock = threading.Lock()
50695072
#TODO(Martin) : Fix this by moving the class to root of the module
50705073
self.cachement: player4.Cachement | None = None
@@ -5124,7 +5127,13 @@ def __init__(self, holder: Holder, bag: Bag, strings: Strings, gui: GuiVar):
51245127
self.listen_alongers = {}
51255128
self.encode_folder_name = encode_folder_name
51265129
self.encode_track_name = encode_track_name
5130+
# Create top menu
5131+
self.x_menu = Menu(self, 190, show_icons=True)
5132+
self.set_menu = Menu(self, 150)
5133+
self.field_menu = Menu(self, 140)
5134+
self.dl_menu = Menu(self, 90)
51275135

5136+
self.cancel_menu = Menu(self, 100)
51285137

51295138
self.tray_lock = threading.Lock()
51305139
self.tray_releases = 0
@@ -13702,12 +13711,12 @@ def render(self):
1370213711
tr = pctl.playing_object()
1370313712
if tr:
1370413713
album_art_gen.display(tr, (window_size[0] - gui.panelY - 1, 0), (gui.panelY, gui.panelY))
13705-
if loading_in_progress or \
13714+
if pctl.loading_in_progress or \
1370613715
tauon.to_scan or \
1370713716
tauon.cm_clean_db or \
1370813717
lastfm.scanning_friends or \
13709-
bag.after_scan or \
13710-
move_in_progress or \
13718+
tauon.after_scan or \
13719+
tauon.move_in_progress or \
1371113720
plex.scanning or \
1371213721
transcode_list or tauon.spot_ctl.launching_spotify or tauon.spot_ctl.spotify_com or subsonic.scanning or \
1371313722
koel.scanning or gui.sync_progress or lastfm.scanning_scrobbles:
@@ -14340,20 +14349,20 @@ def render(self):
1434014349
hit = tauon.coll(rect)
1434114350
tauon.fields.add(rect)
1434214351

14343-
if (x_menu.active or hit) and not tab_menu.active:
14352+
if (tauon.x_menu.active or hit) and not tauon.tab_menu.active:
1434414353
bg = colours.status_text_over
1434514354
else:
1434614355
bg = colours.status_text_normal
1434714356
ddt.text((x, y), word, bg, 212)
1434814357

1434914358
if hit and inp.mouse_click:
14350-
if x_menu.active:
14351-
x_menu.active = False
14359+
if tauon.x_menu.active:
14360+
tauon.x_menu.active = False
1435214361
else:
1435314362
xx = x
1435414363
if x > window_size[0] - (210 * gui.scale):
1435514364
xx = window_size[0] - round(210 * gui.scale)
14356-
x_menu.activate(position=(xx + round(12 * gui.scale), gui.panelY))
14365+
tauon.x_menu.activate(position=(xx + round(12 * gui.scale), gui.panelY))
1435714366
view_box.activate(xx)
1435814367

1435914368
# if True:
@@ -14362,8 +14371,8 @@ def render(self):
1436214371
# rect = (5 * gui.scale, gui.panelY, round(90 * gui.scale), round(25 * gui.scale))
1436314372
#
1436414373

14365-
dl = len(dl_mon.ready)
14366-
watching = len(dl_mon.watching)
14374+
dl = len(tauon.dl_mon.ready)
14375+
watching = len(tauon.dl_mon.watching)
1436714376

1436814377
if (dl > 0 or watching > 0) and core_timer.get() > 2 and prefs.auto_extract and prefs.monitor_downloads:
1436914378
x += 52 * gui.scale
@@ -14376,11 +14385,11 @@ def render(self):
1437614385
# colour = [40, 40, 40, 255]
1437714386
if dl > 0 or watching > 0:
1437814387
if right_click:
14379-
dl_menu.activate(position=(inp.mouse_position[0], gui.panelY))
14388+
tauon.dl_menu.activate(position=(inp.mouse_position[0], gui.panelY))
1438014389
if dl > 0:
1438114390
if inp.mouse_click:
1438214391
pln = 0
14383-
for item in dl_mon.ready:
14392+
for item in tauon.dl_mon.ready:
1438414393
load_order = LoadClass()
1438514394
load_order.target = item
1438614395
pln = pctl.active_playlist_viewing
@@ -14401,8 +14410,8 @@ def render(self):
1440114410

1440214411
load_orders.append(copy.deepcopy(load_order))
1440314412

14404-
if len(dl_mon.ready) > 0:
14405-
dl_mon.ready.clear()
14413+
if len(tauon.dl_mon.ready) > 0:
14414+
tauon.dl_mon.ready.clear()
1440614415
switch_playlist(pln)
1440714416

1440814417
pctl.playlist_view_position = len(pctl.default_playlist)
@@ -14422,7 +14431,7 @@ def render(self):
1442214431
colour = colours.corner_button # [60, 60, 60, 255]
1442314432
if colours.lm:
1442414433
# colour = [180, 180, 180, 255]
14425-
if dl_mon.ready:
14434+
if tauon.dl_mon.ready:
1442614435
colour = colours.corner_button_active # [60, 60, 60, 255]
1442714436

1442814437
self.dl_button.render(x, y + 1 * gui.scale, colour)
@@ -14436,7 +14445,7 @@ def render(self):
1443614445
self.drag_zone_start_x = x - 5 * gui.scale
1443714446
status = True
1443814447

14439-
if loading_in_progress:
14448+
if pctl.loading_in_progress:
1444014449
bg = colours.status_info_text
1444114450
if to_got == "xspf":
1444214451
text = _("Importing XSPF playlist")
@@ -14447,12 +14456,12 @@ def render(self):
1444714456
else:
1444814457
text = _("Importing... ") + str(to_got) # + "/" + str(to_get)
1444914458
if right_click and tauon.coll([x, y, 180 * gui.scale, 18 * gui.scale]):
14450-
cancel_menu.activate(position=(x + 20 * gui.scale, y + 23 * gui.scale))
14451-
elif bag.after_scan:
14459+
tauon.cancel_menu.activate(position=(x + 20 * gui.scale, y + 23 * gui.scale))
14460+
elif tauon.after_scan:
1445214461
# bg = colours.status_info_text
1445314462
bg = [100, 200, 100, 255]
14454-
text = _("Scanning Tags... {N} remaining").format(N=str(len(bag.after_scan)))
14455-
elif move_in_progress:
14463+
text = _("Scanning Tags... {N} remaining").format(N=str(len(tauon.after_scan)))
14464+
elif tauon.move_in_progress:
1445614465
text = _("File copy in progress...")
1445714466
bg = colours.status_info_text
1445814467
elif tauon.cm_clean_db and to_get > 0:
@@ -19454,7 +19463,7 @@ def load_img(self, artist):
1945419463

1945519464
def worker(self):
1945619465
if self.load:
19457-
if bag.after_scan:
19466+
if tauon.after_scan:
1945819467
return
1945919468

1946019469
self.prep()
@@ -20128,7 +20137,7 @@ def render(self, x, y, w, h):
2012820137
text = _("Artist threshold not met")
2012920138
if self.load:
2013020139
text = _("Loading Artist List...")
20131-
if loading_in_progress or transcode_list or bag.after_scan:
20140+
if pctl.loading_in_progress or transcode_list or tauon.after_scan:
2013220141
text = _("Busy...")
2013320142

2013420143
ddt.text(
@@ -27288,7 +27297,7 @@ def cancel_import():
2728827297
if transcode_list:
2728927298
del transcode_list[1:]
2729027299
gui.tc_cancel = True
27291-
if loading_in_progress:
27300+
if pctl.loading_in_progress:
2729227301
gui.im_cancel = True
2729327302
if gui.sync_progress:
2729427303
gui.stop_sync = True
@@ -35232,7 +35241,6 @@ def worker2(tauon: Tauon) -> None:
3523235241
def worker1(tauon: Tauon) -> None:
3523335242
global cue_list
3523435243
global home
35235-
global loading_in_progress
3523635244
global added
3523735245
global to_get
3523835246
global to_got
@@ -35711,7 +35719,7 @@ def commit_track(nt):
3571135719
if prefs.auto_sort or force_scan:
3571235720
tag_scan(nt)
3571335721
else:
35714-
bag.after_scan.append(nt)
35722+
tauon.after_scan.append(nt)
3571535723
tauon.thread_manager.ready("worker")
3571635724

3571735725
pctl.master_count += 1
@@ -35826,7 +35834,6 @@ def cache_paths() -> tuple[dict, dict]:
3582635834
global album_art_gen
3582735835
global to_got
3582835836
global to_get
35829-
global move_in_progress
3583035837

3583135838
active_timer = Timer()
3583235839
while True:
@@ -35883,7 +35890,7 @@ def cache_paths() -> tuple[dict, dict]:
3588335890
gui.regen_single = -1
3588435891
regenerate_playlist(target, silent=True)
3588535892

35886-
if pctl.after_import_flag and not tauon.after_scan and not tauon.search_over.active and not loading_in_progress:
35893+
if pctl.after_import_flag and not tauon.after_scan and not tauon.search_over.active and not pctl.loading_in_progress:
3588735894
pctl.after_import_flag = False
3588835895

3588935896
for i, plist in enumerate(pctl.multi_playlist):
@@ -35902,13 +35909,13 @@ def cache_paths() -> tuple[dict, dict]:
3590235909

3590335910
if tauon.worker_save_state and \
3590435911
not gui.pl_pulse and \
35905-
not loading_in_progress and \
35912+
not pctl.loading_in_progress and \
3590635913
not tauon.to_scan and not tauon.after_scan and \
3590735914
not plex.scanning and \
3590835915
not jellyfin.scanning and \
3590935916
not tauon.cm_clean_db and \
3591035917
not lastfm.scanning_friends and \
35911-
not move_in_progress and \
35918+
not tauon.move_in_progress and \
3591235919
(gui.lowered or not window_is_focused() or not gui.mouse_in_window):
3591335920
save_state()
3591435921
cue_list.clear()
@@ -35917,21 +35924,21 @@ def cache_paths() -> tuple[dict, dict]:
3591735924
# Folder moving
3591835925
if len(tauon.move_jobs) > 0:
3591935926
gui.update += 1
35920-
move_in_progress = True
35927+
tauon.move_in_progress = True
3592135928
job = tauon.move_jobs[0]
3592235929
del tauon.move_jobs[0]
3592335930

3592435931
if job[0].strip("\\/") == job[1].strip("\\/"):
3592535932
show_message(_("Folder copy error."), _("The target and source are the same."), mode="info")
3592635933
gui.update += 1
35927-
move_in_progress = False
35934+
tauon.move_in_progress = False
3592835935
continue
3592935936

3593035937
try:
3593135938
shutil.copytree(job[0], job[1])
3593235939
except Exception:
3593335940
logging.exception("Failed to copy directory")
35934-
move_in_progress = False
35941+
tauon.move_in_progress = False
3593535942
gui.update += 1
3593635943
show_message(_("The folder copy has failed!"), _("Some files may have been written."), mode="warning")
3593735944
continue
@@ -35944,14 +35951,14 @@ def cache_paths() -> tuple[dict, dict]:
3594435951
logging.exception("Failed to delete directory")
3594535952
show_message(_("Something has gone horribly wrong!"), _("Could not delete {name}").format(name=job[0]), mode="error")
3594635953
gui.update += 1
35947-
move_in_progress = False
35954+
tauon.move_in_progress = False
3594835955
return
3594935956

3595035957
show_message(_("Folder move complete."), _("Folder name: {name}").format(name=job[3]), mode="done")
3595135958
else:
3595235959
show_message(_("Folder copy complete."), _("Folder name: {name}").format(name=job[3]), mode="done")
3595335960

35954-
move_in_progress = False
35961+
tauon.move_in_progress = False
3595535962
load_orders.append(job[4])
3595635963
gui.update += 1
3595735964

@@ -38610,7 +38617,7 @@ def save_state() -> None:
3861038617
prefs.bg_showcase_only,
3861138618
None, # prefs.discogs_pat,
3861238619
prefs.mini_mode_mode,
38613-
bag.after_scan,
38620+
tauon.after_scan,
3861438621
gui.gallery_positions,
3861538622
prefs.chart_bg,
3861638623
prefs.left_panel_mode,
@@ -39549,8 +39556,6 @@ def main(holder: Holder):
3954939556
playlist_view_position = 0
3955039557
playlist_playing = -1
3955139558

39552-
loading_in_progress = False
39553-
3955439559
core_use = 0
3955539560
dl_use = 0
3955639561

@@ -40043,7 +40048,7 @@ def main(holder: Holder):
4004340048
if save[130] is not None:
4004440049
prefs.mini_mode_mode = save[130]
4004540050
if save[131] is not None:
40046-
bag.after_scan = save[131]
40051+
tauon.after_scan = save[131]
4004740052
if save[132] is not None:
4004840053
gui.gallery_positions = save[132]
4004940054
if save[133] is not None:
@@ -40893,7 +40898,7 @@ def update(self, force=False):
4089340898
radio_entry_menu = Menu(tauon, 125)
4089440899
showcase_menu = Menu(tauon, 135)
4089540900
center_info_menu = Menu(tauon, 125)
40896-
cancel_menu = Menu(tauon, 100)
40901+
cancel_menu = tauon.cancel_menu
4089740902
gallery_menu = Menu(tauon, 175, show_icons=True)
4089840903
artist_info_menu = Menu(tauon, 135)
4089940904
queue_menu = Menu(tauon, 150)
@@ -40966,8 +40971,6 @@ def update(self, force=False):
4096640971

4096740972
power_bar_icon = asset_loader(bag, loaded_asset_dc, "power.png", True)
4096840973

40969-
move_in_progress = False
40970-
4097140974
folder_tree_stem_menu.add(MenuItem(_("Open Folder"), open_folder_stem, pass_ref=True, icon=folder_icon))
4097240975
folder_tree_menu.add(MenuItem(_("Open Folder"), open_folder, pass_ref=True, pass_ref_deco=True, icon=folder_icon, disable_test=open_folder_disable_test))
4097340976

@@ -41457,16 +41460,15 @@ def update(self, force=False):
4145741460

4145841461

4145941462
# Create top menu
41460-
x_menu = Menu(tauon, 190, show_icons=True)
41463+
x_menu = tauon.x_menu
41464+
set_menu = tauon.set_menu
41465+
field_menu = tauon.field_menu
41466+
dl_menu = tauon.dl_menu
4146141467
view_menu = Menu(tauon, 170)
41462-
set_menu = Menu(tauon, 150)
4146341468
set_menu_hidden = Menu(tauon, 100)
4146441469
vis_menu = Menu(tauon, 140)
4146541470
window_menu = Menu(tauon, 140)
41466-
field_menu = Menu(tauon, 140)
41467-
dl_menu = Menu(tauon, 90)
4146841471

41469-
window_menu = Menu(tauon, 140)
4147041472
window_menu.add(MenuItem(_("Minimize"), do_minimize_button))
4147141473
window_menu.add(MenuItem(_("Maximize"), do_maximize_button))
4147241474
window_menu.add(MenuItem(_("Exit"), do_exit_button))
@@ -43331,7 +43333,7 @@ def dev_mode_disable_save_state() -> None:
4333143333
inp.media_key = ""
4333243334

4333343335
if len(load_orders) > 0:
43334-
loading_in_progress = True
43336+
pctl.loading_in_progress = True
4333543337
pctl.after_import_flag = True
4333643338
tauon.thread_manager.ready("worker")
4333743339
if tauon.loaderCommand == tauon.LC_None:
@@ -43371,28 +43373,28 @@ def dev_mode_disable_save_state() -> None:
4337143373
tauon.thread_manager.ready("worker")
4337243374
break
4337343375

43374-
elif loading_in_progress is True:
43375-
loading_in_progress = False
43376+
elif pctl.loading_in_progress is True:
43377+
pctl.loading_in_progress = False
4337643378
pctl.notify_change()
4337743379

4337843380
if tauon.loaderCommand == tauon.LC_Done:
4337943381
tauon.loaderCommand = tauon.LC_None
4338043382
gui.update += 1
4338143383
# gui.pl_update = 1
43382-
# loading_in_progress = False
43384+
# pctl.loading_in_progress = False
4338343385

4338443386
if update_layout:
4338543387
update_layout_do(tauon=tauon)
4338643388
update_layout = False
4338743389

4338843390
# if tauon.worker_save_state and\
4338943391
# not gui.pl_pulse and\
43390-
# not loading_in_progress and\
43392+
# not pctl.loading_in_progress and\
4339143393
# not tauon.to_scan and\
4339243394
# not plex.scanning and\
4339343395
# not tauon.cm_clean_db and\
4339443396
# not lastfm.scanning_friends and\
43395-
# not move_in_progress:
43397+
# not tauon.move_in_progress:
4339643398
# save_state()
4339743399
# cue_list.clear()
4339843400
# tauon.worker_save_state = False
@@ -44547,7 +44549,7 @@ def dev_mode_disable_save_state() -> None:
4454744549
year_sort(target_pl)
4454844550

4454944551
if not load_orders:
44550-
loading_in_progress = False
44552+
pctl.loading_in_progress = False
4455144553
pctl.notify_change()
4455244554
gui.auto_play_import = False
4455344555
album_artist_dict.clear()

0 commit comments

Comments
 (0)