FontStyleWindow.py :  » Network » emesene » emesene-1.6.2 » 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 » Network » emesene 
emesene » emesene 1.6.2 » FontStyleWindow.py
# -*- coding: utf-8 -*-

#   This file is part of emesene.
#
#    Emesene is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    emesene is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with emesene; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import os
import gtk
from gobject import timeout_add,source_remove

import stock
import dialog

class FontStyleWindow(gtk.Window):
    '''this is the window that opens when you press the font button on the
    conversation window'''

    def __init__(self, controller, parent):
        '''class constructor'''
        gtk.Window.__init__(self)
        
        self.controller = controller
        self.config = self.controller.config
        self.parentUI = parent
        
        self.set_decorated(False)
        self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)

        self.set_position(gtk.WIN_POS_MOUSE)
        self.set_resizable(False)
        self.set_title(_('Font styles'))
        self.set_border_width(5)

        self.vbox = gtk.VBox()
        
        self.closed = True
        
        self.buttonBold = gtk.CheckButton()
        self.buttonBold.connect('toggled', self.toggled, 'bold')
        self.buttonBold.set_active(self.config.user['fontBold'])
        self.buttonBoldLabel = gtk.Label('<span weight="bold">' + \
                                            _('Bold') + '</span>')
        self.buttonBoldLabel.set_use_markup(True)
        self.buttonBold.add(self.buttonBoldLabel)
        
        self.buttonItalic = gtk.CheckButton()
        self.buttonItalic.connect('toggled', self.toggled, 'italic')
        self.buttonItalic.set_active(self.config.user['fontItalic'])
        self.buttonItalicLabel = gtk.Label('<span style="italic">' + \
                                            _('Italic') + '</span>')
        self.buttonItalicLabel.set_use_markup(True)
        self.buttonItalic.add(self.buttonItalicLabel)
        
        self.buttonUnderline = gtk.CheckButton()
        self.buttonUnderline.connect('toggled', self.toggled, 'underline')
        self.buttonUnderline.set_active(self.config.user['fontUnderline'])
        self.buttonUnderlineLabel = gtk.Label('<span underline="single">' + \
                                            _('Underline') + '</span>')
        self.buttonUnderlineLabel.set_use_markup(True)
        self.buttonUnderline.add(self.buttonUnderlineLabel)
        
        self.buttonStrike = gtk.CheckButton()
        self.buttonStrike.connect('toggled', self.toggled, 'strike')
        self.buttonStrike.set_active(self.config.user['fontStrike'])
        self.buttonStrikeLabel = gtk.Label('<span strikethrough="true">' + \
                                            _('Strike') + '</span>')
        self.buttonStrikeLabel.set_use_markup(True)
        self.buttonStrike.add(self.buttonStrikeLabel)
        
        self.buttonReset = gtk.Button(_('Reset'))
        self.buttonReset.connect('clicked', self.resetFormat)
        
        self.vbox.pack_start(self.buttonBold)
        self.vbox.pack_start(self.buttonItalic)
        self.vbox.pack_start(self.buttonUnderline)
        self.vbox.pack_start(self.buttonStrike)
        #self.vbox.pack_start(gtk.HSeparator())  # breaks leave-notify-event
        self.vbox.pack_start(self.buttonReset)
        
        self.add(self.vbox)
        self.vbox.show_all()
        self.connect('leave-notify-event', self.on_leave_notify_event)

        self.tag = None

    def toggled(self, button, option):
        '''callback for the toggled signal'''

        if option == 'bold':
            self.config.user['fontBold'] = button.get_active()
        elif option == 'italic':
            self.config.user['fontItalic'] = button.get_active()
        elif option == 'underline':
            self.config.user['fontUnderline'] = button.get_active()
        elif option == 'strike':
            self.config.user['fontStrike'] = button.get_active()

        # *cough* hack *cough*
        if hasattr(self.parentUI, 'input'):
           self.parentUI.input.applyAttrsToInput()
    
    def resetFormat(self, *args):
        self.config.user['fontBold'] = False
        self.buttonBold.set_active(0)
        self.config.user['fontItalic'] = False
        self.buttonItalic.set_active(0)
        self.config.user['fontUnderline'] = False
        self.buttonUnderline.set_active(0)
        self.config.user['fontStrike'] = False
        self.buttonStrike.set_active(0)
        
        if hasattr(self.parentUI, 'input'):
           self.parentUI.input.applyAttrsToInput()
    
    def on_leave_notify_event(self, *args):
        if not self.tag and not self.closed:
            self.tag = timeout_add(500, self.hide)

    def show(self):
        gtk.Window.show(self)
        self.tag = None
        self.closed = False

    def hide(self):
        gtk.Window.hide(self)
        if (self.tag):
            source_remove(self.tag)
            self.tag = None
        self.closed = True
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.