~ubuntu-branches/ubuntu/trusty/python-avc/trusty

« back to all changes in this revision

Viewing changes to examples/gtk_listtreeview.py

  • Committer: Bazaar Package Importer
  • Author(s): Fabrizio Pollastri
  • Date: 2009-04-20 12:28:35 UTC
  • mfrom: (1.1.4 upstream) (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090420122835-xf2fz6xyszsvixjc
Tags: 0.7.1-1
* New upstream
* Standards-Version bumped to 3.8.1 (no changes needed)
* Removed license.odt file from doc/

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# .+
 
3
#
 
4
# .identifier : $Id:$
 
5
# .context    : Application View Controller
 
6
# .title      : tree view widget display capabilities (GTK)
 
7
# .kind       : python source
 
8
# .author     : Fabrizio Pollastri
 
9
# .site       : Revello - Italy
 
10
# .creation   : 3-Aug-2008
 
11
# .copyright  : (c) 2008 Fabrizio Pollastri.
 
12
# .license    : GNU General Public License (see below)
 
13
#
 
14
# This file is part of "AVC, Application View Controller".
 
15
#
 
16
# AVC is free software; you can redistribute it and/or modify
 
17
# it under the terms of the GNU General Public License as published by
 
18
# the Free Software Foundation; either version 3 of the License, or
 
19
# (at your option) any later version.
 
20
#
 
21
# AVC is distributed in the hope that it will be useful,
 
22
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
23
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
24
# GNU General Public License for more details.
 
25
#
 
26
# You should have received a copy of the GNU General Public License
 
27
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
28
#
 
29
# .-
 
30
 
 
31
 
 
32
import gobject                          #--
 
33
import gtk                              #- gimp tool kit bindings
 
34
import gtk.glade                        # glade bindings
 
35
 
 
36
from avc import *                       # AVC
 
37
 
 
38
import copy                             # object cloning support
 
39
 
 
40
GLADE_XML = 'gtk_listtreeview.glade'    # GUI glade descriptor
 
41
 
 
42
UPDATE_PERIOD = 2000                    # ms
 
43
 
 
44
 
 
45
class Example(AVC):
 
46
  """
 
47
  Showcase of display capabilities for the tree view widget
 
48
  """
 
49
 
 
50
  def __init__(self):
 
51
 
 
52
    # create GUI
 
53
    self.glade = gtk.glade.XML(GLADE_XML)
 
54
 
 
55
    # autoconnect GUI signal handlers
 
56
    self.glade.signal_autoconnect(self)
 
57
 
 
58
    # make tree view rows reorderable
 
59
    self.glade.get_widget('list__treeview').set_reorderable(True)
 
60
    self.glade.get_widget('tree__treeview').set_reorderable(True)
 
61
 
 
62
    # connected variables
 
63
    self.list = {'head':['col1 int','col2 str'], \
 
64
      'body':[[1,'one'],[2,'two'],[3,'three']]}
 
65
    self.list_work = copy.deepcopy(self.list)
 
66
    self.tree = {'head':['col1 int','col2 str'],'body':{ \
 
67
      # root rows
 
68
      '1':[1,'one'], \
 
69
      '2':[2,'two'], \
 
70
      # children of root row '1'
 
71
      '1.1':[11,'one one'], \
 
72
      '1.2':[12,'one two'], \
 
73
      # children of root row '2'
 
74
      '2.1':[21,'two one'], \
 
75
      '2.2':[22,'two two']}}
 
76
 
 
77
    # start variables update
 
78
    update = self.update()
 
79
    gobject.timeout_add(UPDATE_PERIOD,update.next) 
 
80
 
 
81
 
 
82
  def update(self):
 
83
    """
 
84
    Tabular data rows data are rolled down.
 
85
    """
 
86
    rows_num = len(self.list['body'])
 
87
    while True:
 
88
      # save last row of data
 
89
      last_row = self.list_work['body'][-1]
 
90
      # shift down one position each data row
 
91
      for i in range(1,rows_num): 
 
92
        self.list_work['body'][-i] = \
 
93
          self.list_work['body'][-1-i]
 
94
      # copy last row into first position
 
95
      self.list_work['body'][0] = last_row
 
96
      # copy working copy into connected variable
 
97
      self.list = self.list_work
 
98
      yield True
 
99
 
 
100
 
 
101
  def on_destroy(self,window):
 
102
    "Terminate program at window destroy"
 
103
    gtk.main_quit()
 
104
 
 
105
 
 
106
#### MAIN
 
107
 
 
108
example = Example()                     # instantiate the application
 
109
example.avc_init()                      # connect widgets with variables
 
110
gtk.main()                              # run GTK event loop until quit
 
111
 
 
112
#### END