prompt window with logs on raised exception; minor UI updates; minor fixes

This commit is contained in:
Vasyl Horbachenko
2018-07-29 04:16:39 +03:00
parent 73d4a2d414
commit 9dbc9a8a56
25 changed files with 146 additions and 57 deletions

View File

@@ -1,3 +1,4 @@
import logging
import typing
import re
import threading
@@ -83,17 +84,16 @@ class Debriefing:
try:
components = event["initiator"].split("|")
print(components)
category, country_id, group_id, unit_type = components[0], int(components[1]), int(components[2]), db.unit_type_from_name(components[3])
if unit_type is None:
print("Skipped due to no unit type")
logging.info("Skipped due to no unit type")
continue
if category != "unit":
print("Skipped due to category")
logging.info("Skipped due to category")
continue
except Exception as e:
print(e)
logging.error(e)
continue
if country_id not in dead_units:

29
userdata/logging.py Normal file
View File

@@ -0,0 +1,29 @@
import logging
import traceback
from io import StringIO
from tkinter import *
from tkinter.scrolledtext import *
log_stream = StringIO()
logging.basicConfig(stream=log_stream, level=logging.INFO)
def _error_prompt():
tk = Tk()
Label(tk, text="Oops, something went wrong.").grid(row=0)
Label(tk, text="Please send following text to the developer:").grid(row=1)
text = ScrolledText(tk)
text.insert("0.0", log_stream.getvalue())
text.grid(row=2, sticky=NSEW)
tk.focus()
def _handle_exception(self, exception: BaseException, *args):
logging.exception(exception)
_error_prompt()
Tk.report_callback_exception = _handle_exception
logging.info("DCS Libration 1.13 RC2")

View File

@@ -1,3 +1,4 @@
import logging
import typing
import pickle
import os
@@ -56,5 +57,5 @@ def save_game(game) -> bool:
shutil.copy(_temporary_save_file(), _save_file())
return True
except Exception as e:
print(e)
logging.error(e)
return False