Gnumed.timelinelib.wxgui.setup

Package Gnumed :: Package timelinelib :: Package wxgui :: Module setup |
[frames] | no frames]

# Source Code for Module Gnumed.timelinelib.wxgui.setup

     1  # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018  Rickard Lindberg, Roger Lindberg
     2  #
     3  # This file is part of Timeline.
     4  #
     5  # Timeline is free software: you can redistribute it and/or modify
     6  # it under the terms of the GNU General Public License as published by
     7  # the Free Software Foundation, either version 3 of the License, or
     8  # (at your option) any later version.
     9  #
    10  # Timeline is distributed in the hope that it will be useful,
    11  # but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  # GNU General Public License for more details.
    14  #
    15  # You should have received a copy of the GNU General Public License
    16  # along with Timeline.  If not, see <http://www.gnu.org/licenses/>.
    17
    18
    19  from sys import version as python_version
    20  import platform
    21  import sys
    22  import traceback
    23  import locale
    24
    25  import wx
    26
    27  from timelinelib.meta.version import get_full_version
    28  from timelinelib.wxgui.frames.mainframe.mainframe import MainFrame
    29  from timelinelib.wxgui.dialogs.feedback.view import show_feedback_dialog
    30
    31
    32 -def setup_humblewx():
    33      import timelinelib.wxgui.components
    34      import humblewx
    35      humblewx.COMPONENT_MODULES.insert(0, timelinelib.wxgui.components)
    36
    37
    38 -def start_wx_application(application_arguments, before_main_loop_hook=None):
    39      app = wx.App(False)
    40      main_frame = MainFrame(application_arguments)
    41      main_frame.Show()
    42      sys.excepthook = unhandled_exception_hook
    43      if before_main_loop_hook:
    44          before_main_loop_hook()
    45      app.MainLoop()
    46
    47
    48 -def unhandled_exception_hook(exception_type, value, tb):
    49      show_feedback_dialog(
    50          parent=None,
    51          info=create_info_message(),
    52          subject=create_subject(exception_type, value),
    53          body=create_error_message(exception_type, value, tb))
    54
    55
    56 -def create_info_message():
    57      return ("An unexpected error has occurred. Help us fix it by reporting "
    58              "the error through this form. ")
    59
    60
    61 -def create_subject(exception_type, value):
    62      return "".join(traceback.format_exception_only(exception_type, value)).strip()
    63
    64
    65 -def create_error_message(exception_type, value, tb):
    66      return "\n".join([
    67          "Stacktrace:",
    68          "",
    69          indent(("".join(traceback.format_exception(exception_type, value, tb))).strip()),
    70          "",
    71          "Environment:",
    72          "",
    73          indent(create_versions_message()),
    74          indent(create_locale_message()),
    75      ])
    76
    77
    78 -def create_versions_message():
    79      return "\n".join([
    80          "Timeline version: %s" % get_full_version(),
    81          "System version: %s" % ", ".join(platform.uname()),
    82          "Python version: %s" % python_version.replace("\n", ""),
    83          "wxPython version: %s" % wx.version(),
    84      ])
    85
    86
    87 -def create_locale_message():
    88      return "\n".join([
    89          "Locale setting: %s" % " ".join(locale.getlocale(locale.LC_TIME)),
    90          "Locale sample date: 3333-11-22",
    91      ])
    92
    93
    94 -def indent(text):
    95      return "\n".join("    " + x for x in text.split("\n"))
    96