summaryrefslogtreecommitdiffstats
path: root/build_tools/l7/larch0/gui/front/mainwindow.py
blob: 407b46a19e23417ff6f8b572314136d7bae418d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env python
#
# (c) Copyright 2010 Michael Towers (larch42 at googlemail dot com)
#
# This file is part of the larch project.
#
#    larch is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    larch is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with larch; if not, write to the Free Software Foundation, Inc.,
#    51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
#----------------------------------------------------------------------------
#2010.07.13

import __builtin__
from uim import Uim, debug
__builtin__.debug = debug


_running = False
def fss(*args, **kargs):
    while True:
        if _running:
            ui.command(':larch.busy', [], True)
        ok, result = filesystem(*args)
        if _running:
            ui.command(':larch.busy', [], False)
        if ok:
            filter = kargs.get('filter')
            return filter(result) if filter else result

        if kargs.get('trap', True):
            ui.command('errorDialog', result)
            # That might return, but the gui should quit (soon?).
        return None

__builtin__.fss = fss



class Ui(Uim):
    def __init__(self):
        Uim.__init__(self)

    def runningtab(self, i=None):
        if (i == None):
            i = 1 if progress.active else 0
        if (i == 0) and hasattr(stage, 'reenter'):
            stage.reenter()
        self.command(':tabs.set', i)

    def fileDialog(self, message, startdir=None, create=False,
            dirsonly=False, file=None, bookmarks=None, filter=None):
        return self.command('fileDialog', message, startdir, None,
            dirsonly, create, file, bookmarks, filter)

    def enable_installation_page(self, on):
        self.command(':notebook.enableTab', 1, on)

    def quit(self):
        """Do any tidying up which may be necessary.
        """
        larchscripts.close()
        Uim.quit()

    def data(self, key):
        return self.command('main_page_data.get', key)

__builtin__.ui = Ui()


def tab_changed(index):
    __builtin__.stage = pages[index]
    stage.enter()
ui.connect(':notebook*changed', tab_changed)


from page_project import ProjectSettings
from page_installation import Installation
from page_larchify import Larchify
from page_mediumprofile import MediumProfile
from page_medium import Medium


from docviewer import DocViewer

from editor import Editor

from logview import Logger, Progress


def run_error(message, title=None):
    ui.command('warningDialog', message, title)
__builtin__.run_error = run_error

pages = []
def start():
    pages.append(ProjectSettings())
    pages.append(Installation())
    pages.append(Larchify())
    pages.append(MediumProfile())
    pages.append(Medium())

    __builtin__.docviewer = DocViewer()
    __builtin__.edit = Editor().edit

    __builtin__.progress = Progress()
    __builtin__.logger = Logger()

    MainWindow = fss('fetch_layout', 'page_main.uim')
    ui.widgetlist(MainWindow)

    ui.connect('$$$uiclose$$$', ui.quit)
    ui.connect('$$$uiquit$$$', ui.quit)
    ui.connect('$$$cancel$$$', larchscripts.interrupt)

    ui.command(':larch.pack')
    # Set up the first gui page (project settings)
    pages[0].setup()
    ui.command(':larch.show')
    _running = True
    ui.run()