-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdialog_options.py
More file actions
1908 lines (1503 loc) · 67.7 KB
/
dialog_options.py
File metadata and controls
1908 lines (1503 loc) · 67.7 KB
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
# this is a recoding of the options dialog (defined in dialog-options.c)
# in python
# needed because dialog-options.c has functions with SCM data
# which need to be replaced
# some functions also taken from option-util.c in app-utils
import os
import sys
import bisect
import numbers
import time
import traceback
import pdb
from operator import attrgetter
from gi.repository import GObject
from gi.repository import Gtk
from gi.repository import Gdk
import ctypes
import gc
import sw_core_utils
import sw_app_utils
try:
from gnc_builder import GncBuilder
from gnc_date_edit import GncDateEdit
from gnc_currency_edit import GncCurrencyEdit
from gnc_general_select import GncGeneralSelect
from gnc_commodity_edit import GncCommodityEdit
import gnc_tree_view_account
except Exception as errexc:
traceback.print_exc()
pdb.set_trace()
import gnucash
from gnucash_log import PERR
log_module = "gnc.gui.python"
NUM_ACCOUNT_TYPES = gnucash.gnucash_core_c.NUM_ACCOUNT_TYPES
# junky internationalization function
def N_(msg):
return msg
# option dialog calls
#12 0x000000010003f262 in gnc_plugin_page_report_options_cb ()
#1 0x000000010004135a in gnc_report_window_default_params_editor ()
#0 0x00000001001e9354 in gnc_options_dialog_build_contents ()
class GncOption(object):
# ah - the primary purpose of this class is to provide the functionality
# to interact with an options value through the gtk GUI
def __init__ (self, guile_option, changed=False, widget=None, odb=None):
self.guile_option = guile_option
self.changed = changed
self.widget = widget
self.odb = odb
# we may define a widget_changed_proc
#self.widget_changed_proc = None
def get_ui_value (self):
# OK this is really stupid - we have multiple redirection here
# we call a function in the GncOptionDB class
# which by default is set to the internal function in this class
# note that this is for getting the option value from the GUI
# and storing it in the basic option
#return self.odb.get_ui_value(self)
# for the moment punt just call the internal function directly
return self.get_ui_value_internal()
def set_ui_value (self, use_default):
# this is weird - wheres the value
# not needed - this sets the ui widget value to the option value!!
#if self.odb.get_ui_value == None:
# return
#self.odb.set_ui_value(self,use_default)
# for the moment punt just call the internal function directly
self.set_ui_value_internal(use_default)
def ui_get_option (self, option_type_name):
# this should really be ui_get_option_type
global optionTable
if option_type_name in optionTable:
return optionTable[option_type_name]
else:
PERR(log_module,"Option lookup for type '%s' failed!"%option_type_name)
print("Option lookup for type '%s' failed!"%option_type_name)
pdb.set_trace()
return None
def value_validator (self):
if hasattr(self.guile_option, 'value_validator'):
return self.guile_option.value_validator
else:
return None
def set_ui_value_internal (self, use_default):
# this uses the option type (string, boolean)
# to set the scheme value into the widget for the option
#pdb.set_trace()
widget = self.widget
if widget == None:
return None
option_type = self.guile_option.type
if use_default:
value = self.guile_option.default_getter()
else:
value = self.guile_option.getter()
option_def = self.ui_get_option(option_type)
if option_def:
bad_value = option_def.set_value(self,use_default,widget,value)
if bad_value:
PERR(log_module,"bad value")
print("bad value for option", option_type,self.guile_option.name,value)
pdb.set_trace()
pass
else:
PERR(log_module,"Unknown type. Ignoring.")
pdb.set_trace()
pass
def get_ui_value_internal (self):
widget = self.widget
if widget == None:
return None
option_type = self.guile_option.type
option_def = self.ui_get_option(option_type)
if option_def:
result = option_def.get_value(self,widget)
else:
PERR(log_module,"Unknown type for refresh. Ignoring.")
pdb.set_trace()
result = None
return result
def set_selectable_internal (self, selectable):
widget = self.widget
if widget == None:
return None
widget.set_sensitive(selectable)
def changed_internal (self, widget, sensitive):
# this needs to start in this class
print("GncOption changed_internal",str(widget),type(widget))
#pdb.set_trace()
#oldwidget = widget.get_ancestor(Gtk.Dialog)
print("changed_internal 1a",str(widget),isinstance(widget, Gtk.Dialog))
while widget and not isinstance(widget, Gtk.Dialog):
print("changed_internal 1a",str(widget),isinstance(widget, Gtk.Dialog))
widget = widget.get_parent()
print("changed_internal 2",str(widget),isinstance(widget, Gtk.Dialog))
if widget == None:
return
widget.set_response_sensitive(Gtk.ResponseType.OK, sensitive)
widget.set_response_sensitive(Gtk.ResponseType.APPLY, sensitive)
def call_widget_changed_proc (self):
if hasattr(self,"widget_changed_proc"):
value = self.get_ui_value()
if value != None:
self.widget_changed_proc(value)
def changed_widget_cb (self, entry):
print("changed_widget_cb",str(entry))
#pdb.set_trace()
#gc.collect()
self.changed = True
#self.call_widget_changed_proc()
# ah - the widget is the dialog box the option is in
self.changed_internal(entry,True)
def multichoice_cb (self, entry):
print("multichoice_cb")
# this just maps GtkColorButton to widget and calls changed_widget_cb
self.changed_widget_cb(entry)
def commit (self):
print("commit called")
value = self.get_ui_value()
if value == None:
return
validator = self.value_validator()
if validator != None:
result = validator(value)
else:
# punt for the moment
result = [True, value, None]
# from scheme looks like we get a list
if result == None or not isinstance(result,list):
PERR("bad validation result")
return
ok = result[0]
if not isinstance(ok,bool):
PERR("bad validation result")
return
if ok:
value = result[1]
self.guile_option.setter(value)
self.set_ui_value(False)
else:
oops = result[2]
if not isinstance(oops,str):
PERR("bad validation result")
return
#utf8 conversion here
name = self.name
section = self.section
if True:
dialog = Gtk.MessageDialog(None,Gtk.DialogFlags.DESTROY_WITH_PARENT,
Gtk.MessageType.ERROR,Gtk.ButtonsType.OK,N_("There is a problem with option %s:%s.\n%s")%(section,name,oops))
dialog.run()
dialog.destroy()
else:
print("There is a problem with option %s:%s.\n%s"%(section,name,oops))
def set_ui_widget (self, page_box):
packed = False
guile_option = self.guile_option
#ENTER("option %p(%s), box %p",
# option, gnc_option_name(option), page_box);
if guile_option.type == None:
#LEAVE("bad type");
return
raw_name = guile_option.name
if raw_name != None and raw_name != "":
name = N_(raw_name)
else:
name = None
raw_documentation = guile_option.documentation_string
if raw_documentation != None and raw_documentation != "":
documentation = N_(raw_documentation)
else:
documentation = None
# we store the option type (string, boolean etc) in optionTable
# and we lookup the function to use by option type
option_def = self.ui_get_option(guile_option.type)
value = None
enclosing = None
packed = None
# so in python I think we just set the function by the various option classes
# the scheme solution defines functions by type - with python would have
# functions by option instance - but cannot figure if would ever want to be able
# to change function definitions in middle of report globally by type
# interesting - we do need to add a first argument for this indirect call
# is it because we used the class definition of the function??
if option_def and option_def.set_widget != None:
try:
(value, enclosing, packed) = option_def.set_widget(self, page_box, name, documentation)
except Exception as errexc:
traceback.print_exc()
pdb.set_trace()
else:
PERR(log_module,"Unknown option type. Ignoring option \"%s\"."%name)
pdb.set_trace()
if not packed and enclosing != None:
eventbox = Gtk.EventBox()
eventbox.add(enclosing)
page_box.pack_start(eventbox, False, False, 0)
eventbox.set_tooltip_text(documentation)
if value != None:
value.set_tooltip_text(documentation)
def get_color_info (self, use_default):
if use_default:
#return self.guile_option.default_getter()
rgba = self.guile_option.default_getter()
scale = self.guile_option.option_data[0]
else:
#return self.guile_option.getter()
rgba = self.guile_option.getter()
scale = self.guile_option.option_data[0]
scale = 1.0/scale
red = rgba[0]*scale
green = rgba[1]*scale
blue = rgba[2]*scale
alpha = rgba[3]*scale
return (red, green, blue, alpha)
def get_range_info (self):
rng = self.guile_option.option_data
return rng
# load of set callback functions
def set_ui_widget_boolean (self, page_box, name, documentation):
#colon_name = name + ":"
#label = Gtk.Label(colon_name)
#label.set_alignment(1.0, 0.5)
#enclosing = Gtk.HBox(homogeneous=False, spacing=5)
enclosing = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5)
enclosing.set_homogeneous(False)
value = Gtk.CheckButton(label=name)
self.widget = value
self.set_ui_value(False)
value.connect("toggled",self.changed_widget_cb)
#enclosing.pack_start(label, False, False, 0)
enclosing.pack_start(value, False, False, 0)
enclosing.show_all()
# need to figure what goes on with packed - is it pass through??
return (value, enclosing, None)
def set_ui_value_boolean (self, use_default, widget, value):
if isinstance(value,bool):
widget.set_active(value)
return False
else:
return True
def get_ui_value_boolean (self, widget):
newval = widget.get_active()
return newval
def set_ui_widget_string (self, page_box, name, documentation):
colon_name = name + ":"
label = Gtk.Label(colon_name)
label.set_alignment(1.0, 0.5)
#enclosing = Gtk.HBox(homogeneous=False, spacing=0)
enclosing = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5)
enclosing.set_homogeneous(False)
value = Gtk.Entry()
self.widget = value
self.set_ui_value(False)
value.connect("changed",self.changed_widget_cb)
enclosing.pack_start(label, False, False, 0)
enclosing.pack_start(value, False, False, 0)
enclosing.show_all()
# need to figure what goes on with packed - is it pass through??
return (value, enclosing, None)
def set_ui_value_string (self, use_default, widget, value):
if isinstance(value,str):
# we get conversion to utf8 here - ignoring for the moment
widget.set_text(value)
return False
else:
return True
def get_ui_value_string (self, widget):
newstr = widget.get_text()
# need to check utf-8'ness here
return newstr
def set_ui_widget_text (self, page_box, name, documentation, enclosing=None, packed=None):
print("set_ui_widget_text")
def set_ui_value_text (self, use_default, widget, value):
print("set_ui_value_text")
def get_ui_value_text (self, widget):
print("get_ui_value_text")
def set_ui_widget_currency (self, page_box, name, documentation, enclosing=None, packed=None):
print("set_ui_widget_currency")
colon_name = name + ":"
label = Gtk.Label(colon_name)
label.set_alignment(1.0, 0.5)
#enclosing = Gtk.HBox(homogeneous=False, spacing=5)
enclosing = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5)
enclosing.set_homogeneous(False)
value = GncCurrencyEdit()
self.widget = value
self.set_ui_value(False)
value.connect("changed",self.changed_widget_cb)
enclosing.pack_start(label, False, False, 0)
enclosing.pack_start(value, False, False, 0)
enclosing.show_all()
# need to figure what goes on with packed - is it pass through??
return (value, enclosing, None)
def set_ui_value_currency (self, use_default, widget, value):
print("set_ui_value_currency")
if isinstance(value,gnucash.GncCommodity):
widget.set_currency(value)
return False
else:
return True
def get_ui_value_currency (self, widget):
print("get_ui_value_currency")
newcommod = widget.get_currency()
return newcommod
def set_ui_widget_commodity (self, page_box, name, documentation, enclosing=None, packed=None):
print("set_ui_widget_commodity")
#pdb.set_trace()
colon_name = name + ":"
label = Gtk.Label(colon_name)
label.set_alignment(1.0, 0.5)
#enclosing = Gtk.HBox(homogeneous=False, spacing=5)
enclosing = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5)
enclosing.set_homogeneous(False)
# this is not very pythonic
# changing - make GncCommodityEdit subclass of GncGeneralSelect
#value = GncGeneralSelect(GNC_GENERAL_SELECT_TYPE_SELECT,
# gnc_commodity_edit_get_string,
# gnc_commodity_edit_new_select)
value = GncCommodityEdit()
#pdb.set_trace()
self.widget = value
self.set_ui_value(False)
if documentation:
value.entry.set_tooltip_text(documentation)
value.entry.connect("changed",self.changed_widget_cb)
enclosing.pack_start(label, False, False, 0)
enclosing.pack_start(value, False, False, 0)
enclosing.show_all()
# need to figure what goes on with packed - is it pass through??
return (value, enclosing, None)
def set_ui_value_commodity (self, use_default, widget, value):
print("set_ui_value_commodity")
#pdb.set_trace()
if isinstance(value,gnucash.GncCommodity):
widget.set_selected(value)
return False
else:
return True
def get_ui_value_commodity (self, widget):
print("get_ui_value_commodity")
#pdb.set_trace()
newcommod = widget.get_selected()
return newcommod
def set_ui_widget_multichoice (self, page_box, name, documentation, enclosing=None, packed=None):
colon_name = name + ":"
label = Gtk.Label(colon_name)
label.set_alignment(1.0, 0.5)
#enclosing = Gtk.HBox(homogeneous=False, spacing=5)
enclosing = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5)
enclosing.set_homogeneous(False)
value = self.create_multichoice_widget()
self.widget = value
self.set_ui_value(False)
enclosing.pack_start(label, False, False, 0)
enclosing.pack_start(value, False, False, 0)
enclosing.show_all()
# need to figure what goes on with packed - is it pass through??
return (value, enclosing, None)
def set_ui_value_multichoice (self, use_default, widget, value):
indx_value = self.guile_option.lookup_key(value)
if indx_value >= 0 and indx_value < len(self.guile_option.option_data):
widget.set_active(indx_value)
return False
else:
return True
def get_ui_value_multichoice (self, widget):
# big question is whether to base from 0 or 1 - now going with 0
# raw indexes are base 0
newmulti = widget.get_active()
# lots of options use the function (in option-util.c)
# gnc_option_permissible_value that checks in value in range
if newmulti >= 0 and newmulti < len(self.guile_option.option_data):
newval = self.guile_option.option_data[newmulti][0]
else:
newval = None
#pdb.set_trace()
return newval
def set_ui_widget_date (self, page_box, name, documentation, enclosing=None, packed=None):
print("set_ui_widget_date")
colon_name = name + ":"
label = Gtk.Label(colon_name)
label.set_alignment(1.0, 0.5)
#enclosing = Gtk.HBox(homogeneous=False, spacing=0)
enclosing = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5)
enclosing.set_homogeneous(False)
value = self.create_date_widget()
self.widget = value
enclosing.pack_start(label, False, False, 0)
enclosing.pack_start(value, False, False, 0)
eventbox = Gtk.EventBox()
eventbox.add(enclosing)
page_box.pack_start(eventbox, False, False, 0)
packed = True
eventbox.set_tooltip_text(self.guile_option.documentation_string)
self.set_ui_value(False)
enclosing.show_all()
# need to figure what goes on with packed - is it pass through??
return (value, enclosing, packed)
def set_ui_value_date (self, use_default, widget, value):
print("set_ui_value_date")
#pdb.set_trace()
bad_value = False
if use_default:
date_option_type = self.guile_option.default_value[0]
else:
date_option_type = self.guile_option.option_data[0]
vltupl = self.guile_option.getter()
if vltupl[0] == 'relative':
relative = vltupl[1]
indx = self.guile_option.lookup_key(relative)
if date_option_type == 'relative':
widget.set_active(indx)
elif date_option_type == 'both':
widget_list = widget.get_children()
rel_date_widget = widget_list[GncDateEdit.GNC_RD_WID_REL_WIDGET_POS]
self.set_select_method(False,True)
rel_date_widget.set_active(indx)
elif vltupl[0] == 'absolute':
dttm = vltupl[1]
if date_option_type == 'absolute':
widget.set_time_dt(dttm)
elif date_option_type == 'both':
widget_list = widget.get_children()
ab_date_widget = widget_list[GncDateEdit.GNC_RD_WID_AB_WIDGET_POS]
self.set_select_method(True,True)
ab_date_widget.set_time_dt(dttm)
else:
bad_value = True
else:
bad_value = True
return bad_value
def get_ui_value_date (self, widget):
print("get_ui_value_date")
#pdb.set_trace()
subtype = self.guile_option.option_data[0]
widget_list = widget.get_children()
if subtype == 'relative':
#pdb.set_trace()
#rel_date_widget = widget_list[GncDateEdit.GNC_RD_WID_REL_WIDGET_POS]
rel_date_widget = widget
relval = rel_date_widget.get_active()
relval = self.guile_option.lookup_index(relval)
retval = ('relative', relval)
elif subtype == 'absolute':
#pdb.set_trace()
#ab_date_widget = widget_list[GncDateEdit.GNC_RD_WID_AB_WIDGET_POS]
ab_date_widget = widget
#absval = ab_date_widget.get_property('time')
absval = ab_date_widget.get_date()
retval = ('absolute', absval)
elif subtype == 'both':
#pdb.set_trace()
ab_button = widget_list[GncDateEdit.GNC_RD_WID_AB_BUTTON_POS]
ab_date_widget = widget_list[GncDateEdit.GNC_RD_WID_AB_WIDGET_POS]
rel_button = widget_list[GncDateEdit.GNC_RD_WID_REL_BUTTON_POS]
rel_date_widget = widget_list[GncDateEdit.GNC_RD_WID_REL_WIDGET_POS]
if ab_button.get_active():
#absval = ab_date_widget.get_property('time')
absval = ab_date_widget.get_date()
retval = ('absolute', absval)
elif rel_button.get_active():
relval = rel_date_widget.get_active()
relval = self.guile_option.lookup_index(relval)
retval = ('relative', relval)
return retval
def set_ui_widget_account_list (self, page_box, name, documentation, enclosing=None, packed=None):
print("set_ui_widget_account_list")
#pdb.set_trace()
#print("collect in set_ui_widget_account_list 1")
#gc.collect()
enclosing = self.create_account_widget(name)
value = self.widget
#print("collect in set_ui_widget_account_list 2")
#gc.collect()
enclosing.set_tooltip_text(self.guile_option.documentation_string)
page_box.pack_start(enclosing, True, True, 5)
packed = True
self.set_ui_value(False)
selection = value.get_selection()
selection.connect("changed", self.account_cb)
#print("collect in set_ui_widget_account_list 3")
#gc.collect()
enclosing.show_all()
#print("collect in set_ui_widget_account_list 4")
#gc.collect()
# need to figure what goes on with packed - is it pass through??
return (value, enclosing, packed)
def set_ui_value_account_list (self, use_default, widget, value):
print("set_ui_value_account_list")
#pdb.set_trace()
gnc_tree_view_account.do_set_selected_accounts(widget,value,True)
return False
def get_ui_value_account_list (self, widget):
print("get_ui_value_account_list")
#pdb.set_trace()
acc_lst = gnc_tree_view_account.do_get_selected_accounts(widget)
return acc_lst
def set_ui_widget_account_sel (self, page_box, name, documentation, enclosing=None, packed=None):
print("set_ui_widget_account_sel")
pdb.set_trace()
def set_ui_value_account_sel (self, use_default, widget, value):
print("set_ui_value_account_sel")
pdb.set_trace()
def get_ui_value_account_sel (self, widget):
print("get_ui_value_account_sel")
pdb.set_trace()
def set_ui_widget_list (self, page_box, name, documentation, enclosing=None, packed=None):
print("set_ui_widget_list")
#gc.collect()
colon_name = name + ":"
label = Gtk.Label(colon_name)
label.set_alignment(1.0, 0.5)
enclosing = self.create_list_widget(name)
value = self.widget
eventbox = Gtk.EventBox()
eventbox.add(enclosing)
page_box.pack_start(eventbox, False, False, 5)
packed = True
eventbox.set_tooltip_text(self.guile_option.documentation_string)
self.set_ui_value(False)
enclosing.show_all()
#print("collect in set_ui_widget_value_list")
#gc.collect()
# need to figure what goes on with packed - is it pass through??
return (value, enclosing, packed)
def set_ui_value_list (self, use_default, widget, value):
print("set_ui_value_list")
#pdb.set_trace()
selection = widget.get_selection()
selection.unselect_all()
# so where did I get this from??
# cant see it in the c code at all
# I dont know how this worked - I seem to be getting
# values as keys but the tree view requires indexes
# maybe I never updated this from a long time ago??
# - because the C code needs the gnc_option_permissible_value_index call
# to convert from the key to index
#if use_default:
# for itm in self.guile_option.default_value:
# rw = self.guile_option.lookup_key(itm)
# if rw >= 0 and rw < len(self.guile_option.option_data):
# selection.select_path((rw,))
# else:
# return True
#else:
if True:
for itm in value:
#rw = self.guile_option.permissible_value_index(itm)
rw = self.guile_option.lookup_key(itm)
if rw >= 0 and rw < len(self.guile_option.option_data):
path = Gtk.TreePath(rw)
selection.select_path((path,))
else:
return True
return False
def get_ui_value_list (self, widget):
print("get_ui_value_list")
#pdb.set_trace()
# big question is whether to base from 0 or 1 - now going with 0
# raw indexes are base 0
selection = widget.get_selection()
# this has been changed in Gtk3
#newslc = selection.get_selected_rows()
# not sure about this for introspection
#newlst = newslc[1][0].get_indices_with_depth()
# this is how its done in Gtk3/gnucash 3
#num_values = self.guile_option.num_permissible_values()
num_values = len(self.guile_option.option_data)
newlst = []
for row,opt in enumerate(self.guile_option.option_data):
path = Gtk.TreePath(row)
selected = selection.path_is_selected(path)
if selected:
newlst.append(opt[0])
# what am I supposed to be returning for this??
# a list of objects seems to work - it does set
# the option value to a list of the option keys
#pdb.set_trace()
return newlst
def set_ui_widget_number_range (self, page_box, name, documentation, enclosing=None, packed=None):
print("set_ui_widget_number_range")
#pdb.set_trace()
colon_name = name + ":"
label = Gtk.Label(colon_name)
label.set_alignment(1.0, 0.5)
#enclosing = Gtk.HBox(homogeneous=False, spacing=5)
enclosing = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5)
enclosing.set_homogeneous(False)
(lower_bound, upper_bound, num_decimals, step_size) = self.get_range_info()
# note in python the 1st argument is the adjustment value - we can set it later
# so just use a default here
# NOTA BENE - skipping this 1st argument leads to strange non-errors
adj = Gtk.Adjustment(0.0, lower_bound, upper_bound, step_size, step_size*5,0)
value = Gtk.SpinButton.new(adj,step_size, int(num_decimals))
value.set_numeric(True)
biggest = abs(lower_bound)
biggest = max(lower_bound,abs(upper_bound))
num_digits = 0
while biggest >= 1:
num_digits += 1
biggest = biggest/10
if num_digits == 0:
num_digits = 1
num_digits += int(num_decimals)
value.set_width_chars(num_digits)
self.widget = value
self.set_ui_value(False)
value.connect("changed",self.changed_widget_cb)
enclosing.pack_start(label, False, False, 0)
enclosing.pack_start(value, False, False, 0)
enclosing.show_all()
# need to figure what goes on with packed - is it pass through??
return (value, enclosing, None)
def set_ui_value_number_range (self, use_default, widget, value):
print("set_ui_value_number_range")
#pdb.set_trace()
if isinstance(value, numbers.Number):
widget.set_value(value)
return False
else:
return True
def get_ui_value_number_range (self, widget):
print("get_ui_value_number_range")
newnum = widget.get_value()
#pdb.set_trace()
# need to check utf-8'ness here
return newnum
def set_ui_widget_color (self, page_box, name, documentation, enclosing=None, packed=None):
print("set_ui_widget_color")
colon_name = name + ":"
label = Gtk.Label(colon_name)
label.set_alignment(1.0, 0.5)
#enclosing = Gtk.HBox(homogeneous=False, spacing=5)
enclosing = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5)
enclosing.set_homogeneous(False)
use_alpha = self.guile_option.option_data[1]
value = Gtk.ColorButton()
value.set_title(name)
value.set_use_alpha(use_alpha)
self.widget = value
self.set_ui_value(False)
# gnc_option_color_changed_cb just calls gnc_option_changed_widget_cb
value.connect("color-set",self.changed_widget_cb)
enclosing.pack_start(label, False, False, 0)
enclosing.pack_start(value, False, False, 0)
enclosing.show_all()
# need to figure what goes on with packed - is it pass through??
return (value, enclosing, None)
def set_ui_value_color (self, use_default, widget, value):
print("set_ui_value_color")
#DEBUG("red %f, green %f, blue %f, alpha %f", red, green, blue, alpha)
# yes in the C the value argument is totally ignored and get_color_info
# actually gets the value from the option
clr = self.get_color_info(use_default)
if clr:
gclr = Gdk.Color(red=clr[0],green=clr[1],blue=clr[2])
widget.set_color(gclr)
widget.set_alpha(int(clr[3]*0x0ffff))
return False
return True
def get_ui_value_color (self, widget):
print("get_ui_value_color")
newclr = widget.get_color()
newalp = widget.get_alpha()
scl = self.guile_option.option_data[0]
newval = [newclr[0],newclr[1],newclr[2],newalp]
return newclr
def set_ui_widget_font (self, page_box, name, documentation, enclosing=None, packed=None):
print("set_ui_widget_font")
def set_ui_value_font (self, use_default, widget, value):
print("set_ui_value_font")
def get_ui_value_font (self, widget):
print("get_ui_value_font")
def set_ui_widget_pixmap (self, page_box, name, documentation, enclosing=None, packed=None):
print("set_ui_widget_pixmap")
def set_ui_value_pixmap (self, use_default, widget, value):
print("set_ui_value_pixmap")
def get_ui_value_pixmap (self, widget):
print("get_ui_value_pixmap")
def set_ui_widget_radiobutton (self, page_box, name, documentation, enclosing=None, packed=None):
print("set_ui_widget_radiobutton")
def set_ui_value_radiobutton (self, use_default, widget, value):
print("set_ui_value_radiobutton")
def get_ui_value_radiobutton (self, widget):
print("get_ui_value_radiobutton")
def set_ui_widget_dateformat (self, page_box, name, documentation, enclosing=None, packed=None):
print("set_ui_widget_dateformat")
def set_ui_value_dateformat (self, use_default, widget, value):
print("set_ui_value_dateformat")
def get_ui_value_dateformat (self, widget):
print("get_ui_value_dateformat")
def set_ui_widget_budget (self, page_box, name, documentation, enclosing=None, packed=None):
print("set_ui_widget_budget")
def set_ui_value_budget (self, use_default, widget, value):
print("set_ui_value_budget")
def get_ui_value_budget (self, widget):
print("get_ui_value_budget")
def create_date_widget (self):
#pdb.set_trace()
date_type = self.guile_option.option_data[0]
show_time = self.guile_option.option_data[1]
use24 = sw_core_utils.gnc_prefs_get_bool('general', 'clock-24h')
if date_type != 'relative':
ab_widget = GncDateEdit.new(time.time(), show_time, use24)
ab_widget.date_entry.connect("changed", self.changed_option_cb)
if show_time:
ab_widget.time_entry.connect("changed", self.changed_option_cb)
if date_type != 'absolute':
#num_values = self.guile_option.num_permissible_values()
num_values = len(self.guile_option.option_data[2])
store = Gtk.ListStore(GObject.TYPE_STRING,GObject.TYPE_STRING)
def_val = self.guile_option.default_value
for indx,itm in enumerate(self.guile_option.option_data[2]):
itemlst = self.guile_option.lookup_string(itm)
itemstr = itemlst[0]
itemdes = itemlst[1]
store.append((itemstr,itemdes))
rel_widget = self.gnc_combott(store)
# not seeing where this is done in scheme/C
# note this is making the default value the index
#rel_widget.set_active(self.guile_option.default_value)
#rel_widget.set_model(store)
rel_widget.connect("changed",self.multichoice_cb)
if date_type == 'absolute':
self.widget = ab_widget
return ab_widget
elif date_type == 'relative':
self.widget = rel_widget
return rel_widget
elif date_type == 'both':
#box = Gtk.HBox(homogeneous=False, spacing=5)
box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5)
box.set_homogeneous(False)
ab_button = Gtk.RadioButton(group=None)
ab_button.connect("toggled", self.rd_option_ab_set_cb)
rel_button = Gtk.RadioButton(group=ab_button)
rel_button.connect("toggled", self.rd_option_rel_set_cb)
box.pack_start(ab_button, False,False,0)
box.pack_start(ab_widget, False,False,0)
box.pack_start(rel_button, False,False,0)
box.pack_start(rel_widget, False,False,0)
self.widget = box
return box
else:
return None
def changed_option_cb (self, widget):
self.changed_widget_cb(widget)
def rd_option_ab_set_cb (self, widget):
self.set_select_method(True,False)
self.changed_option_cb(widget)
def rd_option_rel_set_cb (self, widget):
self.set_select_method(False,False)
self.changed_option_cb(widget)
def set_select_method (self, use_absolute, set_buttons):
print("set_select_method")
widget_list = self.widget.get_children()
ab_button = widget_list[GncDateEdit.GNC_RD_WID_AB_BUTTON_POS]
ab_widget = widget_list[GncDateEdit.GNC_RD_WID_AB_WIDGET_POS]
rel_button = widget_list[GncDateEdit.GNC_RD_WID_REL_BUTTON_POS]
rel_widget = widget_list[GncDateEdit.GNC_RD_WID_REL_WIDGET_POS]
if use_absolute:
ab_widget.set_sensitive(True)
rel_widget.set_sensitive(False)
if set_buttons:
ab_button.set_active(True)
else:
ab_widget.set_sensitive(False)
rel_widget.set_sensitive(True)
if set_buttons:
rel_button.set_active(True)
def create_account_widget (self, name):
#pdb.set_trace()
#print("collect in create_account_widget 1")
#gc.collect()
# is multiple account selection allowed
multiple_selection = self.guile_option.option_data[0]