| 1 | #!/usr/bin/env python |
|---|
| 2 | # -*- coding: utf-8 -*- |
|---|
| 3 | # Copyright (C) 2008 Adriano Monteiro Marques |
|---|
| 4 | # |
|---|
| 5 | # Author: Francesco Piccinno <stack.box@gmail.com> |
|---|
| 6 | # |
|---|
| 7 | # This program is free software; you can redistribute it and/or modify |
|---|
| 8 | # it under the terms of the GNU General Public License as published by |
|---|
| 9 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | # (at your option) any later version. |
|---|
| 11 | # |
|---|
| 12 | # This program is distributed in the hope that it will be useful, |
|---|
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | # GNU General Public License for more details. |
|---|
| 16 | # |
|---|
| 17 | # You should have received a copy of the GNU General Public License |
|---|
| 18 | # along with this program; if not, write to the Free Software |
|---|
| 19 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | |
|---|
| 21 | import os |
|---|
| 22 | import sys |
|---|
| 23 | import signal |
|---|
| 24 | |
|---|
| 25 | # used by exception hook |
|---|
| 26 | import cgitb |
|---|
| 27 | import tempfile |
|---|
| 28 | |
|---|
| 29 | from umitCore.I18N import _ |
|---|
| 30 | from umitCore.Version import VERSION |
|---|
| 31 | ######################### |
|---|
| 32 | |
|---|
| 33 | UMIT_DEVELOPMENT = os.environ.get("UMIT_DEVELOPMENT", True) |
|---|
| 34 | |
|---|
| 35 | class UmitExceptionHook(object): |
|---|
| 36 | def __call__(self, etype, emsg, etb): |
|---|
| 37 | import warnings |
|---|
| 38 | warnings.filterwarnings("error", module = "gtk") |
|---|
| 39 | try: |
|---|
| 40 | import gtk |
|---|
| 41 | import pango |
|---|
| 42 | from higwidgets.higdialogs import HIGAlertDialog |
|---|
| 43 | except Warning, e: |
|---|
| 44 | print e.message |
|---|
| 45 | sys.exit(-1) |
|---|
| 46 | warnings.resetwarnings() |
|---|
| 47 | |
|---|
| 48 | if etype == ImportError: |
|---|
| 49 | d = HIGAlertDialog(type=gtk.MESSAGE_ERROR, |
|---|
| 50 | message_format=_("Import error"), |
|---|
| 51 | secondary_text=_("\nA required module was not " |
|---|
| 52 | "found.\n\nError: %s" % emsg)) |
|---|
| 53 | d.run() |
|---|
| 54 | d.destroy() |
|---|
| 55 | return |
|---|
| 56 | |
|---|
| 57 | crash_text = cgitb.text((etype, emsg, etb)) |
|---|
| 58 | extrainfo = "%-17s %s\n%-17s %s\n%-17s %s\n%-17s %s\n" % ( |
|---|
| 59 | "sys.platform", sys.platform, "os.name", os.name, |
|---|
| 60 | "Gtk version", '.'.join(map(str, gtk.gtk_version)), |
|---|
| 61 | "Umit version", VERSION) |
|---|
| 62 | crashmsg = "Crash Report\n%s\n%s\nDescription\n%s\n%s" % ('=' * 10, |
|---|
| 63 | extrainfo, '-' * 20, crash_text) |
|---|
| 64 | |
|---|
| 65 | d = HIGAlertDialog(type=gtk.MESSAGE_ERROR, |
|---|
| 66 | message_format=_("Fatal exception"), |
|---|
| 67 | secondary_text=_("\nException:\n")) |
|---|
| 68 | |
|---|
| 69 | view = gtk.TextView() |
|---|
| 70 | view.get_buffer().set_text(crashmsg) |
|---|
| 71 | view.modify_font(pango.FontDescription("mono bold 8")) |
|---|
| 72 | |
|---|
| 73 | sw = gtk.ScrolledWindow() |
|---|
| 74 | sw.add(view) |
|---|
| 75 | sw.set_size_request(600, 400) |
|---|
| 76 | sw.show_all() |
|---|
| 77 | |
|---|
| 78 | d.vbox.pack_start(sw) |
|---|
| 79 | d.run() |
|---|
| 80 | d.destroy() |
|---|
| 81 | gtk.main_quit() |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | if UMIT_DEVELOPMENT: |
|---|
| 85 | sys.excepthook = UmitExceptionHook() |
|---|
| 86 | |
|---|
| 87 | def main(args): |
|---|
| 88 | from umitCore.Paths import Path |
|---|
| 89 | Path.set_umit_conf(os.path.split(args[0])[0]) |
|---|
| 90 | |
|---|
| 91 | try: |
|---|
| 92 | from MainWindow import MainWindow |
|---|
| 93 | app = MainWindow() |
|---|
| 94 | app.run() |
|---|
| 95 | except KeyboardInterrupt: |
|---|
| 96 | sys.exit(signal.SIGINT) |
|---|
| 97 | |
|---|
| 98 | if __name__ == "__main__": |
|---|
| 99 | main(sys.argv) |
|---|