-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgnc_date_format.py
More file actions
234 lines (173 loc) · 8.16 KB
/
gnc_date_format.py
File metadata and controls
234 lines (173 loc) · 8.16 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
# special date widget
from gi.repository import GObject
from gi.repository import GLib
from gi.repository import Gtk
from datetime import datetime
import pdb
import date_ctypes
from gnc_builder import GncBuilder
# adding this class to maintain the date format
class DateFormat(object):
QOF_DATE_FORMAT_US = 0 # /**< United states: mm/dd/yyyy */
QOF_DATE_FORMAT_UK = 1 # /**< Britain: dd/mm/yyyy */
QOF_DATE_FORMAT_CE = 2 # /**< Continental Europe: dd.mm.yyyy */
QOF_DATE_FORMAT_ISO = 3 # /**< ISO: yyyy-mm-dd */
QOF_DATE_FORMAT_LOCALE = 4 # /**< Take from locale information */
QOF_DATE_FORMAT_UTC = 5 # /**< UTC: 2004-12-12T23:39:11Z */
QOF_DATE_FORMAT_CUSTOM = 6 # /**< Used by the check printing code */
QOF_UTC_DATE_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
QOF_DATE_FORMAT = { \
QOF_DATE_FORMAT_US : "%m/%d/%y",
QOF_DATE_FORMAT_UK : "%d/%m/%y",
QOF_DATE_FORMAT_CE : "%m.%d.%y",
QOF_DATE_FORMAT_ISO : "%Y-%m-%d",
QOF_DATE_FORMAT_LOCALE : "%Y-%m-%d",
QOF_DATE_FORMAT_UTC : "%Y-%m-%dT%H:%M:%SZ"
QOF_DATE_FORMAT_CUSTOM : "%Y-%m-%d",
}
def __init__ (self):
self.dateFormat = None
def get_string (self, df):
if df in DateFormat.QOF_DATE_FORMAT:
return DateFormat.QOF_DATE_FORMAT[df]
else:
return "%Y-%m-%d"
def print_date (self, dttm):
def get (self):
return self.dateFormat
def set (self, datefmt):
self.dateFormat = datefmt
class GncDateFormat(Gtk.Box):
# ah - this is something I think Ive missed - we can name the GType here
__gtype_name__ = 'GncDateFormat'
# OK Im now thinking gobject warning messages were happening previously but just did not get the message
cmnt = """
__gproperties__ = {
'report-id' : (int, # type
N_('The numeric ID of the report.'), # nick name
N_('The numeric ID of the report.'), # description
-1, # min value
GLib.MAXINT32, # max value
-1, # default value
GObject.ParamFlags.READWRITE), # flags
#GObject.ParamFlags.CONSTRUCT_ONLY | GObject.ParamFlags.READWRITE), # flags
}
"""
__gsignals__ = {
'format_changed' : (GObject.SignalFlags.RUN_FIRST, None, (int,))
}
def __init__ (self):
super(GncDateFormat,self).__init__(orientation=Gtk.Orientation.HORIZONTAL)
builder = GncBuilder()
builder.add_from_file("gnc-date-format.glade", "format-liststore")
builder.add_from_file("gnc-date-format.glade", "GNC Date Format")
#pdb.set_trace()
# junkily we need to list all signals here
# the gnucash code somehow figures all signals
# turns out only one callback is actually defined
self.builder_handlers = { \
'gnc_ui_date_format_changed_cb' : self.changed_cb
}
# another way to do this is to use self as the argument - which I assume means
# will look for the function in the current object
# unfortunately to use the blocking I need the handler_id which is not available
# when using this method
#builder.connect_signals(self)
builder.connect_signals(self.builder_handlers)
self.label = builder.get_object("widget_label")
self.format_combobox = builder.get_object("format_combobox")
self.months_label = builder.get_object("months_label")
self.month_number = builder.get_object("month_number_button")
self.month_abbrev = builder.get_object("month_abbrev_button")
self.month_name = builder.get_object("month_name_button")
self.years_label = builder.get_object("years_label")
self.years_button = builder.get_object("years_button")
self.custom_label = builder.get_object("format_label")
self.custom_entry = builder.get_object("format_entry")
self.sample_label = builder.get_object("sample_label")
self.custom_entry.handler_block_by_func(self.changed_cb)
self.set_format(date_ctypes.qof_date_format_get())
self.custom_entry.handler_unblock_by_func(self.changed_cb)
dialog = builder.get_object("GNC Date Format")
table = builder.get_object("date_format_table")
dialog.remove(table)
self.add(table)
dialog.destroy()
def enable_month (self, sensitive):
self.months_label.set_sensitive(sensitive)
self.month_number.set_sensitive(sensitive)
self.month_abbrev.set_sensitive(sensitive)
self.month_name.set_sensitive(sensitive)
def enable_year (self, sensitive):
self.years_label.set_sensitive(sensitive)
self.years_button.set_sensitive(sensitive)
def enable_format (self, sensitive):
self.custom_label.set_sensitive(sensitive)
self.custom_entry.set_sensitive(sensitive)
def refresh (self):
pdb.set_trace()
sel_option = self.format_combobox.get_active()
if sel_option == date_ctypes.QofDateFormat.QOF_DATE_FORMAT_CUSTOM:
format = self.custom_entry.get_text()
enable_year = False
enable_month = False
check_modifiers = False
enable_custom = True
elif sel_option == date_ctypes.QofDateFormat.QOF_DATE_FORMAT_LOCALE or \
sel_option == date_ctypes.QofDateFormat.QOF_DATE_FORMAT_UTC:
format = date_ctypes.qof_date_format_get_string(sel_option)
enable_year = False
enable_month = False
check_modifiers = False
enable_custom = False
elif sel_option == date_ctypes.QofDateFormat.QOF_DATE_FORMAT_ISO:
self.month_number.set_active(True)
enable_year = True
enable_month = False
check_modifiers = True
enable_custom = False
else:
enable_year = True
enable_month = True
check_modifiers = True
enable_custom = False
self.enable_year(enable_year)
self.enable_month(enable_month)
self.enable_format(enable_custom)
if check_modifiers:
if self.month_number.get_active():
format = date_ctypes.qof_date_format_get_string(sel_option)
else:
format = date_ctypes.qof_date_text_format_get_string(sel_option)
if self.month_name.get_active():
indx = format.find('b')
if indx >= 0:
format = format[0:indx]+'B'+format[indx+1:]
if self.years_button.get_active():
indx = format.find('y')
if indx >= 0:
format = format[0:indx]+'Y'+format[indx+1:]
#self.custom_entry.signal_handler_block()
self.custom_entry.handler_block_by_func(self.changed_cb)
self.custom_entry.set_text(format)
#self.custom_entry.signal_handler_unblock()
self.custom_entry.handler_unblock_by_func(self.changed_cb)
#secs_now = datetime.now()
#today = datetime.localtime(secs_now)
today = datetime.now()
date_string = date_ctypes.qof_strftime(format, today)
self.sample_label.set_text(date_string)
def set_format (self, format):
self.format_combobox.set_active(format)
self.compute_format()
def get_format (self):
return self.format_combobox.get_active()
def compute_format (self):
print("compute_format")
self.refresh()
#pdb.set_trace()
self.emit("format_changed",0)
def changed_cb (self, *args):
print("changed_cb", args)
#pdb.set_trace()
self.compute_format()