~ubuntu-branches/ubuntu/saucy/geis/saucy-proposed

« back to all changes in this revision

Viewing changes to .pc/python-fix-print-syntax.patch/tools/geisview/filter_definition.py

  • Committer: Package Import Robot
  • Author(s): Luke Yelavich
  • Date: 2012-11-14 14:52:22 UTC
  • Revision ID: package-import@ubuntu.com-20121114145222-c3z09cyxbip191kf
Tags: 2.2.14-0ubuntu2
Fix python print syntax. (LP: #1077419)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# @file geisview/filter_definition.py
 
3
# @brief A GEIS filter definition dialog
 
4
#
 
5
# Copyright (C) 2011 Canonical Ltd
 
6
#
 
7
# This program is free software; you can redistribute it and/or modify
 
8
# it under the terms of the GNU General Public License as published by
 
9
# the Free Software Foundation; either version 3 of the License, or
 
10
# (at your option) any later version.
 
11
#
 
12
# This program is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
# GNU General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU General Public License
 
18
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
#
 
20
 
 
21
from __future__ import print_function, absolute_import, unicode_literals
 
22
 
 
23
import geis
 
24
import geisview.defaults
 
25
import os
 
26
import pygtk
 
27
pygtk.require("2.0")
 
28
import gtk
 
29
 
 
30
# A list of filter facilities to choose from
 
31
geis_filter_facilities = ('GEIS_FILTER_REGION',
 
32
                          'GEIS_FILTER_DEVICE',
 
33
                          'GEIS_FILTER_CLASS')
 
34
 
 
35
geis_region_terms = ('GEIS_REGION_ATTRIBUTE_WINDOWID')
 
36
 
 
37
geis_device_terms = ('GEIS_DEVICE_ATTRIBUTE_ID', 
 
38
                     'GEIS_DEVICE_ATTRIBUTE_DIRECT_TOUCH')
 
39
 
 
40
geis_gesture_terms = ('GEIS_GESTURE_ATTRIBUTE_TOUCHES',
 
41
                      'GEIS_CLASS_ATTRIBUTE_NAME')
 
42
 
 
43
geis_term_op = {'GEIS_FILTER_OP_EQ': '==',
 
44
                'GEIS_FILTER_OP_NE': '!=',
 
45
                'GEIS_FILTER_OP_GT': '>',
 
46
                'GEIS_FILTER_OP_GE': '>=',
 
47
                'GEIS_FILTER_OP_LT': '<',
 
48
                'GEIS_FILTER_OP_LE': '<='}
 
49
 
 
50
facility_combo_name_col  = 0
 
51
facility_combo_value_col = 1
 
52
 
 
53
 
 
54
def populate_term_op(store):
 
55
    for (name, symbol) in geis_term_op:
 
56
        row = store.append()
 
57
        store.set(row, symbol, geis.__dict__[name])
 
58
 
 
59
 
 
60
class FilterDefinition(object):
 
61
 
 
62
    def __init__(self):
 
63
        print "FilterDefinition.__init__() begins"
 
64
        builder = gtk.Builder()
 
65
        builder.add_from_file(os.path.join(geisview.defaults.ui_dir,
 
66
                                           "filter_definition.ui"))
 
67
        builder.connect_signals(self)
 
68
 
 
69
        # prime the name field
 
70
        self._dialog = builder.get_object("filter_definition");
 
71
        self._name_entry = builder.get_object("name_entry");
 
72
 
 
73
        # prime the facility combo
 
74
        self._facility_store = builder.get_object("facility_store");
 
75
        for fac in geis_filter_facilities:
 
76
            row = self._facility_store.append()
 
77
            self._facility_store.set(row,
 
78
                                     facility_combo_name_col,  fac,
 
79
                                     facility_combo_value_col, geis.__dict__[fac])
 
80
        self._facility_combo = builder.get_object("facility_combo");
 
81
        self._facility_combo.set_active(0)
 
82
 
 
83
        # prime the filter terms
 
84
        self._term_list_view = builder.get_object("term_list_view");
 
85
        self._term_list_store = builder.get_object("term_list_store")
 
86
 
 
87
        self._ok_button = builder.get_object("ok_button");
 
88
        self._dialog.show_all()
 
89
        print "FilterDefinition.__init__() ends"
 
90
     
 
91
    def run(self):
 
92
        print "FilterDefinition.run() begins"
 
93
        response = self._dialog.run()
 
94
        if (response):
 
95
            name = self._name_entry.get_text()
 
96
            print "FilterDefinition.run() name=%s" % name
 
97
            print "FilterDefinition.run() facility=%s" % self._facility_store[self._facility_combo.get_active()][facility_combo_value_col]
 
98
        self._dialog.destroy()
 
99
        print "FilterDefinition.run() ends, response=%s" % response
 
100
 
 
101
    def on_name_changed(self, widget, data=None):
 
102
        name = self._name_entry.get_text()
 
103
        if len(name) > 0:
 
104
            self._ok_button.set_sensitive(True)
 
105
        else:
 
106
            self._ok_button.set_sensitive(False)
 
107
        
 
108
    def on_add_term(self, widget, data=None):
 
109
        print "FilterDefinition.on_add_term()"
 
110
        row = self._term_list_store.append()
 
111
        self._term_list_store.set(row,
 
112
                                  0, "<attr name>",
 
113
                                  1, "==",
 
114
                                  2, "<value>")
 
115
 
 
116
    def on_edit_term(self, widget, data=None):
 
117
        print "FilterDefinition.on_edit_term()"
 
118
 
 
119
    def on_remove_term(self, widget, data=None):
 
120
        print "FilterDefinition.on_remove_term()"
 
121
 
 
122
    def on_term_attr_editing_started(self, widget, entry, path, data=None):
 
123
        print "FilterDefinition.on_term_attr_editing_started()"
 
124
        choices = gtk.ListStore(str, str)
 
125
        for c in geis_gesture_terms:
 
126
            choices.append([c, geis.__dict__[c]])
 
127
        completion = gtk.EntryCompletion()
 
128
        completion.set_model(choices)
 
129
        completion.set_text_column(0)
 
130
        completion.set_inline_completion(True)
 
131
        completion.set_popup_completion(False)
 
132
        entry.set_completion(completion)
 
133
        entry.set_text("")
 
134
 
 
135
    def on_term_op_edited(self, widget, path, new_text, data=None):
 
136
        print "FilterDefinition.on_term_op_edited(%s, %s, %s)" % (widget, path, new_text)
 
137