File: FontStyleWindow.py

package info (click to toggle)
emesene 1.0-dist-4
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 4,596 kB
  • ctags: 3,006
  • sloc: python: 25,171; makefile: 14; sh: 1
file content (141 lines) | stat: -rw-r--r-- 5,439 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# -*- 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())
        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