This file is indexed.

/usr/share/pyshared/freespeak/ui/utils.py is in freespeak 0.3.0-5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# FreeSpeak - a GUI frontend to online translator engines
# freespeak/ui/utils.py
#
## Copyright (C) 2005, 2006, 2007, 2008, 2009  Luca Bruno <lethalman88@gmail.com>
##
## This file is part of FreeSpeak.
##   
## FreeSpeak 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.
##    
## FreeSpeak 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 Library General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.

"""
GUI utilities
"""

import gtk
import gobject

class ScrolledWindow (gtk.ScrolledWindow):
    """
    Create a scrolled window with particular options
    """
    def __init__ (self, child):
        gtk.ScrolledWindow.__init__ (self)
        self.set_policy (gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self.set_shadow_type (gtk.SHADOW_ETCHED_IN)
        self.add (child)

class Frame (gtk.Frame):
    """
    HIG compliant frame
    """
    def __init__ (self, label_text, extra_widget=None):
        gtk.Frame.__init__ (self)
        widget = label = gtk.Label ()
        label.set_markup ("<b>"+label_text+"</b>")
        label.show ()
        if extra_widget:
            widget = gtk.HBox (spacing=6)
            widget.pack_start (label, False)
            widget.pack_start (extra_widget, False)
            widget.show ()
        self.set_property ('label-xalign', 0)
        self.set_label_widget (widget)
        self.set_shadow_type (gtk.SHADOW_NONE)

    def add (self, widget):
        """
        Overridden container method to add the widget respecting the HIG
        """
        alignment = gtk.Alignment ()
        alignment.set_property ('top-padding', 6)
        alignment.set_property ('left-padding', 12)
        alignment.set_property ('xscale', 1)
        alignment.set_property ('yscale', 1)
        alignment.add (widget)
        alignment.show ()
        return gtk.Frame.add (self, alignment)

class Progress (gtk.HBox):
    """
    A progress bar to be used as a user feedback.
    The widget contains a cancellation button.
    """
    __gsignals__ = {
        'cancelled': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
        }

    def __init__ (self):
        gtk.HBox.__init__ (self, spacing=6)
        self.running = False

        self.setup_bar ()
        self.setup_cancel ()

    def setup_bar (self):
        """
        Setup the progress bar
        """
        self.bar = gtk.ProgressBar ()
        self.bar.set_pulse_step (0.01)
        self.bar.show ()
        self.pack_start (self.bar)

    def setup_cancel (self):
        """
        Setup the cancellation button
        """
        self.cancel = TinyButton (gtk.STOCK_CANCEL)
        self.cancel.connect ('clicked', self.on_cancel)
        self.cancel.show ()
        self.pack_start (self.cancel, False)

    def pulse_idle (self):
        """
        GObject idle for pulsing the progress bar
        """
        self.bar.pulse ()
        return self.running

    # API

    def is_running (self):
        """
        Returns True if the progress is pulsing, False otherwise
        """
        return self.running

    def set_text (self, text):
        """
        Set the text inside the progress bar
        """
        self.bar.set_text (text)

    def start (self):
        """
        Start pulsing the progress bar
        """
        assert not self.running
        self.running = True
        gobject.timeout_add (10, self.pulse_idle)

    def stop (self):
        """
        Stop the progress
        """
        self.running = False

    # Events

    def on_cancel (self, button):
        """
        Emit the 'cancelled' signal the the cancellation button is clicked
        """
        self.emit ('cancelled')

class TinyButton (gtk.Button):
    """
    A small tiny and eye-candy button to be used beside widgets
    """
    def __init__ (self, stock=None, size=gtk.ICON_SIZE_MENU):
        gtk.Button.__init__ (self)
        self.set_name ("tiny-button")
        self.set_relief (gtk.RELIEF_NONE)
        self.set_property ('can-focus', False)
        if stock:
            image = gtk.image_new_from_stock (stock, size)
            self.set_image (image)

class MessageDialog (gtk.MessageDialog):
    """
    Convenient class for creating message dialogs
    """
    def __init__ (self, parent, message, mtype, buttons):
        flags = gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT
        gtk.MessageDialog.__init__ (self, parent, flags, mtype, buttons, message)
        self.connect ('response', self.on_response)

    def on_response (self, dialog, response):
        """
        Destory the dialog on whatever response
        """
        dialog.destroy ()

def error (message, parent=None):
    """
    Show an error message dialog
    """
    dialog = MessageDialog (parent, message,
                            gtk.MESSAGE_ERROR, gtk.BUTTONS_OK)
    dialog.show_all ()

def warning (message, parent=None):
    """
    Show a warning message dialog
    """
    dialog = MessageDialog (parent, message,
                            gtk.MESSAGE_WARNING, gtk.BUTTONS_OK)
    dialog.show_all ()