/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to olive/frontend/gtk/handler.py

  • Committer: Jelmer Vernooij
  • Date: 2008-06-29 18:12:29 UTC
  • mto: This revision was merged to the branch mainline in revision 519.
  • Revision ID: jelmer@samba.org-20080629181229-1l2m4cf7vvbyh8qg
Simplify progress bar code, use embedded progress bar inside viz window.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
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 as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 
 
17
 
import sys
18
 
 
19
 
try:
20
 
    import pygtk
21
 
    pygtk.require("2.0")
22
 
except:
23
 
    pass
24
 
try:
25
 
    import gtk
26
 
    import gtk.glade
27
 
except:
28
 
    sys.exit(1)
29
 
 
30
 
from olive.backend.info import is_branch
31
 
import olive.backend.errors as errors
32
 
 
33
 
from dialog import OliveDialog
34
 
from menu import OliveMenu
35
 
 
36
 
class OliveHandler:
37
 
    """ Signal handler class for Olive. """
38
 
    def __init__(self, gladefile, comm):
39
 
        self.gladefile = gladefile
40
 
        self.comm = comm
41
 
        
42
 
        self.dialog = OliveDialog(self.gladefile)
43
 
        
44
 
        self.menu = OliveMenu(self.gladefile, self.comm, self.dialog)
45
 
    
46
 
    def on_about_activate(self, widget):
47
 
        self.dialog.about()
48
 
        
49
 
    def on_menuitem_add_files_activate(self, widget):
50
 
        """ Add file(s)... menu handler. """
51
 
        from add import OliveAdd
52
 
        add = OliveAdd(self.gladefile, self.comm, self.dialog)
53
 
        add.display()
54
 
    
55
 
    def on_menuitem_branch_get_activate(self, widget):
56
 
        """ Branch/Get... menu handler. """
57
 
        from branch import OliveBranch
58
 
        branch = OliveBranch(self.gladefile, self.comm, self.dialog)
59
 
        branch.display()
60
 
    
61
 
    def on_menuitem_branch_checkout_activate(self, widget):
62
 
        """ Branch/Checkout... menu handler. """
63
 
        from checkout import OliveCheckout
64
 
        checkout = OliveCheckout(self.gladefile, self.comm, self.dialog)
65
 
        checkout.display()
66
 
    
67
 
    def on_menuitem_branch_commit_activate(self, widget):
68
 
        """ Branch/Commit... menu handler. """
69
 
        from commit import OliveCommit
70
 
        commit = OliveCommit(self.gladefile, self.comm, self.dialog)
71
 
        commit.display()
72
 
    
73
 
    def on_menuitem_branch_missing_revisions_activate(self, widget):
74
 
        """ Branch/Missing revisions menu handler. """
75
 
        import olive.backend.update as update
76
 
        
77
 
        self.comm.set_busy(self.comm.window_main)
78
 
        
79
 
        try:
80
 
            ret = update.missing(self.comm.get_path())
81
 
        except errors.NotBranchError:
82
 
            self.dialog.error_dialog(_('Directory is not a branch'),
83
 
                                     _('You can perform this action only in a branch.'))
84
 
        except errors.ConnectionError:
85
 
            self.dialog.error_dialog(_('Connection error'),
86
 
                                     _('Cannot connect to remote location.\nPlease try again later.'))
87
 
        except errors.NoLocationKnown:
88
 
            self.dialog.error_dialog(_('Parent location is unknown'),
89
 
                                     _('Cannot determine missing revisions if no parent location is known.'))
90
 
        else:
91
 
            if ret > 0:
92
 
                self.dialog.info_dialog(_('There are missing revisions'),
93
 
                                        _('%d revision(s) missing.') % ret)
94
 
            else:
95
 
                self.dialog.info_dialog(_('Local branch up to date'),
96
 
                                        _('There are no missing revisions.'))
97
 
        
98
 
        self.comm.set_busy(self.comm.window_main, False)
99
 
    
100
 
    def on_menuitem_branch_pull_activate(self, widget):
101
 
        """ Branch/Pull menu handler. """
102
 
        import olive.backend.update as update
103
 
        
104
 
        self.comm.set_busy(self.comm.window_main)
105
 
        
106
 
        try:
107
 
            ret = update.pull(self.comm.get_path())
108
 
        except errors.NotBranchError:
109
 
            self.dialog.error_dialog(_('Directory is not a branch'),
110
 
                                     _('You can perform this action only in a branch.'))
111
 
        except errors.NoLocationKnown:
112
 
            self.dialog.error_dialog(_('Parent location is unknown'),
113
 
                                     _('Pulling is not possible until there is no parent location.'))
114
 
        else:
115
 
            self.dialog.info_dialog(_('Pull successful'),
116
 
                                    _('%d revision(s) pulled.') % ret)
117
 
        
118
 
        self.comm.set_busy(self.comm.window_main, False)
119
 
    
120
 
    def on_menuitem_branch_push_activate(self, widget):
121
 
        """ Branch/Push... menu handler. """
122
 
        from push import OlivePush
123
 
        push = OlivePush(self.gladefile, self.comm, self.dialog)
124
 
        push.display()
125
 
    
126
 
    def on_menuitem_branch_status_activate(self, widget):
127
 
        """ Branch/Status... menu handler. """
128
 
        from status import OliveStatus
129
 
        status = OliveStatus(self.gladefile, self.comm, self.dialog)
130
 
        status.display()
131
 
    
132
 
    def on_menuitem_branch_initialize_activate(self, widget):
133
 
        """ Initialize current directory. """
134
 
        import olive.backend.init as init
135
 
        
136
 
        try:
137
 
            init.init(self.comm.get_path())
138
 
        except errors.AlreadyBranchError, errmsg:
139
 
            self.dialog.error_dialog(_('Directory is already a branch'),
140
 
                                     _('The current directory (%s) is already a branch.\nYou can start using it, or initialize another directory.') % errmsg)
141
 
        except errors.BranchExistsWithoutWorkingTree, errmsg:
142
 
            self.dialog.error_dialog(_('Branch without a working tree'),
143
 
                                     _('The current directory (%s)\nis a branch without a working tree.') % errmsg)
144
 
        except:
145
 
            raise
146
 
        else:
147
 
            self.dialog.info_dialog(_('Ininialize successful'),
148
 
                                    _('Directory successfully initialized.'))
149
 
            self.comm.refresh_right()
150
 
        
151
 
    def on_menuitem_file_make_directory_activate(self, widget):
152
 
        """ File/Make directory... menu handler. """
153
 
        from mkdir import OliveMkdir
154
 
        mkdir = OliveMkdir(self.gladefile, self.comm, self.dialog)
155
 
        mkdir.display()
156
 
    
157
 
    def on_menuitem_file_move_activate(self, widget):
158
 
        """ File/Move... menu handler. """
159
 
        from move import OliveMove
160
 
        move = OliveMove(self.gladefile, self.comm, self.dialog)
161
 
        move.display()
162
 
    
163
 
    def on_menuitem_file_rename_activate(self, widget):
164
 
        """ File/Rename... menu handler. """
165
 
        from rename import OliveRename
166
 
        rename = OliveRename(self.gladefile, self.comm, self.dialog)
167
 
        rename.display()
168
 
 
169
 
    def on_menuitem_remove_file_activate(self, widget):
170
 
        """ Remove (unversion) selected file. """
171
 
        from remove import OliveRemove
172
 
        remove = OliveRemove(self.gladefile, self.comm, self.dialog)
173
 
        remove.display()
174
 
    
175
 
    def on_menuitem_stats_diff_activate(self, widget):
176
 
        """ Statistics/Differences... menu handler. """
177
 
        from diff import OliveDiff
178
 
        diff = OliveDiff(self.gladefile, self.comm, self.dialog)
179
 
        diff.display()
180
 
    
181
 
    def on_menuitem_stats_infos_activate(self, widget):
182
 
        """ Statistics/Informations... menu handler. """
183
 
        from info import OliveInfo
184
 
        info = OliveInfo(self.gladefile, self.comm, self.dialog)
185
 
        info.display()
186
 
    
187
 
    def on_menuitem_stats_log_activate(self, widget):
188
 
        """ Statistics/Log... menu handler. """
189
 
        from log import OliveLog
190
 
        log = OliveLog(self.gladefile, self.comm, self.dialog)
191
 
        log.display()
192
 
    
193
 
    def on_menuitem_view_refresh_activate(self, widget):
194
 
        """ View/Refresh menu handler. """
195
 
        # Refresh the left pane
196
 
        self.comm.refresh_left()
197
 
        # Refresh the right pane
198
 
        self.comm.refresh_right()
199
 
    
200
 
    def on_menuitem_view_show_hidden_files_activate(self, widget):
201
 
        """ View/Show hidden files menu handler. """
202
 
        if widget.get_active():
203
 
            # Show hidden files
204
 
            self.comm.pref.set_preference('dotted_files', True)
205
 
            self.comm.pref.refresh()
206
 
            self.comm.refresh_right()
207
 
        else:
208
 
            # Do not show hidden files
209
 
            self.comm.pref.set_preference('dotted_files', False)
210
 
            self.comm.pref.refresh()
211
 
            self.comm.refresh_right()
212
 
 
213
 
    def on_treeview_left_button_press_event(self, widget, event):
214
 
        """ Occurs when somebody right-clicks in the bookmark list. """
215
 
        if event.button == 3:
216
 
            self.menu.left_context_menu().popup(None, None, None, 0,
217
 
                                                event.time)
218
 
        
219
 
    def on_treeview_left_row_activated(self, treeview, path, view_column):
220
 
        """ Occurs when somebody double-clicks or enters an item in the
221
 
        bookmark list. """
222
 
        self.comm.set_busy(treeview)
223
 
        
224
 
        newdir = self.comm.get_selected_left()
225
 
        self.comm.set_path(newdir)
226
 
        
227
 
        self.comm.refresh_right()
228
 
        
229
 
        self.comm.set_busy(treeview, False)
230
 
    
231
 
    def on_treeview_right_button_press_event(self, widget, event):
232
 
        """ Occurs when somebody right-clicks in the file list. """
233
 
        if event.button == 3:
234
 
            # get the menu items
235
 
            m_add = self.menu.ui.get_widget('/context_right/add')
236
 
            m_remove = self.menu.ui.get_widget('/context_right/remove')
237
 
            m_commit = self.menu.ui.get_widget('/context_right/commit')
238
 
            m_diff = self.menu.ui.get_widget('/context_right/diff')
239
 
            # check if we're in a branch
240
 
            if not is_branch(self.comm.get_path()):
241
 
                m_add.set_sensitive(False)
242
 
                m_remove.set_sensitive(False)
243
 
                m_commit.set_sensitive(False)
244
 
                m_diff.set_sensitive(False)
245
 
            else:
246
 
                m_add.set_sensitive(True)
247
 
                m_remove.set_sensitive(True)
248
 
                m_commit.set_sensitive(True)
249
 
                m_diff.set_sensitive(True)
250
 
            self.menu.right_context_menu().popup(None, None, None, 0,
251
 
                                                 event.time)
252
 
        
253
 
    def on_treeview_right_row_activated(self, treeview, path, view_column):
254
 
        """ Occurs when somebody double-clicks or enters an item in the
255
 
        file list. """
256
 
        import os.path
257
 
        
258
 
        newdir = self.comm.get_selected_right()
259
 
        
260
 
        if newdir == '..':
261
 
            self.comm.set_path(os.path.split(self.comm.get_path())[0])
262
 
        else:
263
 
            fullpath = self.comm.get_path() + '/' + newdir
264
 
            if os.path.isdir(fullpath):
265
 
                # selected item is an existant directory
266
 
                self.comm.set_path(fullpath)
267
 
            else:
268
 
                if sys.platform == 'win32':
269
 
                    # open the file with the default application
270
 
                    os.startfile(fullpath)
271
 
                else:
272
 
                    # TODO: support other OSes
273
 
                    print "DEBUG: double-click on non-Win32 platforms not supported."
274
 
        
275
 
        self.comm.refresh_right()
276
 
    
277
 
    def on_window_main_delete_event(self, widget, event=None):
278
 
        """ Do some stuff before exiting. """
279
 
        width, height = self.comm.window_main.get_size()
280
 
        self.comm.pref.set_preference('window_width', width)
281
 
        self.comm.pref.set_preference('window_height', height)
282
 
        x, y = self.comm.window_main.get_position()
283
 
        self.comm.pref.set_preference('window_x', x)
284
 
        self.comm.pref.set_preference('window_y', y)
285
 
        self.comm.pref.set_preference('paned_position',
286
 
                                      self.comm.hpaned_main.get_position())
287
 
        
288
 
        self.comm.pref.write()
289
 
        self.comm.window_main.destroy()
290
 
 
291
 
    def not_implemented(self, widget):
292
 
        """ Display a Not implemented error message. """
293
 
        self.dialog.error_dialog(_('We feel sorry'),
294
 
                                 _('This feature is not yet implemented.'))
295