/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: Szilveszter Farkas (Phanatic)
  • Date: 2006-09-11 02:56:58 UTC
  • mto: (0.14.1 main) (93.1.1 win32.bialix)
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: Szilveszter.Farkas@gmail.com-20060911025658-997cf3a305b9f1da
A better implementation for the drive selection. (OptionMenu didn't work on Win32)

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