97.2.41
by Evan Dandrea
* Clean up bin/usb-creator-gtk to match changes in main.py (Windows main |
1 |
# Copyright (C) 2009 Canonical Ltd.
|
2 |
||
3 |
# This program is free software: you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License version 3,
|
|
5 |
# as published by the Free Software Foundation.
|
|
6 |
#
|
|
7 |
# This program is distributed in the hope that it will be useful,
|
|
8 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
# GNU General Public License for more details.
|
|
11 |
#
|
|
12 |
# You should have received a copy of the GNU General Public License
|
|
13 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
14 |
||
97.2.24
by Evan Dandrea
Support for building a Windows executable. Run make build_windows or make test_windows. |
15 |
# USB Creator for Windows.
|
16 |
import sys |
|
17 |
import os |
|
97.2.37
by Evan Dandrea
* Handle unhandled exceptions by displaying an error message and exiting. |
18 |
|
19 |
import locale |
|
97.2.45
by Evan Dandrea
Add missing imports. |
20 |
import logging |
97.2.37
by Evan Dandrea
* Handle unhandled exceptions by displaying an error message and exiting. |
21 |
|
97.2.24
by Evan Dandrea
Support for building a Windows executable. Run make build_windows or make test_windows. |
22 |
root_dir = os.path.abspath(os.path.dirname(__file__)) |
23 |
lib_dir = os.path.join(root_dir, 'lib') |
|
24 |
sys.path.insert(0, lib_dir) |
|
25 |
||
26 |
from usbcreator.frontends.winui import WinuiFrontend |
|
27 |
from usbcreator.backends.windows import WindowsBackend |
|
381
by Colin Watson
Use str() rather than unicode() in Python 3. |
28 |
from usbcreator.misc import setup_gettext, setup_logging, text_type |
97.2.26
by Evan Dandrea
* Added a Windows icon to be displayed as the application icon on the desktop. |
29 |
|
30 |
setup_logging() |
|
31 |
||
32 |
import ctypes |
|
97.2.37
by Evan Dandrea
* Handle unhandled exceptions by displaying an error message and exiting. |
33 |
MB_ICONSTOP = 16 |
97.2.26
by Evan Dandrea
* Added a Windows icon to be displayed as the application icon on the desktop. |
34 |
try: |
35 |
if not ctypes.windll.advpack.IsNTAdmin(0, 0): |
|
36 |
ctypes.windll.user32.MessageBoxW(0, |
|
97.2.37
by Evan Dandrea
* Handle unhandled exceptions by displaying an error message and exiting. |
37 |
_(u'Please run this program as an administrator to continue.'), |
38 |
_(u'Administrator privileges required'), MB_ICONSTOP) |
|
97.2.26
by Evan Dandrea
* Added a Windows icon to be displayed as the application icon on the desktop. |
39 |
logging.error('Please run this program as an administrator.') |
40 |
sys.exit(1) |
|
41 |
except Exception: |
|
42 |
pass
|
|
97.2.37
by Evan Dandrea
* Handle unhandled exceptions by displaying an error message and exiting. |
43 |
|
44 |
# TODO evand 2009-07-27: Options!
|
|
45 |
||
46 |
translations_dir = os.path.join(root_dir, 'translations') |
|
379
by Colin Watson
Only pass unicode=True to gettext.install in Python 2. |
47 |
setup_gettext(localedir=translations_dir) |
97.2.37
by Evan Dandrea
* Handle unhandled exceptions by displaying an error message and exiting. |
48 |
|
49 |
try: |
|
50 |
b = WindowsBackend() |
|
51 |
WinuiFrontend(b) |
|
366
by Colin Watson
Use "except Exception as e" syntax rather than the old-style "except |
52 |
except Exception as e: |
97.2.37
by Evan Dandrea
* Handle unhandled exceptions by displaying an error message and exiting. |
53 |
# TODO evand 2009-07-28: Thread cleanup?
|
54 |
ctypes.windll.user32.MessageBoxW(0, |
|
381
by Colin Watson
Use str() rather than unicode() in Python 3. |
55 |
_(u'An unhandled exception occurred:\n%s' % text_type(e)), |
97.2.37
by Evan Dandrea
* Handle unhandled exceptions by displaying an error message and exiting. |
56 |
_(u'Error'), MB_ICONSTOP) |
57 |
logging.exception('Unhandled exception:') |
|
58 |
sys.exit(1) |