| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
"""This is Gaphor, a Python based UML editor. |
|---|
| 4 |
""" |
|---|
| 5 |
|
|---|
| 6 |
__all__ = [ 'main', 'resource', 'GaphorError' ] |
|---|
| 7 |
|
|---|
| 8 |
import os |
|---|
| 9 |
|
|---|
| 10 |
import misc.logger |
|---|
| 11 |
|
|---|
| 12 |
from misc.resource import Resource |
|---|
| 13 |
|
|---|
| 14 |
if os.name == 'nt': |
|---|
| 15 |
home = 'USERPROFILE' |
|---|
| 16 |
else: |
|---|
| 17 |
home = 'HOME' |
|---|
| 18 |
|
|---|
| 19 |
user_data_dir = os.path.join(os.getenv(home), '.gaphor') |
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
resource = Resource(initial_resources={ |
|---|
| 29 |
'Name': 'gaphor', |
|---|
| 30 |
'UserDataDir': user_data_dir, |
|---|
| 31 |
'ui.toolbox.classes': True, |
|---|
| 32 |
}) |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
class GaphorError(Exception): |
|---|
| 36 |
""" |
|---|
| 37 |
Gaphor specific exception class |
|---|
| 38 |
""" |
|---|
| 39 |
def __init__(self, args=None): |
|---|
| 40 |
Exception.__init__(self) |
|---|
| 41 |
self.args = args |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
def new_main(gaphor_file=None): |
|---|
| 45 |
""" |
|---|
| 46 |
Not yet used. see main() below. |
|---|
| 47 |
""" |
|---|
| 48 |
from gaphor.application import Application |
|---|
| 49 |
Application.init() |
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
main_window = resource("MainWindow", Application.main_window) |
|---|
| 53 |
|
|---|
| 54 |
if gaphor_file: |
|---|
| 55 |
main_window.set_filename(gaphor_file) |
|---|
| 56 |
main_window.execute_action('FileRevert') |
|---|
| 57 |
else: |
|---|
| 58 |
main_window.execute_action('FileNew') |
|---|
| 59 |
Application.run() |
|---|
| 60 |
Application.shutdown() |
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
def main(gaphor_file=None): |
|---|
| 64 |
""" |
|---|
| 65 |
Start the interactive application. |
|---|
| 66 |
|
|---|
| 67 |
This involves importing plugins and creating the main window. |
|---|
| 68 |
""" |
|---|
| 69 |
import pkg_resources |
|---|
| 70 |
|
|---|
| 71 |
resource('Version', pkg_resources.get_distribution('gaphor').version) |
|---|
| 72 |
resource('DataDir', os.path.join(pkg_resources.get_distribution('gaphor').location, 'gaphor', 'data')) |
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
import gtk |
|---|
| 76 |
import ui |
|---|
| 77 |
import adapters |
|---|
| 78 |
import actions |
|---|
| 79 |
|
|---|
| 80 |
import services.pluginmanager |
|---|
| 81 |
import services.undomanager |
|---|
| 82 |
|
|---|
| 83 |
from ui.mainwindow import MainWindow |
|---|
| 84 |
|
|---|
| 85 |
resource('PluginManager').init(None) |
|---|
| 86 |
|
|---|
| 87 |
ui.load_accel_map() |
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
main_window = resource(MainWindow) |
|---|
| 91 |
main_window.construct() |
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
main_window.connect(lambda win: win.get_state() == MainWindow.STATE_CLOSED and gtk.main_quit()) |
|---|
| 95 |
|
|---|
| 96 |
if gaphor_file: |
|---|
| 97 |
main_window.set_filename(gaphor_file) |
|---|
| 98 |
main_window.execute_action('FileRevert') |
|---|
| 99 |
else: |
|---|
| 100 |
main_window.execute_action('FileNew') |
|---|
| 101 |
|
|---|
| 102 |
gtk.main() |
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
resource.save() |
|---|
| 106 |
|
|---|
| 107 |
ui.save_accel_map() |
|---|
| 108 |
|
|---|
| 109 |
log.info('Bye!') |
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
import __builtin__ |
|---|
| 114 |
__builtin__.__dict__['log'] = misc.logger.Logger() |
|---|
| 115 |
|
|---|
| 116 |
if __debug__: |
|---|
| 117 |
refs = [] |
|---|
| 118 |
|
|---|