fixed bug causing multiple GUI to show up. Now prompts for hostname and

color
This commit is contained in:
Ibrahim Mkusa 2017-04-23 17:15:44 -04:00
parent 3e84c3a5ef
commit 58cff4f1b8
2 changed files with 36 additions and 26 deletions

View File

@ -243,7 +243,9 @@
;; prompt user for username
;; could randomly assign a user
;; 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 (prompt-username)
(define returned (get-text-from-user "Username set-up" "Please enter a username"
main-frame "user" (list 'disallow-invalid)
#:validate
@ -255,6 +257,20 @@
(send input set-label 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
;; TODO get username function maybe
(define (dispatch command)
@ -264,7 +280,8 @@
((eq? command 'get-color) get-my-color)
((eq? command 'set-color) set-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 'set-name) (lambda (newname) (if (string? newname)
(set! name newname)
@ -332,6 +349,6 @@
(substring given-string 7))
;(define thing1 (make-gui))
;(define thing2 (make-gui))
(define hermes-gui (make-gui))
((hermes-gui 'show))
; (define hermes-gui (make-gui))
; ((hermes-gui 'show))

View File

@ -19,7 +19,8 @@
;(sleep 0.25)
(define host3 "localhost")
; (define host3 "localhost")
(define hostname ((hermes-gui 'prompt-hostname)))
(define port-num 4321)
(define sleep-t 0.1)
@ -42,21 +43,13 @@
(define (client port-no)
(parameterize ([current-custodian main-client-cust])
;; 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
; store username to a file for later retrieval along with relevent
; info used for authentication with server
; TODO
; 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)))
;; TODO could store theses info in a file for retrieval later
(define username ((hermes-gui 'prompt-username)))
((hermes-gui 'prompt-color))
;send the username to the server (username in out)
(displayln username out)