firstrun.py :  » IDE » PIDA » pida-0.6beta3 » pida » utils » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » IDE » PIDA 
PIDA » pida 0.6beta3 » pida » utils » firstrun.py
# -*- coding: utf-8 -*- 
"""
    The dialog thats shown on the first run

    :copyright: 2005-2008 by The PIDA Project
    :license: GPL 2 or later (see README/COPYING/LICENSE)
"""
import gtk
from pida.core.environment import get_pixmap_path

pida_icon = gtk.Image()
pida_icon.set_from_file(get_pixmap_path('pida-icon.png'))

class FirstTimeWindow(object):

    def __init__(self, editors):
        self.win = gtk.Dialog(parent=None,
                              title='PIDA First Run Wizard',
                              buttons=(gtk.STOCK_QUIT, gtk.RESPONSE_REJECT,
                                       gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
        hbox = gtk.HBox(spacing=12)
        hbox.set_border_width(12)
        self.win.vbox.pack_start(hbox)
        logo = gtk.Image()
        logofrm = gtk.Alignment(0, 0, 0.1, 0.1)
        logofrm.add(pida_icon)
        hbox.pack_start(logofrm, padding=8)
        box = gtk.VBox()
        hbox.pack_start(box, padding=8)
        s = ('It seems this is the first time '
            'you are running Pida.\n\n<b>Please select an editor:</b>')
        l = gtk.Label()
        l.set_markup(s)
        box.pack_start(l, expand=False, padding=8)
        self.radio = gtk.RadioButton()
        self.editors = {}
        for editor in editors:
            self.editors[editor.get_label()] = editor.get_name()
            ebox = gtk.HBox(spacing=6)
            box.pack_start(ebox, expand=False, padding=4)
            radio = gtk.RadioButton(self.radio, label=editor.get_label())
            ebox.pack_start(radio)
            cbox = gtk.VBox(spacing=3)
            label = gtk.Label()
            label.set_alignment(1, 0.5)
            cbox.pack_start(label)
            ebox.pack_start(cbox, padding=4, expand=False)
            sanitybut = gtk.Button(label='Check')
            ebox.pack_start(sanitybut, expand=False, padding=1)
            sanitybut.connect('clicked', self.cb_sanity, editor, radio, label)
            self.cb_sanity(sanitybut, editor, radio, label)
            self.radio = radio
        bbox = gtk.HBox()
        box.pack_start(bbox, expand=False, padding=4)

    def run(self, filename):
        self.win.show_all()
        response = self.win.run()
        self.win.hide_all()
        editor_name = self.get_editor_option()
        self.win.destroy()
        # Only write the token file if we want the user chose something
        success = (response == gtk.RESPONSE_ACCEPT)
        if success:
            self.write_file(filename)
        return (success, editor_name)

    def cb_sanity(self, button, component, radio, label):
        errs =  component.get_sanity_errors()

        if errs:
            radio.set_sensitive(False)
            radio.set_active(False)
            s = '\n'.join(errs)
            label.set_markup('<span size="small" foreground="#c00000">'
                             '<i>%s</i></span>' % s)
        else:
            radio.set_sensitive(True)
            radio.set_active(True)
            label.set_markup('<span size="small" foreground="#00c000">'
                             '<i>Okay to use</i></span>')
            button.set_sensitive(False)

    def get_editor_option(self, *args):
        for radio in self.radio.get_group():
            if radio.get_active():
                editor = radio.get_label()
                return self.editors[editor]

    def write_file(self, filename):
        f = open(filename, 'w')
        f. write('#Remove this to rerun the start wizard\n\n')
        f.close()

if __name__ == '__main__':
    ftw = FirstTimeWindow([])
    print ftw.run('/home/ali/firstrun')







# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.