~ubuntu-branches/ubuntu/trusty/gespeaker/trusty-proposed

« back to all changes in this revision

Viewing changes to src/pygtkutils.py

  • Committer: Bazaar Package Importer
  • Author(s): Fabio Castelli
  • Date: 2009-12-12 19:59:25 UTC
  • Revision ID: james.westby@ubuntu.com-20091212195925-4ze3lc6pfredpwf1
Tags: upstream-0.7
ImportĀ upstreamĀ versionĀ 0.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##
 
2
#   Project: gespeaker - A GTK frontend for espeak  
 
3
#    Author: Fabio Castelli <muflone@vbsimple.net>
 
4
# Copyright: 2009 Fabio Castelli
 
5
#   License: GPL-2+
 
6
#  This program is free software; you can redistribute it and/or modify it
 
7
#  under the terms of the GNU General Public License as published by the Free
 
8
#  Software Foundation; either version 2 of the License, or (at your option)
 
9
#  any later version.
 
10
 
11
#  This program is distributed in the hope that it will be useful, but WITHOUT
 
12
#  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
13
#  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 
14
#  more details.
 
15
 
16
# On Debian GNU/Linux systems, the full text of the GNU General Public License
 
17
# can be found in the file /usr/share/common-licenses/GPL-2.
 
18
##
 
19
 
 
20
import gtk
 
21
 
 
22
def TextBuffer_get_text(buffer):
 
23
  "Return the whole text on the TextBuffer"
 
24
  return buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter())
 
25
 
 
26
def Radio_get_active(group):
 
27
  "Return the currently active radio button on the group"
 
28
  for button in group:
 
29
    if button.get_active():
 
30
      return button
 
31
 
 
32
def Pixbuf_load_file(filename, size=None):
 
33
  "Load an image file with the desired size if requested"
 
34
  if size and len(size) == 2:
 
35
    return gtk.gdk.pixbuf_new_from_file_at_size(filename, size[0], size[1])
 
36
  else:
 
37
    return gtk.gdk.pixbuf_new_from_file(filename)
 
38
 
 
39
def Window_change_cursor(window, cursor, refresh=False):
 
40
  "Change a window's cursor and optionally forces the refresh"
 
41
  window.set_cursor(cursor and gtk.gdk.Cursor(cursor) or None)
 
42
  if refresh:
 
43
    gtk.gdk.flush()
 
44
 
 
45
def Button_change_stock_description(button, caption, use_underline=None):
 
46
  "Change stock button description"
 
47
  alignment = button.get_children()[0]
 
48
  box = alignment.get_children()[0]
 
49
  first, second = box.get_children()
 
50
  # Find label
 
51
  if type(first) is gtk.Label:
 
52
    label = first
 
53
  elif type(second) is gtk.Label:
 
54
    label = second
 
55
  else:
 
56
    label = None
 
57
  if label:
 
58
    label.set_text(caption)
 
59
    # Set use_underline
 
60
    if use_underline is not None:
 
61
      label.set_use_underline(use_underline)
 
62
 
 
63
def TreeModel_find_text(model, column, text):
 
64
  "Return the path of the found text in the model"
 
65
  iter = model.get_iter_first()
 
66
  while iter:
 
67
    if model.get_value(iter, column) == text:
 
68
      return int(model.get_string_from_iter(iter))
 
69
    iter = model.iter_next(iter)
 
70
 
 
71
def ComboBox_set_item_from_text(combo, column, text):
 
72
  path = TreeModel_find_text(combo.get_model(), column, text)
 
73
  if not path is None:
 
74
    combo.set_active(path)
 
75
    return path
 
76
 
 
77
def ComboBox_get_text(combo, column):
 
78
  active = combo.get_active()
 
79
  if not active is None:
 
80
    return combo.get_model()[active][column]