tip.py :  » Game-2D-3D » PyScrabble » pyscrabble-1.6.2 » pyscrabble » gui » 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 » Game 2D 3D » PyScrabble 
PyScrabble » pyscrabble 1.6.2 » pyscrabble » gui » tip.py
import gtk
from pyscrabble import constants
from pyscrabble import gtkutil
from pyscrabble import manager

WELCOME_TIP = _("Welcome to PyScrabble!\n\nIn the next screen, please register on a public server if you haven't already.\n\nHave fun!")

class TipWindow(gtk.Window):
    '''
    Window for viewing tips
    '''
    
    def __init__(self, tip, callback):
        '''
        Constructor
        
        @param tip: Tip text
        @param callback: Callback when tip is closed
        '''
        
        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
        self.connect("destroy", self.onDestroy )
        self.connect("delete_event", self.onDelete_event )
        self.set_size_request( constants.REGISTER_WINDOW_WIDTH, constants.REGISTER_WINDOW_HEIGHT )
        self.set_resizable( False )
        self.set_border_width( 10 )
        self.set_title( _('Help') )
        
        self.callback = callback
        
        box = gtk.VBox(False, 10)
        
        text = gtkutil.TaggableTextView(buffer=None)
        text.set_editable( False )
        text.set_cursor_visible( False )
        text.set_wrap_mode( gtk.WRAP_WORD )
        text.set_left_margin(10)
        text.set_right_margin(10)
        
        buf = text.get_buffer()
        t = buf.create_tag(justification=gtk.JUSTIFY_LEFT)
        buf.insert_with_tags(buf.get_end_iter(), tip, t)
        
        window = gtk.ScrolledWindow()
        window.add( text )
        window.set_policy( gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC )
        
        box.pack_start( window, True, True, 0 )
        box.pack_start( self.getButtons(), False, False, 0 )
        
        self.add(box)
        
        self.show_all()
    
    def onDelete_event(self, widget, event, data=None):
        '''
        Callback when the widget is deleted
        
        @param widget:
        @param event:
        @param data:
        '''
        self.closeWindow_cb()

    def onDestroy(self, widget, data=None):
        '''
        Callback when the widget is destroyed
        
        @param widget:
        @param data:
        '''
        pass
    
    def getButtons(self):
        '''
        Return buttons
        
        @return: gtk.VButtonBox
        '''
        box = gtk.VButtonBox()
        
        button = gtk.Button(stock=gtk.STOCK_OK)
        button.connect("clicked", self.closeWindow_cb)
        
        box.add(button)
        
        o = manager.OptionManager()
        
        button = gtk.CheckButton(_('Show help at startup'))
        button.set_active( o.get_default_bool_option(constants.OPTION_SHOW_TIPS, True) )
        button.connect("toggled", self.toggleOption_cb, constants.OPTION_SHOW_TIPS, o)
        
        box.add(button)
        
        return box
    
    def closeWindow_cb(self, widget=None):
        '''
        Close the window
        
        @param widget:
        '''
        self.callback()
        self.destroy()
    
    def toggleOption_cb(self, widget, option, om):
        '''
        Preference toggled.
        
        Set the option name to the value of widget.get_active()
        
        @param widget: Widget that activated this callback
        @param option: Option name
        @param om: OptionManager
        '''
        om.set_option(option, int(widget.get_active()))
        
        
        
        
        
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.