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
     24  import wx
     25
     26  from timelinelib.meta.version import get_full_version
     27  from timelinelib.wxgui.frames.mainframe.mainframe import MainFrame
     28  from timelinelib.wxgui.dialogs.feedback.view import show_feedback_dialog
     29
     30
     31 -def setup_humblewx():
     32      import timelinelib.wxgui.components
     33      import humblewx
     34      humblewx.COMPONENT_MODULES.insert(0, timelinelib.wxgui.components)
     35
     36
     37 -def start_wx_application(application_arguments, before_main_loop_hook=None):
     38      app = wx.App(False)
     39      main_frame = MainFrame(application_arguments)
     40      main_frame.Show()
     41      sys.excepthook = unhandled_exception_hook
     42      if before_main_loop_hook:
     43          before_main_loop_hook()
     44      app.MainLoop()
     45
     46
     47 -def unhandled_exception_hook(exception_type, value, tb):
     48      show_feedback_dialog(
     49          parent=None,
     50          info=create_info_message(),
     51          subject=create_subject(exception_type, value),
     52          body=create_error_message(exception_type, value, tb))
     53
     54
     55 -def create_info_message():
     56      return ("An unexpected error has occurred. Help us fix it by reporting "
     57              "the error through this form. ")
     58
     59
     60 -def create_subject(exception_type, value):
     61      return "".join(traceback.format_exception_only(exception_type, value)).strip()
     62
     63
     64 -def create_error_message(exception_type, value, tb):
     65      return "\n".join([
     66          "Stacktrace:",
     67          "",
     68          indent(("".join(traceback.format_exception(exception_type, value, tb))).strip()),
     69          "",
     70          "Environment:",
     71          "",
     72          indent(create_versions_message()),
     73          indent(create_locale_message()),
     74      ])
     75
     76
     77 -def create_versions_message():
     78      return "\n".join([
     79          "Timeline version: %s" % get_full_version(),
     80          "System version: %s" % ", ".join(platform.uname()),
     81          "Python version: %s" % python_version.replace("\n", ""),
     82          "wxPython version: %s" % wx.version(),
     83      ])
     84
     85
     86 -def create_locale_message():
     87      loc = wx.Locale()
     88      language_name = loc.GetLanguageName(loc.GetSystemLanguage())
     89      encoding_name = loc.GetSystemEncodingName()
     90      locale_info = '%s %s' % (language_name, encoding_name)
     91      return "\n".join([
     92          "Locale setting: %s" % locale_info,
     93          "Locale sample date: 3333-11-22",
     94      ])
     95
     96
     97 -def indent(text):
     98      return "\n".join("    " + x for x in text.split("\n"))
     99