-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_datetime_fields.py
More file actions
116 lines (98 loc) · 3.77 KB
/
Copy pathtest_datetime_fields.py
File metadata and controls
116 lines (98 loc) · 3.77 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
#!/usr/bin/env python3
import os
import sys
import logging
import datetime
# Add parent directory to path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
try:
log_name = os.path.splitext(os.path.basename(__file__))[0] + '.log'
fh = logging.FileHandler(log_name, mode='w')
fh.setLevel(logging.DEBUG)
fh.setFormatter(logging.Formatter('%(asctime)s %(name)s %(levelname)s: %(message)s'))
root_logger = logging.getLogger()
root_logger.setLevel(logging.DEBUG)
existing = False
for h in list(root_logger.handlers):
try:
if isinstance(h, logging.FileHandler) and os.path.abspath(getattr(h, 'baseFilename', '')) == os.path.abspath(log_name):
existing = True
break
except Exception:
pass
if not existing:
root_logger.addHandler(fh)
print(f"Logging test output to: {os.path.abspath(log_name)}")
except Exception as _e:
print(f"Failed to configure file logger: {_e}")
def test_datefield(backend_name=None):
"""Interactive test for YDateField and YTimeField widgets."""
if backend_name:
print(f"Setting backend to: {backend_name}")
os.environ['MUI_BACKEND'] = backend_name
else:
print("Using auto-detection")
try:
from manatools.aui.yui import YUI, YUI_ui
import manatools.aui.yui_common as yui
# Force re-detection
YUI._instance = None
YUI._backend = None
backend = YUI.backend()
print(f"Using backend: {backend.value}")
ui = YUI_ui()
factory = ui.widgetFactory()
dialog = factory.createMainDialog()
vbox = factory.createVBox(dialog)
factory.createHeading(vbox, "Date/Time Field Test")
factory.createLabel(vbox, f"Backend: {backend.value}")
# Create datefield
hbox = factory.createHBox(vbox)
df = factory.createDateField(hbox, "Select Date:")
#df.setStretchable(yui.YUIDimension.YD_HORIZ, True)
now = datetime.datetime.now()
df.setValue(now.strftime("%Y-%m-%d"))
factory.createLabel(hbox, "right widget")
# Create timefield
try:
hbox = factory.createHBox(vbox)
tf = factory.createTimeField(hbox, "Select Time:")
#tf.setStretchable(yui.YUIDimension.YD_HORIZ, True)
tf.setValue(now.strftime("%H:%M:%S"))
factory.createLabel(hbox, "right widget")
except Exception as e:
tf = None
logging.getLogger(__name__).exception("Failed to create TimeField: %s", e)
# Buttons
h = factory.createHBox(vbox)
ok_btn = factory.createPushButton(h, "OK")
close_btn = factory.createPushButton(h, "Close")
print("\nOpening Date/TimeField test dialog...")
while True:
ev = dialog.waitForEvent()
et = ev.eventType()
if et == yui.YEventType.CancelEvent:
break
elif et == yui.YEventType.WidgetEvent:
wdg = ev.widget()
reason = ev.reason()
if wdg == close_btn and reason == yui.YEventReason.Activated:
break
if wdg == ok_btn and reason == yui.YEventReason.Activated:
print("OK clicked. Final date:", df.value())
if tf is not None:
print("Final time:", tf.value())
break
logging.info("Date: %s", df.value())
if tf is not None:
logging.info("Time: %s", tf.value())
dialog.destroy()
except Exception as e:
print(f"Error testing DateField with backend {backend_name}: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
if len(sys.argv) > 1:
test_datefield(sys.argv[1])
else:
test_datefield()