@@ -20,6 +20,7 @@ from background_music_player import BackgroundMusicPlayer
20
20
from constants import Config , Colors , Columns , FileTypes
21
21
from projector import ProjectorWindow
22
22
from settings import SettingsDialog
23
+ from log_window import LogWindow
23
24
24
25
if sys .platform .startswith ('linux' ):
25
26
try :
@@ -49,19 +50,14 @@ parser.add_argument('files_dir', nargs='*', help='Path to a directory with track
49
50
50
51
args = parser .parse_args ()
51
52
53
+ filename_re = args .filename_re
54
+ background_zad_path = args .background_zad_path
55
+ background_tracks_dir = args .background_tracks_dir
56
+ debug_output = args .debug_output
57
+ auto_load_files = args .auto_load_files
58
+ auto_load_bg = args .auto_load_bg
52
59
53
- def fix_encoding (path ):
54
- return path .decode (sys .getfilesystemencoding ()) if path and isinstance (path , str ) else path
55
-
56
-
57
- filename_re = fix_encoding (args .filename_re )
58
- background_zad_path = fix_encoding (args .background_zad_path )
59
- background_tracks_dir = fix_encoding (args .background_tracks_dir )
60
- debug_output = fix_encoding (args .debug_output )
61
- auto_load_files = fix_encoding (args .auto_load_files )
62
- auto_load_bg = fix_encoding (args .auto_load_bg )
63
-
64
- dirs = set (fix_encoding (d ) for d in args .files_dir )
60
+ dirs = args .files_dir
65
61
66
62
67
63
class MainFrame (wx .Frame ):
@@ -75,6 +71,8 @@ class MainFrame(wx.Frame):
75
71
self .settings = {Config .PROJECTOR_SCREEN : wx .Display .GetCount () - 1 } # The last one
76
72
77
73
self .proj_win = None
74
+ self .log_win = None
75
+ self .log_text = "Init" + os .linesep
78
76
self .filename_re = None
79
77
self .grid_rows = None
80
78
self .data = {}
@@ -114,9 +112,16 @@ class MainFrame(wx.Frame):
114
112
with SettingsDialog (self .settings , self ) as settings_dialog :
115
113
if settings_dialog .ShowModal () == wx .ID_OK :
116
114
self .settings = settings_dialog .settings
115
+ self .Bind (wx .EVT_MENU , on_settings , menu_file .Append (wx .ID_ANY , "&Settings" ))
116
+
117
+ show_log_menu_item = menu_file .Append (wx .ID_ANY , "&Show Log" )
117
118
118
- self .Bind (wx .EVT_MENU , on_settings ,
119
- menu_file .Append (wx .ID_ANY , "&Settings" ))
119
+ def on_log (e ):
120
+ self .log_win = LogWindow (self , lambda : show_log_menu_item .Enable (True ))
121
+ self .log_win .Show ()
122
+ self .log_win .append (self .log_text )
123
+ show_log_menu_item .Enable (False )
124
+ self .Bind (wx .EVT_MENU , on_log , show_log_menu_item )
120
125
121
126
self .prefer_audio = menu_file .Append (wx .ID_ANY , "&Prefer No Video (fallback)" , kind = wx .ITEM_CHECK )
122
127
self .prefer_audio .Check (False )
@@ -316,6 +321,14 @@ class MainFrame(wx.Frame):
316
321
self .vlc_instance .release ()
317
322
self .Destroy ()
318
323
324
+ def log (self , msg ):
325
+ self .log_text += msg + os .linesep
326
+ try :
327
+ if self .log_win .ClassName == u'wxDialog' :
328
+ self .log_win .append (msg + os .linesep )
329
+ except (AttributeError , RuntimeError ):
330
+ return
331
+
319
332
def grid_set_shape (self , new_rows , new_cols , readonly_cols = None ):
320
333
current_rows , current_cols = self .grid .GetNumberRows (), self .grid .GetNumberCols ()
321
334
if current_rows > 0 :
@@ -499,7 +512,7 @@ class MainFrame(wx.Frame):
499
512
ext = ext .lower () # Never forget doing this!
500
513
match = re .search (self .filename_re , name )
501
514
if not match :
502
- print ("[WARNING] File %s does not match filename_re" % file_path )
515
+ self . log ("[WARNING] File %s does not match filename_re" % file_path )
503
516
num = match .group ('num' )
504
517
505
518
if num not in self .data :
@@ -509,7 +522,7 @@ class MainFrame(wx.Frame):
509
522
value = match .group (group )
510
523
if value and group != 'num' :
511
524
if group in self .data [num ] and self .data [num ][group ] != value :
512
- print ("[WARNING] Inconsistent value '%s': changing '%s' to '%s'.\n \t \t Item: %s" %
525
+ self . log ("[WARNING] Inconsistent value '%s': changing '%s' to '%s'.\n \t \t Item: %s" %
513
526
(group , self .data [num ][group ], value , str (self .data [num ])))
514
527
self .data [num ][group ] = value
515
528
@@ -520,7 +533,7 @@ class MainFrame(wx.Frame):
520
533
self .data [num ]['files' ][ext ] = file_path
521
534
else :
522
535
msg = "Duplicate files were found:\n %s\n Conflicts with: %s" % (file_path , self .data [num ])
523
- print ('[!!! ALERT !!!] ' + msg )
536
+ self . log ('[!!! ALERT !!!] ' + msg )
524
537
wx .MessageBox ('ALERT !!!\n ' + msg , "Duplicate files alert" , wx .OK | wx .ICON_ERROR )
525
538
526
539
self .grid_set_shape (len (self .data ), len (self .grid_rows ))
@@ -738,7 +751,7 @@ class MainFrame(wx.Frame):
738
751
return functools .reduce (lambda a , b : a or b , [self .search_box .GetValue ().lower () in cell .lower ()
739
752
for cell in row ['cols' ]])
740
753
741
- filtered_grid_data = filter (match , self .full_grid_data )
754
+ filtered_grid_data = list ( filter (match , self .full_grid_data ) )
742
755
found = bool (filtered_grid_data )
743
756
if found :
744
757
self .grid_set_data (filtered_grid_data , self .grid_default_bg_color , True )
@@ -781,13 +794,14 @@ class MainFrame(wx.Frame):
781
794
num = self .get_num (self .grid .GetGridCursorRow ())
782
795
try :
783
796
files = self .data [num ]['files' ].items () # (ext, path)
784
- video_files = filter (lambda a : a [0 ] in FileTypes .video_extensions , files )
797
+ video_files = [file [1 ] for file in files if file [0 ] in FileTypes .video_extensions ]
798
+
785
799
if video_files and not self .prefer_audio .IsChecked ():
786
- file_path = video_files [0 ][ 1 ]
800
+ file_path = video_files [0 ]
787
801
sound_only = False
788
802
else :
789
- audio_files = filter ( lambda a : a [0 ] in FileTypes .audio_extensions , files )
790
- file_path , sound_only = (audio_files [0 ][ 1 ] , True ) if audio_files else (video_files [0 ][ 1 ], False )
803
+ audio_files = [ file [ 1 ] for file in files if file [0 ] in FileTypes .audio_extensions ]
804
+ file_path , sound_only = (audio_files [0 ], True ) if audio_files else (video_files [0 ], False )
791
805
except IndexError :
792
806
self .player_status = u"Nothing to play for №%s" % num
793
807
return
@@ -809,7 +823,7 @@ class MainFrame(wx.Frame):
809
823
def play_sync (self , target_vol , sound_only ):
810
824
if not sound_only :
811
825
while not self .set_vlc_video_panel ():
812
- print ("Trying to get video panel handler..." )
826
+ self . log ("Trying to get video panel handler..." )
813
827
814
828
if self .player .play () != 0 : # [Play] button is pushed here!
815
829
wx .CallAfter (lambda : self .set_player_status ('Playback FAILED !!!' ))
@@ -822,10 +836,10 @@ class MainFrame(wx.Frame):
822
836
status = "%s [%.3fs]" % (self .player_state_parse (state ), (time .time () - start ))
823
837
wx .CallAfter (lambda : self .set_player_status (status ))
824
838
if debug_output :
825
- print (status )
839
+ self . log (status )
826
840
time .sleep (0.007 )
827
841
if debug_output :
828
- print ("Started playback in %.0fms" % ((time .time () - start ) * 1000 ))
842
+ self . log ("Started playback in %.0fms" % ((time .time () - start ) * 1000 ))
829
843
830
844
if not sound_only :
831
845
wx .CallAfter (lambda : self .proj_win .Layout ())
@@ -841,10 +855,10 @@ class MainFrame(wx.Frame):
841
855
status = "Trying to unmute... [%.3fs]" % (time .time () - start )
842
856
wx .CallAfter (lambda : self .set_player_status (status ))
843
857
if debug_output :
844
- print (status )
858
+ self . log (status )
845
859
time .sleep (0.001 )
846
860
if debug_output and status [0 ] == 'T' :
847
- print ("Unmuted in %.0fms" % ((time .time () - start ) * 1000 ))
861
+ self . log ("Unmuted in %.0fms" % ((time .time () - start ) * 1000 ))
848
862
849
863
def ui_upd ():
850
864
self .player_status = '%s Vol:%d' % (self .player_state_parse (self .player .get_state ()),
0 commit comments