/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 initialize.py

  • Committer: Szilveszter Farkas (Phanatic)
  • Date: 2006-08-07 16:51:21 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-20060807165121-10fe27c374bbdffd
Added new artwork.

2006-08-07  Szilveszter Farkas <Szilveszter.Farkas@gmail.com>

    * olive.galde: added custom artwork (icons)
    * icons/*: new icons for the toolbar
    * setup.py: install the icons

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 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
 
from gi.repository import GObject
18
 
from gi.repository import Gtk
19
 
 
20
 
import os
21
 
 
22
 
from bzrlib import (
23
 
    bzrdir,
24
 
    errors,
25
 
    transport,
26
 
    )
27
 
 
28
 
from bzrlib.plugins.gtk.dialog import error_dialog
29
 
from bzrlib.plugins.gtk.errors import show_bzr_error
30
 
from bzrlib.plugins.gtk.i18n import _i18n
31
 
 
32
 
 
33
 
class InitDialog(Gtk.Dialog):
34
 
    """ Initialize dialog. """
35
 
 
36
 
    def __init__(self, path, parent=None):
37
 
        """ Initialize the Initialize dialog. """
38
 
        super(InitDialog, self).__init__(
39
 
            title="Initialize - Olive", parent=parent, flags=0,
40
 
            buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
41
 
        
42
 
        # Get arguments
43
 
        self.path = path
44
 
        
45
 
        # Create the widgets
46
 
        self._button_init = Gtk.Button(_i18n("_Initialize"), use_underline=True)
47
 
        self._label_question = Gtk.Label(label=_i18n("Which directory do you want to initialize?"))
48
 
        self._radio_current = Gtk.RadioButton.new_with_label(
49
 
            None, _i18n("Current directory"))
50
 
        self._radio_custom = Gtk.RadioButton.new_with_label_from_widget(
51
 
            self._radio_current, _i18n("Create a new directory with the name:"))
52
 
        self._entry_custom = Gtk.Entry()
53
 
        self._hbox_custom = Gtk.HBox()
54
 
        
55
 
        # Set callbacks
56
 
        self._button_init.connect('clicked', self._on_init_clicked)
57
 
        self._radio_custom.connect('toggled', self._on_custom_toggled)
58
 
        
59
 
        # Set properties
60
 
        self._entry_custom.set_sensitive(False)
61
 
        
62
 
        # Construct the dialog
63
 
        self.action_area.pack_end(self._button_init, False, False, 0)
64
 
        
65
 
        self._hbox_custom.pack_start(self._radio_custom, False, False, 0)
66
 
        self._hbox_custom.pack_start(self._entry_custom, True, True, 0)
67
 
        
68
 
        content_area = self.get_content_area()
69
 
        content_area.pack_start(self._label_question, True, True, 0)
70
 
        content_area.pack_start(self._radio_current, True, True, 0)
71
 
        content_area.pack_start(self._hbox_custom, True, True, 0)
72
 
        
73
 
        # Display the dialog
74
 
        content_area.show_all()
75
 
    
76
 
    def _on_custom_toggled(self, widget):
77
 
        """ Occurs if the Custom radiobutton is toggled. """
78
 
        if self._radio_custom.get_active():
79
 
            self._entry_custom.set_sensitive(True)
80
 
            self._entry_custom.grab_focus()
81
 
        else:
82
 
            self._entry_custom.set_sensitive(False)
83
 
    
84
 
    @show_bzr_error
85
 
    def _on_init_clicked(self, widget):
86
 
        if self._radio_custom.get_active() and len(self._entry_custom.get_text()) == 0:
87
 
            error_dialog(_i18n("Directory name not specified"),
88
 
                         _i18n("You should specify a new directory name."))
89
 
            return
90
 
        
91
 
        if self._radio_current.get_active():
92
 
            location = self.path
93
 
        else:
94
 
            location = self.path + os.sep + self._entry_custom.get_text()
95
 
        
96
 
        format = bzrdir.format_registry.make_bzrdir('default')        
97
 
        to_transport = transport.get_transport(location)
98
 
        
99
 
        try:
100
 
            to_transport.mkdir('.')
101
 
        except errors.FileExists:
102
 
            pass
103
 
                    
104
 
        try:
105
 
            existing_bzrdir = bzrdir.BzrDir.open(location)
106
 
        except errors.NotBranchError:
107
 
            branch = bzrdir.BzrDir.create_branch_convenience(to_transport.base,
108
 
                                                             format=format)
109
 
        else:
110
 
            from bzrlib.transport.local import LocalTransport
111
 
            if existing_bzrdir.has_branch():
112
 
                if (isinstance(to_transport, LocalTransport)
113
 
                    and not existing_bzrdir.has_workingtree()):
114
 
                        raise errors.BranchExistsWithoutWorkingTree(location)
115
 
                raise errors.AlreadyBranchError(location)
116
 
            else:
117
 
                branch = existing_bzrdir.create_branch()
118
 
                existing_bzrdir.create_workingtree()
119
 
        
120
 
        self.response(Gtk.ResponseType.OK)