~ubuntu-branches/ubuntu/utopic/pida/utopic

« back to all changes in this revision

Viewing changes to pida/utils/firstrun.py

  • Committer: Bazaar Package Importer
  • Author(s): Jan Luebbe
  • Date: 2007-04-17 16:08:06 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070417160806-3ttlb6igf94x9i03
Tags: 0.4.4-1
* New upstream release (closes: #419129)
* Add dependency on python-glade2 (closes: #418716)
* Update copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
21
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
#SOFTWARE.
23
 
import os
24
23
import gtk
25
 
import pida.core.base as base
26
 
 
27
 
import distutils.spawn as spawn
28
 
 
29
 
from pkg_resources import Requirement, resource_filename
30
 
icon_file = resource_filename(Requirement.parse('pida'),
31
 
                              'pida-icon.png')
 
24
from pida.pidagtk.contentview import create_pida_icon
 
25
 
32
26
im = gtk.Image()
33
 
im.set_from_file(icon_file)
34
 
 
35
 
class IComponent(object):
36
 
 
37
 
    def get_sanity_errors(self):
38
 
        return None
39
 
 
40
 
class Vim(IComponent):
41
 
    LABEL = 'Vim'
42
 
    def get_sanity_errors(self):
43
 
        if spawn.find_executable('gvim'):
44
 
            return []
45
 
        else:
46
 
            return ['Gvim is not installed']
47
 
 
48
 
class Vimmulti(Vim):
49
 
    LABEL = 'Vim external'
50
 
        
51
 
class Culebra(IComponent):
52
 
    LABEL = 'Culebra'
53
 
 
54
 
    def get_sanity_errors(self):
55
 
        errors = []
56
 
        try:
57
 
            import gtksourceview
58
 
        except ImportError:
59
 
            errors.append('Gtksourceview is not installed')
60
 
        try:
61
 
            import rat
62
 
        except ImportError:
63
 
            errors.append('Rat is not installed')
64
 
        return errors
65
 
 
66
 
EDITORS = [Vim(), Vimmulti(), Culebra()]
 
27
im.set_from_pixbuf(create_pida_icon())
67
28
 
68
29
class FirstTimeWindow(object):
69
30
 
70
 
    def __init__(self):
 
31
    def __init__(self, editors):
71
32
        self.win = gtk.Dialog(parent=None,
72
33
                              title='PIDA First Run Wizard',
73
34
                              buttons=(gtk.STOCK_QUIT, gtk.RESPONSE_REJECT,
87
48
        l.set_markup(s)
88
49
        box.pack_start(l, expand=False, padding=8)
89
50
        self.radio = gtk.RadioButton()
90
 
        for editor in EDITORS:
 
51
        for editor in editors:
91
52
            ebox = gtk.HBox(spacing=6)
92
53
            box.pack_start(ebox, expand=False, padding=4)
93
 
            radio = gtk.RadioButton(self.radio, label=editor.LABEL)
 
54
            radio = gtk.RadioButton(self.radio, label=editor.display_name)
94
55
            ebox.pack_start(radio)
95
56
            cbox = gtk.VBox(spacing=3)
96
57
            label = gtk.Label()
101
62
            ebox.pack_start(sanitybut, expand=False, padding=1)
102
63
            sanitybut.connect('clicked', self.cb_sanity, editor, radio, label)
103
64
            self.cb_sanity(sanitybut, editor, radio, label)
104
 
            errs =  editor.get_sanity_errors()
105
65
            self.radio = radio
106
66
        bbox = gtk.HBox()
107
67
        box.pack_start(bbox, expand=False, padding=4)
112
72
        self.win.hide_all()
113
73
        editor_name = self.get_editor_option()
114
74
        self.win.destroy()
115
 
        self.write_file(filename)
 
75
        # Only write the token file if we want the user chose something
 
76
        if response == gtk.RESPONSE_ACCEPT:
 
77
            self.write_file(filename)
116
78
        return (response, editor_name)
117
79
 
118
80
    def cb_sanity(self, button, component, radio, label):
119
81
        errs =  component.get_sanity_errors()
 
82
 
120
83
        if errs:
121
84
            radio.set_sensitive(False)
122
85
            radio.set_active(False)
142
105
        f.close()
143
106
 
144
107
if __name__ == '__main__':
145
 
    ftw = FirstTimeWindow()
 
108
    ftw = FirstTimeWindow([])
146
109
    print ftw.run('/home/ali/.firstrun')
147
110