This file is indexed.

/usr/share/doc/python-gtkmvc-doc/quickstart/index.html is in python-gtkmvc-doc 1.99.1-1build1.

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
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>gtkmvc in 45 minutes &mdash; gtkmvc: A Quickstart Guide 1.99.1 documentation</title>
    
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '1.99.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="gtkmvc: A Quickstart Guide 1.99.1 documentation" href="#" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li><a href="#">gtkmvc: A Quickstart Guide 1.99.1 documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="gtkmvc-in-45-minutes">
<h1>gtkmvc in 45 minutes<a class="headerlink" href="#gtkmvc-in-45-minutes" title="Permalink to this headline"></a></h1>
<p>This document presents gtkmvc for those who are in hurry, or for
curious people who want to have a quick overview of gtkmvc features
and capabilities.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p>This document is not exhaustive, as many important details are not
described. For a complete information refer to the User Manual and to
the Tutorial, both coming along with gtkmvc.</p>
<p class="last">It is assumed you already know <em>Python</em>, <em>pygtk</em> and have some
experience with <em>design issues</em>.
However, here you will find a short introduction
presenting the main actors that are going to play a role into an
GUI application based on gtkmvc.</p>
</div>
<div class="section" id="introduction">
<h2>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline"></a></h2>
<div class="section" id="what-is-gtkmvc-and-what-it-does">
<h3>What is gtkmvc, and what it does<a class="headerlink" href="#what-is-gtkmvc-and-what-it-does" title="Permalink to this headline"></a></h3>
<p>gtkmvc is a thin framework for developing GUI applications with
Python and the pygtk toolkit.</p>
<ol class="arabic simple">
<li>It helps you to organize the source code of your application.</li>
<li>It provides some support for making views out of glade files.</li>
<li>It separates the data/logic of your application (the <em>model</em>)
from the presentation layer (the <em>view</em>).</li>
<li>It tries to be as much transparent as possible wrt your application.</li>
</ol>
</div>
<div class="section" id="some-terminology">
<h3>Some terminology<a class="headerlink" href="#some-terminology" title="Permalink to this headline"></a></h3>
<dl class="docutils">
<dt><strong>Model</strong></dt>
<dd><p class="first">Contains the logic of the application, the data that are
independent on the GUI.
For example, in a <em>music player</em>:</p>
<ul class="last simple">
<li>The list of the mp3 file names.</li>
<li>The methods for playing the files in the list.</li>
</ul>
</dd>
<dt><strong>Observer</strong></dt>
<dd>It is an entity interested in observing some parts of one or
more Models. Observers are used to react to certain changes in
models without creating explicit dependencies or links with them.</dd>
<dt><strong>Observable Property</strong></dt>
<dd><p class="first">It is an attribute of the Model, that is supposed to be
<em>observable</em> by one or more observers connected to the model.
For example:</p>
<ul class="simple">
<li>The property <tt class="docutils literal"><span class="pre">current_perc</span></tt> holding the % of the mp3 file
that is being played.</li>
</ul>
<p class="last">Observable properties can be <em>concrete</em> (data is phisically
stored in the model), or <em>logical</em> (data is function of
other properties, or stored outside the model, like in a
database.)</p>
</dd>
<dt><strong>View</strong></dt>
<dd>Contains a set of widgets, and the methods for
manipulating them. The set of widgets can be build out of a
<em>GtkBuilder</em> file, or <em>glade</em> file.</dd>
<dt><strong>Controller</strong></dt>
<dd><p class="first">It is a particular kind of Observer, connected to one model
and to one or more views. It contains the GUI logic, and all
handlers for GUI signals. E.g.</p>
<ul class="last simple">
<li>The code that makes a progress bar advance in the view
as the music file is played by the model.</li>
</ul>
</dd>
<dt><strong>Adapter</strong></dt>
<dd><p class="first">Adapts the content of one widget (or a set of widgets) into
the view with one observable property into the model. An
adapter keeps the content of an observable property
up-to-dated with the content of a widget, and
viceversa. Adapters live into the controllers.
E.g.</p>
<ul class="last simple">
<li>An adapter that bounds property <tt class="docutils literal"><span class="pre">current_perc</span></tt> with a
progress bar widget into the view.</li>
</ul>
</dd>
</dl>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">All these entities are now presented more in details.</p>
</div>
</div>
<div class="section" id="what-is-all-this-complexity-for">
<h3>What is all this complexity for?<a class="headerlink" href="#what-is-all-this-complexity-for" title="Permalink to this headline"></a></h3>
<p>The final goal is to improve your life as a
designer/programmer. Designing a complex GUI is an easy task only
in principle. In fact it is hard to decouple logic and presentation
layers, and even harder to separate control code that <em>should</em> be
separate. And in the end, it is easy to get spaghetti code
especially in the control flow part of the GUI.</p>
<p>In the picture you can see how a middle/large GUI application can be
organized and decomposed with gtkmvc.</p>
<a class="reference internal image-reference" href="_images/diagram.png"><img alt="_images/diagram.png" src="_images/diagram.png" /></a>
<p>Spend some time looking at this funny image. On the left, models
designed as a pair of separate hierarchies lay. One of the model in
the left hierarchy observes one model into the other hierarchy.</p>
<p>On the right, the presentation layer is designed as a hierarchy of
three views. Each view may be based on one GtkBuilder/glade file
that can be shared among views.</p>
<p>The model and the view sides do not see each other as they are
separated by the two depicted barriers. Those red barriers avoid
the model to be involved in the presentation layer, and the view to
be tempted to access the model part.</p>
<p>In the middle, the control part live. The controllers within it can
see through the barriers. Controllers observe some parts of the logic
into the model side, and can control some parts of the views.</p>
<ol class="arabic simple">
<li>One controller controls one view (and possibly the sub-views)</li>
<li>One view can be controller by one or more controllers.</li>
<li>One controller control and observes one model.</li>
<li>One controller can also observe many other models.</li>
<li>One model can be observed by many observers.</li>
</ol>
<p>The picture shows how a GUI can be decomposed. Keep in mind that
decomposition is always intended to couple with (and hopefully reduce)
complexity.</p>
<p>For example, you can have a controller controlling the menu and the
toolbar of the application, a controller for one sub-view, two
controllers for another sub-view, etc. Each controller is connected to
one model, which is a part of the application logic.</p>
</div>
</div>
<div class="section" id="views">
<h2>Views<a class="headerlink" href="#views" title="Permalink to this headline"></a></h2>
<p>A view is a class that is intended to be a container for widgets.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">gtk</span>
<span class="kn">from</span> <span class="nn">gtkmvc</span> <span class="kn">import</span> <span class="n">View</span>

<span class="k">class</span> <span class="nc">MyView</span> <span class="p">(</span><span class="n">View</span><span class="p">):</span>
   <span class="n">builder</span> <span class="o">=</span> <span class="s">&quot;gtk_builder_file.glade&quot;</span>

   <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
       <span class="n">View</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

       <span class="c"># possible construction of manual widgets</span>
       <span class="bp">self</span><span class="p">[</span><span class="s">&#39;name_of_new_label&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">gtk</span><span class="o">.</span><span class="n">Label</span><span class="p">(</span><span class="s">&quot;A label manually constructed!&quot;</span><span class="p">)</span>
       <span class="bp">self</span><span class="p">[</span><span class="s">&#39;some_container_in_builder_file&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">pack_start</span><span class="p">(</span><span class="bp">self</span><span class="p">[</span><span class="s">&#39;name_of_new_label&#39;</span><span class="p">])</span>

       <span class="c"># possible setup of all widgets</span>
       <span class="c"># ...</span>
       <span class="k">return</span>

   <span class="k">def</span> <span class="nf">set_sensitivity</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flag</span><span class="p">):</span>
       <span class="k">for</span> <span class="n">wid</span> <span class="ow">in</span> <span class="p">(</span><span class="bp">self</span><span class="p">[</span><span class="n">x</span><span class="p">]</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="p">(</span><span class="s">&#39;widget1&#39;</span><span class="p">,</span> <span class="s">&#39;widget2&#39;</span><span class="p">,</span> <span class="p">)):</span>
           <span class="n">wid</span><span class="o">.</span><span class="n">set_sensitive</span><span class="p">(</span><span class="n">flag</span><span class="p">)</span>
           <span class="k">pass</span>
       <span class="k">return</span>

   <span class="k">pass</span> <span class="c"># end of class</span>
</pre></div>
</div>
<p>Your view is derived from base class <tt class="docutils literal"><span class="pre">gtkmvc.View</span></tt> that offers
several services:</p>
<ol class="arabic simple">
<li>Attribute <tt class="docutils literal"><span class="pre">builder</span></tt> that is used to tell the view which
GtkBuilder file its widgets are taken from. As an alternative,
attribute <tt class="docutils literal"><span class="pre">glade</span></tt> can be used for deprecated glade files.</li>
<li>Attribute <tt class="docutils literal"><span class="pre">top</span></tt> which contains the name of the top-level widget.</li>
<li>The view instance can be used a container (a dictionary) of
widgets, both for accessing named widgets in GtkBuilder files,
and for creating new widgets manually.</li>
</ol>
<p>Views can be decomposed into a hierarchy of views. For example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">gtk</span>
<span class="kn">from</span> <span class="nn">gtkmvc</span> <span class="kn">import</span> <span class="n">View</span>

<span class="k">class</span> <span class="nc">MySuperView</span> <span class="p">(</span><span class="n">View</span><span class="p">):</span>
   <span class="n">builder</span> <span class="o">=</span> <span class="s">&quot;view1.glade&quot;</span>
   <span class="n">top</span> <span class="o">=</span> <span class="s">&quot;top_widget_name&quot;</span>

   <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
       <span class="n">View</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

       <span class="bp">self</span><span class="o">.</span><span class="n">subview</span> <span class="o">=</span> <span class="n">MySubView</span><span class="p">()</span>

       <span class="c"># connects the subview to a widget in the containing view</span>
       <span class="bp">self</span><span class="p">[</span><span class="s">&#39;some_container&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">subview</span><span class="o">.</span><span class="n">get_top_widget</span><span class="p">())</span>
       <span class="k">return</span>
   <span class="k">pass</span> <span class="c"># end of class</span>

<span class="k">class</span> <span class="nc">MySubView</span> <span class="p">(</span><span class="n">View</span><span class="p">):</span>
   <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
       <span class="n">View</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">builder</span><span class="o">=</span><span class="s">&quot;view2.glade&quot;</span><span class="p">,</span> <span class="n">top</span><span class="o">=</span><span class="s">&quot;view2_top_widget&quot;</span><span class="p">)</span>
       <span class="c"># setting of sub view...</span>
       <span class="k">return</span>
   <span class="k">pass</span> <span class="c"># end of class</span>
</pre></div>
</div>
<p>As you can see:</p>
<ol class="arabic simple">
<li>It is possible to construct a hierarchy of views to deal with view
composition.</li>
<li>Subviews  can be connected to known containers widgets into the
containing view, like in the example.</li>
<li>Class View provides the method <tt class="docutils literal"><span class="pre">get_top_widget</span></tt> that returns the
View&#8217;s top level widget.</li>
<li>All attributes <tt class="docutils literal"><span class="pre">glade</span></tt>, <tt class="docutils literal"><span class="pre">builder</span></tt> and <tt class="docutils literal"><span class="pre">top</span></tt> can be overridden
or substituted by View&#8217;s constructor equivalent parameters.</li>
</ol>
<p>For simple cases (views offering no services, and only based on a
glade file) it is not mandatory to derive our own class:</p>
<div class="highlight-python"><pre>from gtkmvc import View
v = View(builder="myview.glade", top="mytop_widget)</pre>
</div>
</div>
<div class="section" id="models">
<h2>Models<a class="headerlink" href="#models" title="Permalink to this headline"></a></h2>
<p>A model is a class that is intended to contain the application&#8217;s
logic. A model contains data and methods, and a subset of the data can be
declared to be <em>observable</em>.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">gtkmvc</span> <span class="kn">import</span> <span class="n">Model</span>
<span class="k">class</span> <span class="nc">MyModel</span> <span class="p">(</span><span class="n">Model</span><span class="p">):</span>
   <span class="n">data1</span> <span class="o">=</span> <span class="mi">10</span>
   <span class="n">data2</span> <span class="o">=</span> <span class="s">&quot;a string&quot;</span>
   <span class="n">data3</span> <span class="o">=</span> <span class="s">&quot;a list of strings&quot;</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>

   <span class="n">__observables__</span> <span class="o">=</span> <span class="p">(</span><span class="s">&quot;data1&quot;</span><span class="p">,</span> <span class="s">&quot;data3&quot;</span><span class="p">)</span>

   <span class="k">pass</span> <span class="c"># end of class</span>
</pre></div>
</div>
<p>A model must derive from <tt class="docutils literal"><span class="pre">gtkmvc.Model</span></tt> <a class="footnote-reference" href="#fn1" id="id1">[1]</a> which derives from
<tt class="docutils literal"><span class="pre">Observer</span></tt> as models may be interested in observing themselves and
other models (see <em>Observers</em> below).</p>
<p><em>Observable Properties</em> are declared through the special attribute
<tt class="docutils literal"><span class="pre">__observables__</span></tt> which is a sequence of string names.</p>
<p>In the example class attributes <tt class="docutils literal"><span class="pre">data1</span></tt> and <tt class="docutils literal"><span class="pre">data3</span></tt> are declared
to be observable properties. Names in <tt class="docutils literal"><span class="pre">__observables__</span></tt> can contain
wildcards <a class="footnote-reference" href="#fn2" id="id2">[2]</a> and all attributes in the class not beginning with a
double underscore <tt class="docutils literal"><span class="pre">__</span></tt> will be checked for matching. For example
<tt class="docutils literal"><span class="pre">__observables__</span> <span class="pre">=</span> <span class="pre">(&quot;data?&quot;,)</span></tt> would match <tt class="docutils literal"><span class="pre">data1</span></tt>, <tt class="docutils literal"><span class="pre">data2</span></tt> and
<tt class="docutils literal"><span class="pre">data3</span></tt>.</p>
<div class="section" id="observable-properties">
<h3>Observable Properties<a class="headerlink" href="#observable-properties" title="Permalink to this headline"></a></h3>
<p>Observable properties live into models and can be assigned to several
types of values, included lists, maps, and user defined classes.  For
all details about the observable properties, see the User Manual for
the details.</p>
<div class="section" id="value-properties">
<h4>1. Value Properties<a class="headerlink" href="#value-properties" title="Permalink to this headline"></a></h4>
<p><em>Value Properties</em> are intended to hold values which when are
<em>re-assigned</em> observers are notified.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">gtkmvc</span> <span class="kn">import</span> <span class="n">Model</span>
<span class="k">class</span> <span class="nc">MyModel</span> <span class="p">(</span><span class="n">Model</span><span class="p">):</span>
   <span class="n">data1</span> <span class="o">=</span> <span class="mi">5</span>
   <span class="n">data2</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">]</span>
   <span class="n">data3</span> <span class="o">=</span> <span class="p">{}</span>
   <span class="n">data4</span> <span class="o">=</span> <span class="n">SomeClass</span><span class="p">()</span>
   <span class="n">__observables__</span> <span class="o">=</span> <span class="p">(</span><span class="s">&quot;data?&quot;</span><span class="p">,</span> <span class="p">)</span>
   <span class="k">pass</span> <span class="c"># end of class</span>

<span class="n">m</span> <span class="o">=</span> <span class="n">MyModel</span><span class="p">()</span>
<span class="c"># here the properties are re-assigned</span>
<span class="n">m</span><span class="o">.</span><span class="n">data1</span> <span class="o">+=</span> <span class="mi">15</span>
<span class="n">m</span><span class="o">.</span><span class="n">data2</span> <span class="o">=</span> <span class="p">[</span><span class="mi">4</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">6</span><span class="p">]</span>
<span class="n">m</span><span class="o">.</span><span class="n">data3</span> <span class="o">=</span> <span class="p">{</span> <span class="s">&quot;key&quot;</span> <span class="p">:</span> <span class="s">&quot;value&quot;</span> <span class="p">}</span>
<span class="n">m</span><span class="o">.</span><span class="n">data4</span> <span class="o">=</span> <span class="n">SomeOtherClass</span><span class="p">()</span>
</pre></div>
</div>
<p>Every time a value property gets reassigned, observers observing it
will be notified.</p>
</div>
<div class="section" id="logical-properties">
<h4>2. Logical Properties<a class="headerlink" href="#logical-properties" title="Permalink to this headline"></a></h4>
<p>Sometimes it is needed to store values of properties <em>outside</em> the
model, like in the File System, in a DB, or somewhere in the network
via RPC. In other cases values are not <em>stored</em>, but are <em>calculated</em>
out of other properties.  In these cases it is possible to declare
observable properties that do not correspond to any class attribute,
but that correspond each to a pair of methods (getter/setter):</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">gtkmvc</span> <span class="kn">import</span> <span class="n">Model</span>
<span class="k">class</span> <span class="nc">MyModel</span> <span class="p">(</span><span class="n">Model</span><span class="p">):</span>
   <span class="n">data1</span> <span class="o">=</span> <span class="mi">5</span>
   <span class="n">__observables__</span> <span class="o">=</span> <span class="p">(</span><span class="s">&quot;data1&quot;</span><span class="p">,</span> <span class="s">&quot;data_external&quot;</span><span class="p">)</span>

   <span class="nd">@Model.getter</span>
   <span class="k">def</span> <span class="nf">data_external</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
       <span class="n">value</span> <span class="o">=</span> <span class="n">get_the_value_somehow</span><span class="p">()</span>
       <span class="k">return</span> <span class="n">value</span>

   <span class="nd">@Model.setter</span>
   <span class="k">def</span> <span class="nf">data_external</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
       <span class="c"># store the value somehow...</span>
       <span class="k">return</span>

   <span class="k">pass</span> <span class="c"># end of class</span>
</pre></div>
</div>
<p>The syntax for declaring getter/setter pair for a property is inpired
to the syntax of python decorator <tt class="xref py py-func docutils literal"><span class="pre">property()</span></tt>.</p>
<p>It is also possible to define getters and/or setters that takes also
the name of the property, making possible to define multi-properties
getter/setter pairs:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">gtkmvc</span> <span class="kn">import</span> <span class="n">Model</span>
<span class="k">class</span> <span class="nc">MyModel</span> <span class="p">(</span><span class="n">Model</span><span class="p">):</span>
   <span class="n">data1</span> <span class="o">=</span> <span class="mi">5</span> <span class="c"># this is a concrete property</span>
   <span class="n">__observables__</span> <span class="o">=</span> <span class="p">(</span><span class="s">&quot;data1&quot;</span><span class="p">,</span> <span class="s">&quot;data2&quot;</span><span class="p">,</span> <span class="s">&quot;data3&quot;</span><span class="p">,</span> <span class="s">&quot;data4&quot;</span><span class="p">)</span>


   <span class="c"># this handles data3 and data4</span>
   <span class="nd">@Model.getter</span><span class="p">(</span><span class="s">&quot;data3&quot;</span><span class="p">,</span> <span class="s">&quot;data4&quot;</span><span class="p">)</span>
   <span class="k">def</span> <span class="nf">d3_d4_get</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">prop_name</span><span class="p">):</span>
       <span class="k">if</span> <span class="n">prop_name</span> <span class="o">==</span> <span class="s">&quot;data3&quot;</span><span class="p">:</span> <span class="n">value</span> <span class="o">=</span> <span class="o">...</span> <span class="c"># get the value of data3 somehow</span>
       <span class="k">elif</span> <span class="n">prop_name</span> <span class="o">==</span> <span class="s">&quot;data4&quot;</span><span class="p">:</span> <span class="o">...</span>
       <span class="c"># ...</span>
       <span class="k">return</span> <span class="n">value</span>

   <span class="c"># this handles data2, data3 and data4</span>
   <span class="nd">@Model.setter</span><span class="p">(</span><span class="s">&quot;data[234]&quot;</span><span class="p">)</span>
   <span class="k">def</span> <span class="nf">d2_d3_d4_set</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">prop_name</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
       <span class="k">if</span> <span class="n">prop_name</span> <span class="o">==</span> <span class="s">&quot;data2&quot;</span><span class="p">:</span> <span class="o">...</span> <span class="c"># store the value of data3 somehow</span>
       <span class="k">elif</span> <span class="n">prop_name</span> <span class="o">==</span> <span class="s">&#39;data3&#39;</span><span class="p">:</span> <span class="o">...</span>
       <span class="c"># ...</span>
       <span class="k">return</span>

   <span class="nd">@Model.getter</span>
   <span class="k">def</span> <span class="nf">data2</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
       <span class="n">value</span> <span class="o">=</span> <span class="o">...</span> <span class="c"># get the value somehow</span>
       <span class="k">return</span> <span class="n">value</span>

   <span class="k">pass</span> <span class="c"># end of class</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Notice the use of pattern matching when defining
getter/setter pairs, like for <cite>d2_d3_d4_set</cite>.</p>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">You can exploit custom properties values to perform some
custom actions when a property is read or written.</p>
</div>
</div>
<div class="section" id="mutable-containers">
<h4>3. Mutable containers<a class="headerlink" href="#mutable-containers" title="Permalink to this headline"></a></h4>
<p>When the value of an observable property is a mutable object, like a
sequence or a map, observers may be interested in being notified when
a method is called on the object itself:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># here the object contents are changed:</span>
<span class="n">m</span><span class="o">.</span><span class="n">data2</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mi">7</span><span class="p">)</span>
<span class="n">m</span><span class="o">.</span><span class="n">data3</span><span class="p">[</span><span class="s">&#39;key2&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">&quot;value for key2&quot;</span>
</pre></div>
</div>
</div>
<div class="section" id="mutable-class-instances">
<h4>4. Mutable class instances<a class="headerlink" href="#mutable-class-instances" title="Permalink to this headline"></a></h4>
<p>Properties can be instances of mutable classes. Like for containers
objects, observers may be interested in being notified when a method
changing the object is called:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># here the object contents are changed:</span>
<span class="n">m</span><span class="o">.</span><span class="n">data4</span><span class="o">.</span><span class="n">some_method_changing_the_instance</span><span class="p">()</span>
</pre></div>
</div>
<p>Of course it is needed to declare method
<tt class="docutils literal"><span class="pre">SomeOtherClass.some_method_changing_the_instance</span></tt> to be
observable. For example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">gtkmvc.model</span> <span class="kn">import</span> <span class="n">Model</span><span class="p">,</span> <span class="n">Observable</span>
<span class="k">class</span> <span class="nc">SomeOtherClass</span> <span class="p">(</span><span class="n">Observable</span><span class="p">):</span>
   <span class="sd">&quot;&quot;&quot;This is a class that is thought to be integrated into the</span>
<span class="sd">   observer pattern. It is declared to be &#39;observable&#39; and the</span>
<span class="sd">   methods which we are interested in monitoring are decorated</span>
<span class="sd">   accordingly&quot;&quot;&quot;</span>

   <span class="n">val</span> <span class="o">=</span> <span class="mi">0</span>

   <span class="nd">@Observable.observed</span> <span class="c"># this way the method is declared as &#39;observed&#39;</span>
   <span class="k">def</span> <span class="nf">change</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="bp">self</span><span class="o">.</span><span class="n">val</span> <span class="o">+=</span> <span class="mi">1</span>

   <span class="k">pass</span> <span class="c">#end of class</span>
</pre></div>
</div>
<p>Observable properties derive from class <tt class="docutils literal"><span class="pre">Observable</span></tt> and methods
that change the content of the instance can be declared by using the
<tt class="docutils literal"><span class="pre">Observable.observed</span></tt> decorator like in the example.</p>
<p>Ok, but what if my class is already existing? It is less natural, but
gtkmvc supports observable properties of already existing classes&#8217;
instances:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">gtkmvc</span> <span class="kn">import</span> <span class="n">Model</span><span class="p">,</span> <span class="n">Observer</span>

<span class="k">class</span> <span class="nc">ExistingClass</span> <span class="p">(</span><span class="nb">object</span><span class="p">):</span>
   <span class="sd">&quot;&quot;&quot;This is an already existing class whose code is not intended to</span>
<span class="sd">   be changed. Instead, when instantiated into the model, it is</span>
<span class="sd">   declared in a particular manner, so that the model can recognise</span>
<span class="sd">   it and wrap it in order to monitor it&quot;&quot;&quot;</span>

   <span class="n">val</span> <span class="o">=</span> <span class="mi">0</span>

   <span class="k">def</span> <span class="nf">change</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="bp">self</span><span class="o">.</span><span class="n">val</span> <span class="o">+=</span> <span class="mi">1</span>
   <span class="k">pass</span> <span class="c">#end of class</span>


<span class="k">class</span> <span class="nc">MyModel</span> <span class="p">(</span><span class="n">Model</span><span class="p">):</span>

   <span class="n">obj</span> <span class="o">=</span> <span class="p">(</span><span class="n">ExistingClass</span><span class="p">,</span> <span class="n">ExistingClass</span><span class="p">(),</span> <span class="p">(</span><span class="s">&#39;change&#39;</span><span class="p">,))</span>
   <span class="n">__observables__</span> <span class="o">=</span> <span class="p">[</span><span class="s">&quot;obj&quot;</span><span class="p">]</span>

   <span class="k">pass</span> <span class="c"># end of class</span>
</pre></div>
</div>
<p>The triplet must contain the name of the class, the instance, and a
list naming the methods whose calls can be observed by observers.</p>
</div>
<div class="section" id="signals">
<h4>5. Signals<a class="headerlink" href="#signals" title="Permalink to this headline"></a></h4>
<p>Sometimes the models want to communicate to observers that <em>events</em>
occurred. For this <tt class="docutils literal"><span class="pre">Signal</span></tt> can be used as property value:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">gtkmvc</span> <span class="kn">import</span> <span class="n">Model</span><span class="p">,</span> <span class="n">Signal</span>
<span class="k">class</span> <span class="nc">MyModel</span> <span class="p">(</span><span class="n">Model</span><span class="p">):</span>
   <span class="n">sgn</span> <span class="o">=</span> <span class="n">Signal</span><span class="p">()</span>
   <span class="n">__observables__</span> <span class="o">=</span> <span class="p">(</span><span class="s">&quot;sgn&quot;</span><span class="p">,)</span>
   <span class="k">pass</span>

<span class="n">m</span> <span class="o">=</span> <span class="n">MyModel</span><span class="p">()</span>
<span class="n">m</span><span class="o">.</span><span class="n">sgn</span><span class="o">.</span><span class="n">emit</span><span class="p">()</span>
<span class="n">m</span><span class="o">.</span><span class="n">sgn</span><span class="o">.</span><span class="n">emit</span><span class="p">(</span><span class="s">&quot;A value can also be passed here&quot;</span><span class="p">)</span>
<span class="n">m</span><span class="o">.</span><span class="n">sgn</span> <span class="o">=</span> <span class="n">Signal</span><span class="p">()</span> <span class="c"># here the signal is reassigned</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="section" id="observers">
<h2>Observers<a class="headerlink" href="#observers" title="Permalink to this headline"></a></h2>
<p>An observer is a class that is interested in being notified when some
observable properties into one or models it observes gets changed.</p>
<p>Methods in the observer that are intended to receive notifications can
be defined through:</p>
<ol class="arabic simple">
<li>Statically with a decorator</li>
<li>Dynamically</li>
</ol>
<p>Depending on the type of the observable property, you can see three
different types of notifications:</p>
<ol class="arabic simple">
<li>Assign notifications (for value change in assignments)</li>
<li>Method calls (for containers and class instances)</li>
<li>Signal emitting (for signals)</li>
</ol>
<p>In the example you find assign, before call, after call and signal
notifications, presented in the static flavours:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">gtkmvc</span> <span class="kn">import</span> <span class="n">Observer</span>

<span class="k">class</span> <span class="nc">MyObserver</span> <span class="p">(</span><span class="n">Observer</span><span class="p">):</span>

   <span class="c"># ------------------------------------------------------</span>
   <span class="c">#    Value change</span>
   <span class="c"># ------------------------------------------------------</span>

   <span class="c"># common notification for multiple properties:</span>
   <span class="nd">@Observer.observe</span><span class="p">(</span><span class="s">&quot;data1&quot;</span><span class="p">,</span> <span class="n">assign</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
   <span class="nd">@Observer.observe</span><span class="p">(</span><span class="s">&quot;data2&quot;</span><span class="p">,</span> <span class="n">assign</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
   <span class="k">def</span> <span class="nf">assign_notification</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">model</span><span class="p">,</span> <span class="n">prop_name</span><span class="p">,</span> <span class="n">info</span><span class="p">):</span>
       <span class="k">print</span> <span class="s">&quot;assign_notification:&quot;</span><span class="p">,</span> <span class="n">prop_name</span><span class="p">,</span> <span class="n">info</span><span class="o">.</span><span class="n">old</span><span class="p">,</span> <span class="n">info</span><span class="o">.</span><span class="n">new</span>

   <span class="c"># multiple notifications for the same properties are possible:</span>
   <span class="nd">@Observer.observe</span><span class="p">(</span><span class="s">&quot;data1&quot;</span><span class="p">,</span> <span class="n">assign</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
   <span class="k">def</span> <span class="nf">another_assign_notification</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">model</span><span class="p">,</span> <span class="n">prop_name</span><span class="p">,</span> <span class="n">info</span><span class="p">):</span>
       <span class="k">print</span> <span class="s">&quot;another_assign_notification:&quot;</span><span class="p">,</span> <span class="n">prop_name</span><span class="p">,</span> <span class="n">info</span><span class="o">.</span><span class="n">old</span><span class="p">,</span> <span class="n">info</span><span class="o">.</span><span class="n">new</span>
       <span class="k">return</span>

   <span class="c"># ------------------------------------------------------</span>
   <span class="c">#    Before and After method call</span>
   <span class="c"># ------------------------------------------------------</span>
   <span class="nd">@Observer.observe</span><span class="p">(</span><span class="s">&quot;data3&quot;</span><span class="p">,</span> <span class="n">before</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
   <span class="k">def</span> <span class="nf">before_call_notification</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">model</span><span class="p">,</span> <span class="n">prop_name</span><span class="p">,</span> <span class="n">info</span><span class="p">):</span>
       <span class="k">print</span> <span class="s">&quot;before_call_notification:&quot;</span><span class="p">,</span> <span class="n">prop_name</span><span class="p">,</span> <span class="n">info</span><span class="o">.</span><span class="n">instance</span><span class="p">,</span> <span class="n">info</span><span class="o">.</span><span class="n">method_name</span>
       <span class="k">return</span>

   <span class="c"># multiple notification types are allowed:</span>
   <span class="nd">@Observer.observe</span><span class="p">(</span><span class="s">&quot;data3&quot;</span><span class="p">,</span> <span class="n">before</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">after</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
   <span class="k">def</span> <span class="nf">before_after_call_notification</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">model</span><span class="p">,</span> <span class="n">prop_name</span><span class="p">,</span> <span class="n">info</span><span class="p">):</span>
       <span class="k">if</span> <span class="s">&quot;before&quot;</span> <span class="ow">in</span> <span class="n">info</span><span class="p">:</span>
          <span class="k">print</span> <span class="s">&quot;before_after_call_notification: BEFORE:&quot;</span><span class="p">,</span> <span class="n">prop_name</span><span class="p">,</span> <span class="n">info</span><span class="o">.</span><span class="n">instance</span><span class="p">,</span> <span class="n">info</span><span class="o">.</span><span class="n">method_name</span>
       <span class="k">else</span><span class="p">:</span>
          <span class="k">assert</span> <span class="s">&quot;after&quot;</span> <span class="ow">in</span> <span class="n">info</span>
          <span class="k">print</span> <span class="s">&quot;before_after_call_notification: AFTER:&quot;</span><span class="p">,</span> <span class="n">prop_name</span><span class="p">,</span> <span class="n">info</span><span class="o">.</span><span class="n">instance</span><span class="p">,</span> <span class="n">info</span><span class="o">.</span><span class="n">method_name</span><span class="p">,</span> <span class="n">info</span><span class="o">.</span><span class="n">result</span>
          <span class="k">pass</span>
       <span class="k">return</span>

   <span class="c"># ------------------------------------------------------</span>
   <span class="c">#    Signal emitted</span>
   <span class="c"># ------------------------------------------------------</span>
   <span class="nd">@Observer.observe</span><span class="p">(</span><span class="s">&quot;sgn&quot;</span><span class="p">,</span> <span class="n">signal</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">assign</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
   <span class="k">def</span> <span class="nf">signal_notification</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">model</span><span class="p">,</span> <span class="n">prop_name</span><span class="p">,</span> <span class="n">info</span><span class="p">):</span>
       <span class="k">if</span> <span class="s">&quot;signal&quot;</span> <span class="ow">in</span> <span class="n">info</span><span class="p">:</span>
          <span class="k">print</span> <span class="s">&quot;signal_notification: SIGNAL:&quot;</span><span class="p">,</span> <span class="n">prop_name</span><span class="p">,</span> <span class="n">info</span><span class="o">.</span><span class="n">arg</span>
       <span class="k">else</span><span class="p">:</span>
          <span class="k">assert</span> <span class="s">&quot;assign&quot;</span> <span class="ow">in</span> <span class="n">info</span>
          <span class="k">print</span> <span class="s">&quot;signal_notification: ASSIGN:&quot;</span><span class="p">,</span> <span class="n">prop_name</span><span class="p">,</span> <span class="n">info</span><span class="o">.</span><span class="n">old</span><span class="p">,</span> <span class="n">info</span><span class="o">.</span><span class="n">new</span>
          <span class="k">pass</span>
       <span class="k">return</span>
   <span class="k">pass</span> <span class="c"># end of class</span>
</pre></div>
</div>
<p>Here is how the model and our observer can be connected/unconnected:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">m</span> <span class="o">=</span> <span class="n">MyModel</span><span class="p">()</span>
<span class="n">o</span> <span class="o">=</span> <span class="n">MyObserver</span><span class="p">()</span>
<span class="n">o</span><span class="o">.</span><span class="n">observe_model</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
<span class="c"># ...</span>
<span class="n">o</span><span class="o">.</span><span class="n">relieve_model</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
</pre></div>
</div>
<p><tt class="docutils literal"><span class="pre">Observer</span></tt> constructor optionally takes a model that it registers
into:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">m</span> <span class="o">=</span> <span class="n">MyModel</span><span class="p">()</span>
<span class="n">o</span> <span class="o">=</span> <span class="n">MyObserver</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
<span class="c"># ...</span>
<span class="n">o</span><span class="o">.</span><span class="n">relieve_model</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
</pre></div>
</div>
<p>Now let&#8217;s try to modify the assigned value to a property:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">gtkmvc</span> <span class="kn">import</span> <span class="n">Model</span>
<span class="k">class</span> <span class="nc">MyModel</span> <span class="p">(</span><span class="n">Model</span><span class="p">):</span>
   <span class="n">data1</span> <span class="o">=</span> <span class="mi">10</span>
   <span class="n">data2</span> <span class="o">=</span> <span class="s">&quot;a string&quot;</span>
   <span class="n">data3</span> <span class="o">=</span> <span class="s">&quot;gtkmvc makes your life easier&quot;</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
   <span class="n">__observables__</span> <span class="o">=</span> <span class="p">(</span><span class="s">&quot;data?&quot;</span><span class="p">,</span> <span class="p">)</span>
   <span class="k">pass</span> <span class="c"># end of class</span>

<span class="n">m</span> <span class="o">=</span> <span class="n">MyModel</span><span class="p">()</span>
<span class="n">o</span> <span class="o">=</span> <span class="n">MyObserver</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>

<span class="n">m</span><span class="o">.</span><span class="n">data1</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="k">print</span> <span class="s">&quot;&gt;&gt;&gt; Here m.data is&quot;</span><span class="p">,</span> <span class="n">m</span><span class="o">.</span><span class="n">data1</span>

<span class="n">m</span><span class="o">.</span><span class="n">data2</span> <span class="o">=</span> <span class="s">&quot;Another string&quot;</span>
<span class="n">m</span><span class="o">.</span><span class="n">data3</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&quot;and fun&quot;</span><span class="p">)</span>
<span class="n">m</span><span class="o">.</span><span class="n">data3</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="s">&quot;music&quot;</span>

<span class="n">m</span><span class="o">.</span><span class="n">sgn</span><span class="o">.</span><span class="n">emit</span><span class="p">(</span><span class="s">&quot;Hello world!&quot;</span><span class="p">)</span>
<span class="n">m</span><span class="o">.</span><span class="n">sgn</span> <span class="o">=</span> <span class="n">Signal</span><span class="p">()</span> <span class="c"># sgn is reassigned</span>
</pre></div>
</div>
<p>The execution of this example produces the following output:</p>
<div class="highlight-python"><pre>assign_notification: data1 10 11
another_assign_notification: data1 10 11
&gt;&gt;&gt; Here m.data is 11
assign_notification: data2 a string Another string
before_call_notification: data3 ['gtkmvc', 'makes', 'your', 'life', 'easier'] append
before_after_call_notification: BEFORE: data3 ['gtkmvc', 'makes', 'your', 'life', 'easier'] append
before_after_call_notification: AFTER: data3 ['gtkmvc', 'makes', 'your', 'life', 'easier', 'and fun'] append None
before_call_notification: data3 ['gtkmvc', 'makes', 'your', 'life', 'easier', 'and fun'] __setitem__
before_after_call_notification: BEFORE: data3 ['gtkmvc', 'makes', 'your', 'life', 'easier', 'and fun'] __setitem__
before_after_call_notification: AFTER: data3 ['music', 'makes', 'your', 'life', 'easier', 'and fun'] __setitem__ None
signal_notification: SIGNAL: sgn Hello world!
signal_notification: ASSIGN: sgn &lt;gtkmvc.observable.Signal object at 0x7f88957f5fd0&gt; &lt;gtkmvc.observable.Signal object at 0x7f8895801ad0&gt;</pre>
</div>
<p>Of course an observer is not limited to observe one model:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">m1</span> <span class="o">=</span> <span class="n">MyModel</span><span class="p">()</span>
<span class="n">o</span> <span class="o">=</span> <span class="n">MyObserver</span><span class="p">(</span><span class="n">m1</span><span class="p">)</span> <span class="c"># o observes m1</span>
<span class="n">m2</span> <span class="o">=</span> <span class="n">AnotherModel</span><span class="p">()</span>
<span class="n">o</span><span class="o">.</span><span class="n">observe_model</span><span class="p">(</span><span class="n">m2</span><span class="p">)</span> <span class="c"># o observes also m2 now</span>
</pre></div>
</div>
<p>It is usual to see models observing other models, like siblings or
sub-models in model hierarchies. For this reason class <tt class="docutils literal"><span class="pre">Model</span></tt>
derives from class <tt class="docutils literal"><span class="pre">Observer</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">m3</span> <span class="o">=</span> <span class="n">AnotherModel</span><span class="p">()</span>
<span class="n">m3</span><span class="o">.</span><span class="n">observe_model</span><span class="p">(</span><span class="n">m2</span><span class="p">)</span> <span class="c"># m3 observes m2</span>
</pre></div>
</div>
</div>
<div class="section" id="controllers">
<h2>Controllers<a class="headerlink" href="#controllers" title="Permalink to this headline"></a></h2>
<p>Controllers are the most complex structures that are intended to:</p>
<ol class="arabic simple">
<li>Contain the GUI logic.</li>
<li>Connect one model and one or more views, without making them know.</li>
<li>Observe the model they are connected to.</li>
<li>Provide handlers for gtk signals (declared in the views connected to it)</li>
<li>Setting up widgets that depend on the model. For example setting up
of <tt class="docutils literal"><span class="pre">gtk.TreeView</span></tt> whose <tt class="docutils literal"><span class="pre">gtk.TreeModel</span></tt> lives within the model
(see <a class="reference internal" href="#gtk-treeview"><em>TreeViews and relatives</em></a>)</li>
<li>Setting up <a class="reference internal" href="#adapters"><em>Adapters</em></a></li>
</ol>
<p>This is the typical structure of a controller:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">gtkmvc</span> <span class="kn">import</span> <span class="n">Controller</span>

<span class="k">class</span> <span class="nc">MyController</span> <span class="p">(</span><span class="n">Controller</span><span class="p">):</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">model</span><span class="p">,</span> <span class="n">view</span><span class="p">):</span>
        <span class="n">Controller</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">model</span><span class="p">,</span> <span class="n">view</span><span class="p">)</span>

        <span class="c"># From here on the connected model and view are accessible</span>
        <span class="c"># through fields &#39;self.model&#39; and &#39;self.view&#39; respectively.</span>

        <span class="c"># setup internal fields...</span>

        <span class="c"># setup sub-controllers...</span>

        <span class="k">return</span>

    <span class="k">def</span> <span class="nf">register_view</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">view</span><span class="p">):</span>
        <span class="c"># initializes the view if needed</span>

        <span class="c"># setup widgets that need a model, like TreeView (see next section)...</span>

        <span class="c"># setup widgets not specified in glade, like TreeViewColumn...</span>

        <span class="c"># connect additional signals (e.g. for manually constructed widgets...</span>

        <span class="k">return</span>

    <span class="k">def</span> <span class="nf">register_adapters</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="c"># setup all adapters (see Adapters below)</span>
        <span class="k">return</span>

    <span class="c"># ------------------------------------------------------------</span>
    <span class="c">#      GTK Signal handlers</span>
    <span class="c"># ------------------------------------------------------------</span>
    <span class="k">def</span> <span class="nf">on_button_clicked</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">button</span><span class="p">):</span>
        <span class="c"># ...</span>
        <span class="k">return</span>

    <span class="c"># ...</span>

    <span class="c"># ------------------------------------------------------------</span>
    <span class="c">#      Notifications of observable properties</span>
    <span class="c"># ------------------------------------------------------------</span>
    <span class="nd">@Controller.observe</span><span class="p">(</span><span class="s">&quot;prop_name&quot;</span><span class="p">,</span> <span class="n">assign</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
    <span class="k">def</span> <span class="nf">notification</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">model</span><span class="p">,</span> <span class="n">prop_name</span><span class="p">,</span> <span class="n">info</span><span class="p">):</span>
        <span class="c">#...</span>
        <span class="k">return</span>

    <span class="k">pass</span> <span class="c"># end of class</span>
</pre></div>
</div>
<p>As you see, a controller does a lot of work, and tends to blow-up in
size. For this reason it is important to split big controllers into
sub-controllers. In a typical configuration, the application model is
split into sub-modules, say <em>m1</em>, <em>m2</em> and <em>m3</em>.
The application controller is split into several sub-controllers, and
there are sub controllers <em>c1</em>, <em>c2</em> and <em>c3</em> respectively controlling
just <em>m1</em>, <em>m2</em> and <em>m3</em>.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># file model.py</span>
<span class="kn">from</span> <span class="nn">gtkmvc</span> <span class="kn">import</span> <span class="n">Model</span>
<span class="k">class</span> <span class="nc">ApplModel</span> <span class="p">(</span><span class="n">Model</span><span class="p">):</span>
  <span class="c"># observable properties...</span>

  <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
      <span class="n">Model</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

      <span class="c"># sub-models:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">m1</span> <span class="o">=</span> <span class="n">MyModel1</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">m2</span> <span class="o">=</span> <span class="n">MyModel2</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">m3</span> <span class="o">=</span> <span class="n">MyModel3</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

      <span class="c"># say you want to observe what happens within m3</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">observe_model</span><span class="p">(</span><span class="n">m3</span><span class="p">)</span>
      <span class="k">return</span>

  <span class="c"># ...</span>
  <span class="k">pass</span> <span class="c"># end of class</span>
</pre></div>
</div>
<p>Here only class <tt class="docutils literal"><span class="pre">MyModel1</span></tt> is reported:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># file model.py</span>
<span class="k">class</span> <span class="nc">MyModel1</span> <span class="p">(</span><span class="n">Model</span><span class="p">):</span>
  <span class="c"># observable properties...</span>

  <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">appl</span><span class="p">):</span>
      <span class="n">Model</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">appl_model</span> <span class="o">=</span> <span class="n">appl</span>
      <span class="c">#...</span>
      <span class="k">return</span>
  <span class="k">pass</span>
</pre></div>
</div>
<p>The controllers have a similar structure:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># file ctrl.py</span>
<span class="kn">from</span> <span class="nn">gtkmvc</span> <span class="kn">import</span> <span class="n">Controller</span>
<span class="k">class</span> <span class="nc">ApplCtrl</span> <span class="p">(</span><span class="n">Controller</span><span class="p">):</span>

  <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">appl_model</span><span class="p">,</span> <span class="n">appl_view</span><span class="p">):</span>
      <span class="n">Controller</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">appl_model</span><span class="p">,</span> <span class="n">appl_view</span><span class="p">)</span>

      <span class="c"># sub-controllers</span>

      <span class="c"># appl_view is shared among application and c1 controllers</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">c1</span> <span class="o">=</span> <span class="n">MyCtrl1</span><span class="p">(</span><span class="n">appl_model</span><span class="o">.</span><span class="n">m1</span><span class="p">,</span> <span class="n">appl_view</span><span class="p">)</span>

      <span class="c"># c2 controls subview v2</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">c2</span> <span class="o">=</span> <span class="n">MyCtrl</span><span class="p">(</span><span class="n">appl_model</span><span class="o">.</span><span class="n">m2</span><span class="p">,</span> <span class="n">appl_view</span><span class="o">.</span><span class="n">v2</span><span class="p">)</span>
      <span class="c">#...</span>
      <span class="k">return</span>
  <span class="k">pass</span>
</pre></div>
</div>
<p>However, it is pretty common to have controllers split also to control
different parts of a view. For example, the application (top) level
controller made of three sub-controllers, respectively controlling the
application main window, the toolbars, and the main component
featuring in the main window. The key here is to split the complexity
into pieces which can harmoniously live together.</p>
<div class="section" id="treeviews-and-relatives">
<span id="gtk-treeview"></span><h3><a class="reference external" href="http://www.pygtk.org/docs/pygtk/class-gtktreeview.html">TreeViews</a> and relatives<a class="headerlink" href="#treeviews-and-relatives" title="Permalink to this headline"></a></h3>
<p><tt class="docutils literal"><span class="pre">gtk</span></tt> makes a limited use of the MVC pattern for some widgets. Those
are the <tt class="docutils literal"><span class="pre">TextView</span></tt>, the <tt class="docutils literal"><span class="pre">TreeView</span></tt> and all those widgets that are
based on the <tt class="docutils literal"><span class="pre">TreeModel</span></tt> class.</p>
<p>How does <em>gtkmvc</em> click on this architecture?</p>
<ol class="arabic simple">
<li>Widgets like <tt class="docutils literal"><span class="pre">TreeView</span></tt>, <tt class="docutils literal"><span class="pre">TextView</span></tt>, etc. live into the view side.</li>
<li>Model side of those widgets like <tt class="docutils literal"><span class="pre">TextBuffer</span></tt>, <tt class="docutils literal"><span class="pre">ListStore</span></tt>,
etc. have to live into the model.</li>
<li>The controller is responsible for connecting the view parts with the
model parts.</li>
</ol>
<p>The view is based on the glade file shown here:</p>
<img alt="_images/mvc_glade.png" src="_images/mvc_glade.png" />
<p>This is the full code for this example:</p>
<div class="highlight-python"><pre>import gtk
from gtkmvc import View
class MyView(View):
   glade = "mvc.glade"
   pass # end of class

from gtkmvc import Model
class MyModel (Model):
   # ...
   text_buf = gtk.TextBuffer()
   list_store = gtk.ListStore(int, str)
   # ...
   def __init__(self):
       Model.__init__(self)
       text = """gtkmvc is a thin framework for
developing GUI applications with
Python and the pygtk toolkit."""
       # fills in some data
   self.text_buf.set_text(text)
       for n, word in enumerate(text.split()):
           self.list_store.append([n+1,word])
           pass
       return

   pass # end of class

from gtkmvc import Controller
class MyCtrl (Controller):
   # ...

   def register_view(self, view):
       text_view = view['textview']
   # connects the buffer and the text view
   text_view.set_buffer(self.model.text_buf)

   # connects the treeview to the liststore
   tv = view['treeview']
       tv.set_model(self.model.list_store)

   # creates the columns of the treeview
       rend = gtk.CellRendererText()
       col = gtk.TreeViewColumn('Col1', rend, text=0)
       tv.append_column(col)

       rend = gtk.CellRendererText()
       col = gtk.TreeViewColumn('Col2', rend, text=1)
       tv.append_column(col)
   return
   pass # end of class

# running triplet
m = MyModel()
v = MyView()
c = MyCtrl(m,v)
gtk.main()</pre>
</div>
<p>When executed, this is what pops up:</p>
<img alt="_images/mvc.png" src="_images/mvc.png" />
</div>
</div>
<div class="section" id="adapters">
<span id="id3"></span><h2>Adapters<a class="headerlink" href="#adapters" title="Permalink to this headline"></a></h2>
<p>Adapters <em>adapt</em> widgets in the view and attributes (possibly
observable) in the model.</p>
<p>Basically they automatically connect some signal of widgets to align
shown data to data stored into the model.</p>
<p>Class <tt class="docutils literal"><span class="pre">Controller</span></tt> offers method <tt class="docutils literal"><span class="pre">register_adapters</span></tt> that is the
ideal place when setting up adapters.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">gtkmvc</span> <span class="kn">import</span> <span class="n">View</span>
<span class="k">class</span> <span class="nc">MyView</span> <span class="p">(</span><span class="n">View</span><span class="p">):</span>
   <span class="n">glade</span> <span class="o">=</span> <span class="s">&quot;example.glade&quot;</span>
   <span class="k">pass</span> <span class="c"># end of class</span>
</pre></div>
</div>
<p>Glade file <tt class="docutils literal"><span class="pre">example.glade</span></tt> is shown here in <tt class="docutils literal"><span class="pre">glade-3</span></tt>.</p>
<img alt="_images/example_glade.png" src="_images/example_glade.png" />
<p>There are four widgets we want to keep aligned to the corresponding
values stored into the model.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">gtkmvc</span> <span class="kn">import</span> <span class="n">Model</span>
<span class="k">class</span> <span class="nc">MyModel</span> <span class="p">(</span><span class="n">Model</span><span class="p">):</span>
   <span class="n">data1</span> <span class="o">=</span> <span class="s">&quot;Some descriptive message&quot;</span>
   <span class="n">data2</span> <span class="o">=</span> <span class="s">&quot;Some textual data&quot;</span>
   <span class="n">data3</span> <span class="o">=</span> <span class="mi">10</span>
   <span class="n">data4</span> <span class="o">=</span> <span class="bp">True</span> <span class="c"># a flag</span>

   <span class="n">__observables__</span> <span class="o">=</span> <span class="p">(</span><span class="s">&quot;data?&quot;</span><span class="p">,)</span>

   <span class="k">pass</span> <span class="c"># end of class</span>
</pre></div>
</div>
<p>Now to connect the view and the model, we need a controller. Here an
adapter is built to adapt label <tt class="docutils literal"><span class="pre">label_data1</span></tt> to the observable
property <tt class="docutils literal"><span class="pre">data1</span></tt>.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">gtkmvc</span> <span class="kn">import</span> <span class="n">Controller</span>
<span class="kn">from</span> <span class="nn">gtkmvc.adapters</span> <span class="kn">import</span> <span class="n">Adapter</span>
<span class="kn">import</span> <span class="nn">gtk</span>

<span class="k">class</span> <span class="nc">MyCtrl</span> <span class="p">(</span><span class="n">Controller</span><span class="p">):</span>
   <span class="k">def</span> <span class="nf">register_view</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">view</span><span class="p">):</span>
       <span class="c"># we connect manually as the glade file does not contain this signal handler</span>
       <span class="n">view</span><span class="p">[</span><span class="s">&#39;window1&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="s">&#39;destroy&#39;</span><span class="p">,</span> <span class="n">gtk</span><span class="o">.</span><span class="n">mainquit</span><span class="p">)</span>
   <span class="k">return</span>

   <span class="k">def</span> <span class="nf">register_adapters</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
       <span class="n">ad</span> <span class="o">=</span> <span class="n">Adapter</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="p">,</span> <span class="s">&quot;data1&quot;</span><span class="p">)</span>
       <span class="n">ad</span><span class="o">.</span><span class="n">connect_widget</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">view</span><span class="p">[</span><span class="s">&quot;label_data1&quot;</span><span class="p">],</span>
             <span class="n">setter</span><span class="o">=</span><span class="k">lambda</span> <span class="n">w</span><span class="p">,</span><span class="n">v</span><span class="p">:</span> <span class="n">w</span><span class="o">.</span><span class="n">set_markup</span><span class="p">(</span><span class="s">&quot;&lt;big&gt;&lt;b&gt;</span><span class="si">%s</span><span class="s">&lt;/b&gt;&lt;/big&gt;&quot;</span> <span class="o">%</span> <span class="n">v</span><span class="p">))</span>
       <span class="bp">self</span><span class="o">.</span><span class="n">adapt</span><span class="p">(</span><span class="n">ad</span><span class="p">)</span>
   <span class="k">return</span>

   <span class="k">pass</span> <span class="c"># end of class</span>
</pre></div>
</div>
<p>Optional parameter <tt class="docutils literal"><span class="pre">setter</span></tt> is called when it is time to write the
value into the given widget. Here it used to markup the text.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">There are similar parameters for getting, setting and error
handling that can be called both when getting/setting the
value from/to the model and the widget. Adapters are complex
entities that can be further developed, see the User
Manual for a complete description.</p>
</div>
<p>Finally, we need only to create a <strong>MVC</strong> triplet and run <tt class="docutils literal"><span class="pre">gtk</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">m</span> <span class="o">=</span> <span class="n">MyModel</span><span class="p">()</span>
<span class="n">v</span> <span class="o">=</span> <span class="n">MyView</span><span class="p">()</span>
<span class="n">c</span> <span class="o">=</span> <span class="n">MyCtrl</span><span class="p">(</span><span class="n">m</span><span class="p">,</span><span class="n">v</span><span class="p">)</span>

<span class="n">gtk</span><span class="o">.</span><span class="n">main</span><span class="p">()</span>
</pre></div>
</div>
<p>Here you see the result.</p>
<img alt="_images/example.png" src="_images/example.png" />
<p>Method <tt class="docutils literal"><span class="pre">Controller.adapt</span></tt> is polymorphic, offering several
variants. One can be exploited for basic tasks like dry connection of
a widget and a corresponding property in the model.</p>
<p>In the example we connect all the widgets very easily:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">gtkmvc</span> <span class="kn">import</span> <span class="n">Controller</span>
<span class="kn">import</span> <span class="nn">gtk</span>

<span class="k">class</span> <span class="nc">MyCtrl</span> <span class="p">(</span><span class="n">Controller</span><span class="p">):</span>
   <span class="k">def</span> <span class="nf">register_view</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">view</span><span class="p">):</span>
       <span class="c"># we connect manually as the glade file does not contain this signal handler</span>
       <span class="n">view</span><span class="p">[</span><span class="s">&#39;window1&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="s">&#39;destroy&#39;</span><span class="p">,</span> <span class="n">gtk</span><span class="o">.</span><span class="n">mainquit</span><span class="p">)</span>
   <span class="k">return</span>

   <span class="k">def</span> <span class="nf">register_adapters</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
       <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="p">(</span><span class="s">&quot;data1&quot;</span><span class="p">,</span> <span class="s">&quot;data2&quot;</span><span class="p">,</span> <span class="s">&quot;data3&quot;</span><span class="p">,</span> <span class="s">&quot;data4&quot;</span><span class="p">):</span> <span class="bp">self</span><span class="o">.</span><span class="n">adapt</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
   <span class="k">return</span>

   <span class="k">pass</span> <span class="c"># end of class</span>
</pre></div>
</div>
<p>Very compact isn&#8217;t it? Here you see the result of this magic, where
the widgets&#8217; content reflect the initial values of the observable
properties they are attached to.</p>
<img alt="_images/example2.png" src="_images/example2.png" />
<p>What is really interesting is that if you change the value of a widget
(say, you change the text in the text entry, or in the spinbutton),
also the value of the corresponding property in the model gets
changed, and viceversa if the properties are also observable.</p>
</div>
<div class="section" id="where-do-you-go-now">
<h2>Where do you go now?<a class="headerlink" href="#where-do-you-go-now" title="Permalink to this headline"></a></h2>
<p>Good reading so far? If you are interested, you can download and
install <strong>gtkmvc</strong>, see the examples provided along with it, read the
User Manual, read the Tutorial, subscribe to the project mailing list,
send feedback to the user, and - most of all - <em>start using it</em>!</p>
<p class="rubric">Footnotes</p>
<table class="docutils footnote" frame="void" id="fn1" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id1">[1]</a></td><td>Or any class derived from <tt class="docutils literal"><span class="pre">gtkmvc.Model</span></tt>, see the User Manual</td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="fn2" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id2">[2]</a></td><td>See Python module
<a class="reference external" href="http://docs.python.org/library/fnmatch.html">fnmatch</a>
for information about accepted wildcards</td></tr>
</tbody>
</table>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="#">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">gtkmvc in 45 minutes</a><ul>
<li><a class="reference internal" href="#introduction">Introduction</a><ul>
<li><a class="reference internal" href="#what-is-gtkmvc-and-what-it-does">What is gtkmvc, and what it does</a></li>
<li><a class="reference internal" href="#some-terminology">Some terminology</a></li>
<li><a class="reference internal" href="#what-is-all-this-complexity-for">What is all this complexity for?</a></li>
</ul>
</li>
<li><a class="reference internal" href="#views">Views</a></li>
<li><a class="reference internal" href="#models">Models</a><ul>
<li><a class="reference internal" href="#observable-properties">Observable Properties</a><ul>
<li><a class="reference internal" href="#value-properties">1. Value Properties</a></li>
<li><a class="reference internal" href="#logical-properties">2. Logical Properties</a></li>
<li><a class="reference internal" href="#mutable-containers">3. Mutable containers</a></li>
<li><a class="reference internal" href="#mutable-class-instances">4. Mutable class instances</a></li>
<li><a class="reference internal" href="#signals">5. Signals</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#observers">Observers</a></li>
<li><a class="reference internal" href="#controllers">Controllers</a><ul>
<li><a class="reference internal" href="#treeviews-and-relatives">TreeViews and relatives</a></li>
</ul>
</li>
<li><a class="reference internal" href="#adapters">Adapters</a></li>
<li><a class="reference internal" href="#where-do-you-go-now">Where do you go now?</a></li>
</ul>
</li>
</ul>

  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="_sources/index.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li><a href="#">gtkmvc: A Quickstart Guide 1.99.1 documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2010, Roberto Cavada.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
    </div>
  </body>
</html>