From 58cff4f1b8c1d5085121384221adcff4b5273fdf Mon Sep 17 00:00:00 2001 From: Ibrahim Mkusa Date: Sun, 23 Apr 2017 17:15:44 -0400 Subject: [PATCH] fixed bug causing multiple GUI to show up. Now prompts for hostname and color --- Hermes/GUI.rkt | 41 +++++++++++++++++++++++++++++------------ Hermes/client.rkt | 21 +++++++-------------- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/Hermes/GUI.rkt b/Hermes/GUI.rkt index 7780e28..7a0b868 100644 --- a/Hermes/GUI.rkt +++ b/Hermes/GUI.rkt @@ -243,18 +243,34 @@ ;; prompt user for username ;; could randomly assign a user ;; after calling get-text set it as new label of text-field - (define (get-username) - (define returned (get-text-from-user "Username set-up" "Please enter a username" - main-frame "user" (list 'disallow-invalid) - #:validate - (lambda (input) - (if (and (string? input) (<= (string-length input) 10) - (>= (string-length input) 2)) - #t - #f)))) + ; 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 + (lambda (input) + (if (and (string? input) (<= (string-length input) 10) + (>= (string-length input) 2)) + #t + #f)))) (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)) diff --git a/Hermes/client.rkt b/Hermes/client.rkt index ae1354c..a86dc0a 100644 --- a/Hermes/client.rkt +++ b/Hermes/client.rkt @@ -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)