diff options
author | emkael <emkael@tlen.pl> | 2017-12-16 12:05:28 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2017-12-16 12:05:28 +0100 |
commit | 262b36a3e5b994247ccb624d527afff031a1e26c (patch) | |
tree | 3a49da6cb60ac9b3f03837a5b5fdc7e0b7f1e4a6 /src/bidding_data_gui.py | |
parent | 3a2f499648d7b45454c05fd353eb9cd097f4c079 (diff) |
Speeding up messages output for GUI version
Diffstat (limited to 'src/bidding_data_gui.py')
-rw-r--r-- | src/bidding_data_gui.py | 79 |
1 files changed, 52 insertions, 27 deletions
diff --git a/src/bidding_data_gui.py b/src/bidding_data_gui.py index ddd086b..fd07a7d 100644 --- a/src/bidding_data_gui.py +++ b/src/bidding_data_gui.py @@ -7,6 +7,7 @@ Graphical user interface to insert HTML tables with bidding data into traveller files generated by JFR Pary. """ +import copy import json import logging as log import os @@ -17,6 +18,8 @@ import threading import tkFileDialog import tkMessageBox +from threading import Lock + import Tkinter as tk from bidding_data import __version__ as bidding_data_version @@ -81,29 +84,7 @@ class BiddingGUI(tk.Frame): changed_files += parser.compress_bidding_files() if self.__variables['goniec_enabled'].get() == 1: parser.send_changed_files(changed_files) - - # inform of any warnings/errors that might have occuerd - if self.__gui_logger.errors(): - self.queue(res.play, 'error') - self.queue(self.log_field.insert, tk.END, - ('Podczas wykonywania programu wystąpiły błędy ' + - 'w liczbie: %d\n' + - 'Sprawdź dziennik logów\n') - % self.__gui_logger.errors()) - self.queue(self.log_field.yview, tk.END) - elif self.__gui_logger.warnings(): - self.queue(res.play, 'warning') - self.queue(self.log_field.insert, tk.END, - ('Podczas wykonywania programu wystąpiły ' + - 'ostrzeżenia w liczbie: %d\n' + - 'Sprawdź dziennik logów\n') - % self.__gui_logger.warnings()) - self.queue(self.log_field.yview, tk.END) - else: - self.queue(res.play, 'success') - self.queue(self.log_field.insert, tk.END, - 'Wszystko wporzo.\n') - self.queue(self.log_field.yview, tk.END) + self.__gui_logger.print_summary() except Exception as ex: # JFRBidding errors are logged # (and notified of after entire execution), @@ -536,14 +517,17 @@ class BiddingGUI(tk.Frame): """Construct the handler, provided Text widget to bind to.""" log.Handler.__init__(self) self.text = text + self.__messages_mutex = Lock() + self.__messages = [] + self.__messages_to_output = [] + self.text.master.queue(self.__output) def emit(self, record): """Output the message.""" msg = self.format(record) - # Append message to the Text widget, at the end.""" - self.text.master.queue(self.text.insert, tk.END, msg + '\n') - # scroll to the bottom, afterwards - self.text.master.queue(self.text.yview, tk.END) + self.__messages_mutex.acquire() + self.__messages.append(msg) + self.__messages_mutex.release() def handle(self, record): """Handle log message record (count errors/warnings).""" @@ -553,6 +537,19 @@ class BiddingGUI(tk.Frame): if record.levelname == 'ERROR': self.__error_count += 1 + def __output(self): + self.__messages_mutex.acquire() + self.__messages_to_output = copy.copy(self.__messages) + self.__messages = [] + self.__messages_mutex.release() + if len(self.__messages_to_output) > 0: + msg = '\n'.join(self.__messages_to_output).encode('utf8') + # Append message to the Text widget, at the end.""" + self.text.master.queue(self.text.insert, tk.END, msg + '\n') + # scroll to the bottom, afterwards + self.text.master.queue(self.text.yview, tk.END) + self.text.master.queue(self.__output) + # message stats, for summary purposes __warning_count = 0 __error_count = 0 @@ -567,10 +564,38 @@ class BiddingGUI(tk.Frame): def reset_counts(self): """Reset stats and log output.""" + self.__messages_mutex.acquire() + self.__messages_to_output = [] + self.__messages = [] + self.__messages_mutex.release() self.__warning_count = 0 self.__error_count = 0 self.text.master.queue(self.text.delete, 1.0, tk.END) + def print_summary(self): + self.__messages_mutex.acquire() + # inform of any warnings/errors that might have occuerd + if self.errors(): + self.__messages.append( + ('Podczas wykonywania programu wystąpiły błędy ' + + 'w liczbie: %d\n' + + 'Sprawdź dziennik logów\n').decode('utf8') + % self.errors()) + self.text.master.queue(res.play, 'error') + elif self.warnings(): + self.__messages.append( + ('Podczas wykonywania programu wystąpiły ' + + 'ostrzeżenia w liczbie: %d\n' + + 'Sprawdź dziennik logów\n').decode('utf8') + % self.warnings()) + self.text.master.queue(res.play, 'warning') + else: + self.__messages.append(self.text.insert, tk.END, + 'Wszystko wporzo.\n') + self.text.master.queue(res.play, 'success') + self.__messages_mutex.release() + + # disable default logging limits/thresholds log.basicConfig( level=log.NOTSET, |