-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample 1.2.rkt
More file actions
101 lines (82 loc) · 3.86 KB
/
Example 1.2.rkt
File metadata and controls
101 lines (82 loc) · 3.86 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
#lang racket/gui
(define (toggle-list-box genre-checkbox list-box)
(if (send genre-checkbox get-value)
(send list-box enable #t) ;; Enable if and only genre checkbox is enabled
(send list-box enable #f))) ;; Else disabled
(define (combined-callback checkbox event)
(update-submit-button) ;; Calls submit counter function
(toggle-list-box genre-checkbox list-box)) ;; Enables/Disables list box
(define (reset-main)
(send name-checkbox set-value #f)
(send date-checkbox set-value #f)
(send publisher-checkbox set-value #f)
(send region-checkbox set-value #f)
(send genre-checkbox set-value #f))
(define secondary-controls (list list-box)) ;; To be expanded
(define (reset-secondary)
(send list-box set-selection '()))
(define main-frame (new frame%
[label "Select Options"]
[width 800]
[height 600]))
(define control-panel1
(new vertical-panel%
[parent main-frame]))
(define control-panel2
(new vertical-panel%
[parent main-frame]))
(define control-panel3
(new vertical-panel%
[parent main-frame]))
(define (checkbox-callback checkbox event)
(update-submit-button))
;; Button to create name option, enabled to interact by default
(define name-checkbox (new check-box%
[parent control-panel1]
[label "Name"]
[callback checkbox-callback]))
;; Button to create date option, enabled to interact by default
(define date-checkbox (new check-box%
[parent control-panel1]
[label "Date"]
[callback checkbox-callback]))
;; Button to create publisher option, enabled to interact by default
(define publisher-checkbox (new check-box%
[parent control-panel1]
[label "Publisher"]
[callback checkbox-callback]))
;; Button to create region option, enabled to interact by default
(define region-checkbox (new check-box%
[parent control-panel1]
[label "Region"]
[callback checkbox-callback]))
;; Button to create genre option, enabled to interact by default
(define genre-checkbox (new check-box%
[parent control-panel1]
[label "Genre"]
[callback combined-callback]))
(define list-box (new list-box%
[parent control-panel2]
[label "Genre Options:"]
[choices '("Action" "Adventure" "Fighting" "Platform" "Puzzle"
"Racing" "Role-Playing" "Shooter" "Simulation"
"Sports" "Strategy" "Misc")]
[enabled #f]
[style (list 'single)]))
(define submit-button (new button%
[parent control-panel3]
[label "Submit"]
[enabled #f]
[callback (λ (button event)
;; (submit-filters)
(reset-main)
(reset-secondary))]))
(send main-frame show #t)
;; Corrected logic to enable/disable the submit button
(define (update-submit-button)
(let* ([checkboxes (list name-checkbox date-checkbox publisher-checkbox region-checkbox genre-checkbox)]
[checked-count (count (lambda (checkbox) (send checkbox get-value)) checkboxes)])
;; Use the 'enable' method with an argument to enable/disable based on condition
(if (= checked-count 3)
(send submit-button enable #t) ; Enable the button if exactly 3 checkboxes are selected
(send submit-button enable #f)))) ; Otherwise, disable it