2
# @file geisview/filter_definition.py
3
# @brief A GEIS filter definition dialog
5
# Copyright (C) 2011 Canonical Ltd
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.
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.
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/>.
21
from __future__ import print_function, absolute_import, unicode_literals
24
import geisview.defaults
30
# A list of filter facilities to choose from
31
geis_filter_facilities = ('GEIS_FILTER_REGION',
35
geis_region_terms = ('GEIS_REGION_ATTRIBUTE_WINDOWID')
37
geis_device_terms = ('GEIS_DEVICE_ATTRIBUTE_ID',
38
'GEIS_DEVICE_ATTRIBUTE_DIRECT_TOUCH')
40
geis_gesture_terms = ('GEIS_GESTURE_ATTRIBUTE_TOUCHES',
41
'GEIS_CLASS_ATTRIBUTE_NAME')
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': '<='}
50
facility_combo_name_col = 0
51
facility_combo_value_col = 1
54
def populate_term_op(store):
55
for (name, symbol) in geis_term_op:
57
store.set(row, symbol, geis.__dict__[name])
60
class FilterDefinition(object):
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)
69
# prime the name field
70
self._dialog = builder.get_object("filter_definition");
71
self._name_entry = builder.get_object("name_entry");
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)
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")
87
self._ok_button = builder.get_object("ok_button");
88
self._dialog.show_all()
89
print "FilterDefinition.__init__() ends"
92
print "FilterDefinition.run() begins"
93
response = self._dialog.run()
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
101
def on_name_changed(self, widget, data=None):
102
name = self._name_entry.get_text()
104
self._ok_button.set_sensitive(True)
106
self._ok_button.set_sensitive(False)
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,
116
def on_edit_term(self, widget, data=None):
117
print "FilterDefinition.on_edit_term()"
119
def on_remove_term(self, widget, data=None):
120
print "FilterDefinition.on_remove_term()"
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)
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)