-
Notifications
You must be signed in to change notification settings - Fork 0
/
gnc_utils.py
182 lines (139 loc) · 5.32 KB
/
gnc_utils.py
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
# utilities for combo objects
import types
#from gi.repository import GObject
from gi.repository import Gtk
from datetime import datetime
import pdb
import sw_app_utils
import gnucash
def N_(msg):
return msg
# define this response constant here
RESPONSE_NEW = 1
if True:
def set_by_string (self, text):
model = self.get_model()
iter = model.get_iter_first()
if not iter:
self.set_active(-1)
return
column = self.get_entry_text_column()
while True:
tree_string = model.get_value(iter,column)
if tree_string != text:
iter = model.iter_next(iter)
if not iter:
break
continue
#self.get_data("changed_id")
id = self.changed_id
# we have an issue that something doesnt seem to be initialized right in the
# currency text box - which leads to "random" numbers being returned for id
# (once a currency has been selected things seem to work rightset)
# also have an issue that cannot delete in the currency text chooser drops
# immediately
# apparently you cannot edit the currency text in c code - MUST choose from drop down
# list - except the text box doesnt seem to be properly disabled
if not type(id) == int and not type(id) == long: pdb.set_trace()
self.handler_block(id)
self.set_active_iter(iter)
self.handler_unblock(id)
index = self.get_active()
#self.set_data("last_index",index)
self.last_index = index
return
def add_completion (self):
entry = self.get_child()
completion = entry.get_completion()
if completion:
return
completion = Gtk.EntryCompletion()
model = self.get_model()
completion.set_model(model)
completion.set_text_column(0)
completion.set_inline_completion(True)
entry.set_completion(completion)
def require_list_item (self):
print("gnc_cbwe_require_list_item",self)
self.add_completion()
entry = self.get_child()
completion = entry.get_completion()
index = self.get_active()
if index == -1:
model = completion.get_model()
iter = model.get_iter_first()
if iter:
self.set_active(0)
self.last_index = index
id = self.connect("changed", self.changed_cb)
completion.connect("match_selected", self.match_selected_cb)
entry.connect("focus-out-event", self.focus_out_cb)
print("gnc_cbwe_require_list_item",self,"changed_id",id)
#self.set_data("changed_id", id)
self.changed_id = id
print("gnc_cbwe_require_list_item",self,"changed_id",id,self.changed_id)
def focus_out_cb (self, entry, event):
print("gnc_cbwe_focus_out_cb")
text = entry.get_text()
self.set_by_string(text)
index = self.last_index
self.set_active(index)
return False
def changed_cb (self, *args):
print("gnc_cbwe_changed_cb",args)
widget = args[0]
index = widget.get_active()
if index == -1:
return
self.last_index = index
def match_selected_cb (self, *args):
print("gnc_cbwe_match_selected_cb",args)
column = self.get_entry_text_column()
text = comp_model.get(comp_iter,0)
# unfortunately unless I can figure out how to do dynamic subclasses
# this seems to be the only way
# define the functions at the module level
# store them in the Mixin class
# hopefully can then use them as Mixin and objects
class GncCBWEMixin(object):
pass
GncCBWEMixin.set_by_string = set_by_string
GncCBWEMixin.add_completion = add_completion
GncCBWEMixin.require_list_item = require_list_item
GncCBWEMixin.focus_out_cb = focus_out_cb
GncCBWEMixin.changed_cb = changed_cb
GncCBWEMixin.match_selected_cb = match_selected_cb
def add_utils (combo_object):
# try adding directly as attributes
# this seems to work
combo_object.set_by_string = types.MethodType(set_by_string, combo_object)
combo_object.add_completion = types.MethodType(add_completion, combo_object)
combo_object.require_list_item = types.MethodType(require_list_item, combo_object)
combo_object.focus_out_cb = types.MethodType(focus_out_cb, combo_object)
combo_object.changed_cb = types.MethodType(changed_cb, combo_object)
combo_object.match_selected_cb = types.MethodType(match_selected_cb, combo_object)
# new attempt - make a proper class using the mixin
# - then use instantiation of this where need to
class GncCBWE(GncCBWEMixin):
def __init__ (self):
#self.gnc_cbwe = GncCBWEMixin()
pass
# try using classmethods
# this is probably not going to work
# may need static methods
@classmethod
def gnc_cbwe_set_by_string (cls, text):
cls.set_by_string(text)
def gnc_cbwe_add_completion (self):
pass
@classmethod
def gnc_cbwe_require_list_item (cls):
cls.require_list_item()
def gnc_cbwe_focus_out_cb (self, *args):
pass
def gnc_cbwe_changed_cb (self, *args):
pass
def gnc_cbwe_match_selected_cb (self, *args):
pass
def gnc_cbwe_set_by_string (self, text):
pass