fixed bug causing multiple GUI to show up. Now prompts for hostname and
color
This commit is contained in:
parent
3e84c3a5ef
commit
58cff4f1b8
@ -243,18 +243,34 @@
|
|||||||
;; prompt user for username
|
;; prompt user for username
|
||||||
;; could randomly assign a user
|
;; could randomly assign a user
|
||||||
;; after calling get-text set it as new label of text-field
|
;; after calling get-text set it as new label of text-field
|
||||||
(define (get-username)
|
; TODO there is a pattern here could wrap all this into resusable prompt funciton
|
||||||
(define returned (get-text-from-user "Username set-up" "Please enter a username"
|
;
|
||||||
main-frame "user" (list 'disallow-invalid)
|
(define (prompt-username)
|
||||||
#:validate
|
(define returned (get-text-from-user "Username set-up" "Please enter a username"
|
||||||
(lambda (input)
|
main-frame "user" (list 'disallow-invalid)
|
||||||
(if (and (string? input) (<= (string-length input) 10)
|
#:validate
|
||||||
(>= (string-length input) 2))
|
(lambda (input)
|
||||||
#t
|
(if (and (string? input) (<= (string-length input) 10)
|
||||||
#f))))
|
(>= (string-length input) 2))
|
||||||
|
#t
|
||||||
|
#f))))
|
||||||
(send input set-label returned)
|
(send input set-label returned)
|
||||||
returned)
|
returned)
|
||||||
|
|
||||||
|
(define (prompt-hostname)
|
||||||
|
(define returned (get-text-from-user "Hostname set-up" "Please enter a hostname"
|
||||||
|
main-frame "localhost" (list 'disallow-invalid)
|
||||||
|
#:validate
|
||||||
|
(lambda (input)
|
||||||
|
(if (and (string? input) (<= (string-length input) 50)
|
||||||
|
(>= (string-length input) 2))
|
||||||
|
#t
|
||||||
|
#f))))
|
||||||
|
; (send input set-label returned)
|
||||||
|
returned)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;;dispatch goes below that
|
;;dispatch goes below that
|
||||||
;; TODO get username function maybe
|
;; TODO get username function maybe
|
||||||
(define (dispatch command)
|
(define (dispatch command)
|
||||||
@ -264,7 +280,8 @@
|
|||||||
((eq? command 'get-color) get-my-color)
|
((eq? command 'get-color) get-my-color)
|
||||||
((eq? command 'set-color) set-color)
|
((eq? command 'set-color) set-color)
|
||||||
((eq? command 'prompt-color) prompt-color)
|
((eq? command 'prompt-color) prompt-color)
|
||||||
((eq? command 'get-username) get-username)
|
((eq? command 'prompt-username) prompt-username)
|
||||||
|
((eq? command 'prompt-hostname) prompt-hostname)
|
||||||
((eq? command 'send) send-message) ;; call to show a message in a gui
|
((eq? command 'send) send-message) ;; call to show a message in a gui
|
||||||
((eq? command 'set-name) (lambda (newname) (if (string? newname)
|
((eq? command 'set-name) (lambda (newname) (if (string? newname)
|
||||||
(set! name newname)
|
(set! name newname)
|
||||||
@ -332,6 +349,6 @@
|
|||||||
(substring given-string 7))
|
(substring given-string 7))
|
||||||
;(define thing1 (make-gui))
|
;(define thing1 (make-gui))
|
||||||
;(define thing2 (make-gui))
|
;(define thing2 (make-gui))
|
||||||
(define hermes-gui (make-gui))
|
; (define hermes-gui (make-gui))
|
||||||
((hermes-gui 'show))
|
; ((hermes-gui 'show))
|
||||||
|
|
||||||
|
@ -19,7 +19,8 @@
|
|||||||
;(sleep 0.25)
|
;(sleep 0.25)
|
||||||
|
|
||||||
|
|
||||||
(define host3 "localhost")
|
; (define host3 "localhost")
|
||||||
|
(define hostname ((hermes-gui 'prompt-hostname)))
|
||||||
(define port-num 4321)
|
(define port-num 4321)
|
||||||
(define sleep-t 0.1)
|
(define sleep-t 0.1)
|
||||||
|
|
||||||
@ -42,21 +43,13 @@
|
|||||||
(define (client port-no)
|
(define (client port-no)
|
||||||
(parameterize ([current-custodian main-client-cust])
|
(parameterize ([current-custodian main-client-cust])
|
||||||
;; connect to server at port 8080
|
;; connect to server at port 8080
|
||||||
(define-values (in out) (tcp-connect host3 port-no)) ;; define values
|
;; TODO catch error here
|
||||||
|
(define-values (in out) (tcp-connect hostname port-no)) ;; define values
|
||||||
;; binds to multiple values akin to unpacking tuples in python
|
;; binds to multiple values akin to unpacking tuples in python
|
||||||
|
|
||||||
; store username to a file for later retrieval along with relevent
|
;; TODO could store theses info in a file for retrieval later
|
||||||
; info used for authentication with server
|
(define username ((hermes-gui 'prompt-username)))
|
||||||
; TODO
|
((hermes-gui 'prompt-color))
|
||||||
; semaphore for gui object
|
|
||||||
; could display a bubble and prompt for username in GUI object
|
|
||||||
|
|
||||||
; create a gui object
|
|
||||||
; (define hermes-gui (make-gui))
|
|
||||||
; ((hermes-gui 'show))
|
|
||||||
;(displayln "What's your name?")
|
|
||||||
;(define username (read-line))
|
|
||||||
(define username ((hermes-gui 'get-username)))
|
|
||||||
|
|
||||||
;send the username to the server (username in out)
|
;send the username to the server (username in out)
|
||||||
(displayln username out)
|
(displayln username out)
|
||||||
|
Loading…
Reference in New Issue
Block a user