Skip to content

Commit 192c969

Browse files
committed
log window
1 parent 07fafde commit 192c969

File tree

2 files changed

+62
-27
lines changed

2 files changed

+62
-27
lines changed

Diff for: src/log_window.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import wx
2+
3+
4+
class LogWindow(wx.Dialog):
5+
def __init__(self, parent, close_handler):
6+
wx.Dialog.__init__(self, parent, title="FestEngine Log", style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
7+
self.close_handler = close_handler
8+
main_sizer = wx.BoxSizer(wx.VERTICAL)
9+
10+
self.text_ctrl = wx.TextCtrl(self, style=wx.TE_READONLY | wx.TE_MULTILINE)
11+
main_sizer.Add(self.text_ctrl, 1, wx.EXPAND)
12+
13+
self.SetSizer(main_sizer)
14+
self.Bind(wx.EVT_CLOSE, self.on_close)
15+
16+
def append(self, text):
17+
self.text_ctrl.AppendText(text)
18+
19+
def on_close(self, e):
20+
self.close_handler()
21+
self.Destroy()

Diff for: src/main.pyw

+41-27
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ from background_music_player import BackgroundMusicPlayer
2020
from constants import Config, Colors, Columns, FileTypes
2121
from projector import ProjectorWindow
2222
from settings import SettingsDialog
23+
from log_window import LogWindow
2324

2425
if sys.platform.startswith('linux'):
2526
try:
@@ -49,19 +50,14 @@ parser.add_argument('files_dir', nargs='*', help='Path to a directory with track
4950

5051
args = parser.parse_args()
5152

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
5259

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
6561

6662

6763
class MainFrame(wx.Frame):
@@ -75,6 +71,8 @@ class MainFrame(wx.Frame):
7571
self.settings = {Config.PROJECTOR_SCREEN: wx.Display.GetCount() - 1} # The last one
7672

7773
self.proj_win = None
74+
self.log_win = None
75+
self.log_text = "Init" + os.linesep
7876
self.filename_re = None
7977
self.grid_rows = None
8078
self.data = {}
@@ -114,9 +112,16 @@ class MainFrame(wx.Frame):
114112
with SettingsDialog(self.settings, self) as settings_dialog:
115113
if settings_dialog.ShowModal() == wx.ID_OK:
116114
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")
117118

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)
120125

121126
self.prefer_audio = menu_file.Append(wx.ID_ANY, "&Prefer No Video (fallback)", kind=wx.ITEM_CHECK)
122127
self.prefer_audio.Check(False)
@@ -316,6 +321,14 @@ class MainFrame(wx.Frame):
316321
self.vlc_instance.release()
317322
self.Destroy()
318323

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+
319332
def grid_set_shape(self, new_rows, new_cols, readonly_cols=None):
320333
current_rows, current_cols = self.grid.GetNumberRows(), self.grid.GetNumberCols()
321334
if current_rows > 0:
@@ -499,7 +512,7 @@ class MainFrame(wx.Frame):
499512
ext = ext.lower() # Never forget doing this!
500513
match = re.search(self.filename_re, name)
501514
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)
503516
num = match.group('num')
504517

505518
if num not in self.data:
@@ -509,7 +522,7 @@ class MainFrame(wx.Frame):
509522
value = match.group(group)
510523
if value and group != 'num':
511524
if group in self.data[num] and self.data[num][group] != value:
512-
print("[WARNING] Inconsistent value '%s': changing '%s' to '%s'.\n\t\tItem: %s" %
525+
self.log("[WARNING] Inconsistent value '%s': changing '%s' to '%s'.\n\t\tItem: %s" %
513526
(group, self.data[num][group], value, str(self.data[num])))
514527
self.data[num][group] = value
515528

@@ -520,7 +533,7 @@ class MainFrame(wx.Frame):
520533
self.data[num]['files'][ext] = file_path
521534
else:
522535
msg = "Duplicate files were found:\n%s\nConflicts with: %s" % (file_path, self.data[num])
523-
print('[!!! ALERT !!!] ' + msg)
536+
self.log('[!!! ALERT !!!] ' + msg)
524537
wx.MessageBox('ALERT !!!\n' + msg, "Duplicate files alert", wx.OK | wx.ICON_ERROR)
525538

526539
self.grid_set_shape(len(self.data), len(self.grid_rows))
@@ -738,7 +751,7 @@ class MainFrame(wx.Frame):
738751
return functools.reduce(lambda a, b: a or b, [self.search_box.GetValue().lower() in cell.lower()
739752
for cell in row['cols']])
740753

741-
filtered_grid_data = filter(match, self.full_grid_data)
754+
filtered_grid_data = list(filter(match, self.full_grid_data))
742755
found = bool(filtered_grid_data)
743756
if found:
744757
self.grid_set_data(filtered_grid_data, self.grid_default_bg_color, True)
@@ -781,13 +794,14 @@ class MainFrame(wx.Frame):
781794
num = self.get_num(self.grid.GetGridCursorRow())
782795
try:
783796
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+
785799
if video_files and not self.prefer_audio.IsChecked():
786-
file_path = video_files[0][1]
800+
file_path = video_files[0]
787801
sound_only = False
788802
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)
791805
except IndexError:
792806
self.player_status = u"Nothing to play for №%s" % num
793807
return
@@ -809,7 +823,7 @@ class MainFrame(wx.Frame):
809823
def play_sync(self, target_vol, sound_only):
810824
if not sound_only:
811825
while not self.set_vlc_video_panel():
812-
print("Trying to get video panel handler...")
826+
self.log("Trying to get video panel handler...")
813827

814828
if self.player.play() != 0: # [Play] button is pushed here!
815829
wx.CallAfter(lambda: self.set_player_status('Playback FAILED !!!'))
@@ -822,10 +836,10 @@ class MainFrame(wx.Frame):
822836
status = "%s [%.3fs]" % (self.player_state_parse(state), (time.time() - start))
823837
wx.CallAfter(lambda: self.set_player_status(status))
824838
if debug_output:
825-
print(status)
839+
self.log(status)
826840
time.sleep(0.007)
827841
if debug_output:
828-
print("Started playback in %.0fms" % ((time.time() - start) * 1000))
842+
self.log("Started playback in %.0fms" % ((time.time() - start) * 1000))
829843

830844
if not sound_only:
831845
wx.CallAfter(lambda: self.proj_win.Layout())
@@ -841,10 +855,10 @@ class MainFrame(wx.Frame):
841855
status = "Trying to unmute... [%.3fs]" % (time.time() - start)
842856
wx.CallAfter(lambda: self.set_player_status(status))
843857
if debug_output:
844-
print(status)
858+
self.log(status)
845859
time.sleep(0.001)
846860
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))
848862

849863
def ui_upd():
850864
self.player_status = '%s Vol:%d' % (self.player_state_parse(self.player.get_state()),

0 commit comments

Comments
 (0)