Lisp HUG Maillist Archive

(Lisp-HUG) Push Button Background Color...

Hello to the List from the snowy Rocky Mountains...

I am cleaning-up/sparkling-up some production code and am trying to 
get push buttons to change their background colors...     ...and 
realize, after some experimenting, that I don't know how to do that.

Specifying :foreground/:background in the (make-instance 
'capi:push-button... ) call sets the foreground/background allright, 
but those appear to be the colors of the outlining borders - and not 
the color of the actual plane background of the button.

I am trying to convince a push button to flash a different color 
(i.e., the actual background of the button - not just the border) when pressed.

All that I am able to get is the usual blah-grey color of CAPI buttons.

Any pointers on how to do that???  I appreciate it.

Regards,

Jack Harper
Secure Outcomes Inc.
Evergreen, Colorado USA


Re: (Lisp-HUG) Push Button Background Color...

Jack Harper wrote:
> 
> I am trying to convince a push button to flash a different color (i.e., 
> the actual background of the button - not just the border) when pressed.
> 

The following works for me (5.1/Motif; the documentation states that 
:press-callback is not supported on Cocoa):

(defun foo (&key (default :grey80)
                  (clicked :red)
                  (cb (constantly nil)))
   (let ((colors (list default clicked)))
     (flet ((change-color (b)
              (rotatef (first colors)
                       (second colors))
              (setf (capi:simple-pane-background b)
                    (first colors))))
       (make-instance 'capi:push-button
                      :text "Click Me"
                      :callback-type :item
                      :press-callback #'change-color
                      :selection-callback
                      (lambda (b)
                        (change-color b)
                        (funcall cb b))))))

Mike


Re: (Lisp-HUG) Push Button Background Color...

Unable to parse email body. Email id is 9648

Re: (Lisp-HUG) Push Button Background Color...

At 02:53 PM 1/6/2010, you wrote:

> > I am trying to convince a push button to flash a different color
> > (i.e., the actual background of the button - not just the border) 
> when pressed.
>
>On what platform?
>
>pt


Windows XP.

Regards,

Jack Harper
Secure Outcomes Inc
Evergreen, Colorado USA



Re: (Lisp-HUG) Push Button Background Color...

At 02:16 PM 1/6/2010, Mike Watters wrote:
Jack Harper wrote:
I am trying to convince a push button to flash a different color (i.e., the actual background of the button - not just the border) when pressed.

The following works for me (5.1/Motif; the documentation states that :press-callback is not supported on Cocoa):

(defun foo (&key (default :grey80)
                 (clicked :red)
                 (cb (constantly nil)))
  (let ((colors (list default clicked)))
    (flet ((change-color (b)
             (rotatef (first colors)
                      (second colors))
             (setf (capi:simple-pane-background b)
                   (first colors))))
      (make-instance 'capi:push-button
                     :text "Click Me"
                     :callback-type :item
                     :press-callback #'change-color
                     :selection-callback
                     (lambda (b)
                       (change-color b)
                       (funcall cb b))))))

Mike


Yes, I see what you are doing with the (setf (capi:simple-pane-background ....))

However, on my Windows XP system, I still just get a blah-grey background with, now, a colored border...

I think the issue distills down to why do I not see a :red pane color that surrounds the "Click Me" (also not :green) text in the following:   (hopefully, the list server will allow the small embedded image to come across):

Emacs!

e.g., is there some rational way to have :green text and a :red background pane inside a CAPI button?


Regards to the List -

Jack Harper
Secure Outcomes Inc.
Evergreen, Colorado USA (...snowing like mad here at 8,000-feet/2400-meters elevation with +5F/-15C   :)

Re: (Lisp-HUG) Push Button Background Color...

At 04:24 PM 1/6/2010, Evan Patton wrote:
>Unfortunately, this is a limitation of the old Windows GDI. The 
>standard UI button cannot have its color be overridden unless you 
>draw the button manually as part of the WNDPROC callback (in C). If 
>LispWorks has a way of hooking into this function, then it would be 
>possible to change the color. However, GDI+ does support this 
>functionality, so if you really need it you could call out to 
>Windows to implement it.

<snip>



>>Yes, I see what you are doing with the (setf 
>>(capi:simple-pane-background ...))
>>
>>However, on my Windows XP system, I still just get a blah-grey 
>>background with, now, a colored border...

<snip>

Thank You Evan for that piece of information --

I appreciate it.

Amazing to me that MicroSoft would leave out such a fundamental thing.

I have been wandering aimlessly through documentation and code 
snippets trying to figure out just what silly thing I have been doing wrong.

I suppose that an option would be to implement my own 
Colorable-Push-Button class that actually does what I need and try to 
integrate that into CAPI - but, Good Heavens, what a 
pain...   ...would probably take a few days of fumbling about 
deciphering CAPI classes/slots etc to get such a thing correct.


Regards,

Jack Harper
Secure Outcomes Inc.
Evergreen, Colorado USA




Re: (Lisp-HUG) Push Button Background Color...

At 03:08 AM 1/7/2010, you wrote:
>Jack Harper wrote on Wed, 06 Jan 2010 16:37:34 -0700 02:37:
>
>| Amazing to me that MicroSoft would leave out such a fundamental thing.

....and then Dmitriy said:

>This thing is not such a fundamental IMHO. Button color different from
>standard/theme-imposed is a kind poor style and violates general GUI design
>principles.
>
>Though, with the advert of lots of ugly designed websites that seems to
>become more and more tolerable :-(
>--
>Sincerely,
>Dmitriy Ivanov
>lisp.ystok.ru


Sorry for the delay in responding to people that commented on my 
question "Push Button Background Color".

I had abdominal surgery this past Friday which really knocked me down 
a bit.  The Good News is that the Docs used a laproscopic technique 
that minimized the chopping and hacking.  But, I still feel like I 
was shot in the gut :(         Hooray for the narcotic/pain-killer 
"Vicodin" :)))

Dmitriy - You are clearly correct in your statement. However, I use 
Lisp to build embedded soft-realtime systems where I don't want the 
system to look like MicroSoft Windows at all - more like an iPhone in 
this case. My application is controlled with a built-in touchscreen 
and so I need active things other than Windows-styled buttons (I use 
"Windows XP Embedded" booting out of flash memory rather than 
straight "Windows XP").

Please see http://www.secureoutcomes.net/livescan-products.html for 
the embedded system - written completely in LW Common Lisp (along 
with CLOS, CAPI & Friends).

"Laughing Water" suggested (Thank You!) that I use :image buttons to 
do what I need to do - which is when a text "button" is pressed on 
the touchscreen, that the button-thing flash a different color (Blue) 
for, say, 100-milliseconds so the user knows that the button really activated.

I have tried that and it works well with one exception - I do not see 
the "flash" :image button unless I inject a (capi:display-message 
"XXX") while the flash button is active. I can replace the 
(capi:display-message) with a (sleep 5) and I *still* do not see the 
flash image button (the Sleep should allow the various processes 
associated with the other buttons etc to run - just as does the 
(capi:display-message) - but "something" is *very* different between the two).

I have defined two buttons - one is :text that normally shows. The 
:callback for the :text button (capi:hide-pane )'s itself and then 
(capi:show-pane)'s the "flash" button through its process which is 
the same size and has the exact same (X, Y) coordinates on the 
layout/interface. It then waits 100-milliseconds and then reverses 
the sequence to bring the :text button back up and to hide the 
"Flash" button...

I have taken the relevant code out of the production code and 
produced the following simple snippet:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

(defun test-button()

   (let* ((solid-blue-button (make-instance 
'capi:push-button                                       ; Solid-Blue 
:Image Button for the "flash". It lives "under" the :text button.

                                            :x 50 :y 50

                                            :text nil
                                            :image "d:/ls1100 
runtime/bilder/solid-blue-image.bmp"  ; This is a 50x60 pixel blue .bmp file

                                            :external-min-width 50
                                            :external-max-width 50
                                            :external-min-height 60
                                            :external-max-height 60))


          (button (make-instance 
'capi:push-button 
; Text Button "Q" - It usually lives on top of the Hidden :image button...

                                 :x 50 :y 
50 
; Coordinates are the same as for the Flash button above...

                                 :text "Q"
                                 :image nil

                                 :external-min-width 50
                                 :external-max-width 50
                                 :external-min-height 60
                                 :external-max-height 60

                                 :font (gp:make-font-description 
:family "Eurostyle Regular/Black"
                                                                 :size 36
                                                                 :weight 
:medium
                                                                 :slant :roman)

                                 :callback-type :item

                                 :selection-callback 
; On Button Press...
                                   #'(lambda( self )

                                       (capi:hide-pane 
self)                                                       ; Text 
Button Hides Itself...

                                       (capi:apply-in-pane-process 
solid-blue-button                   ; ...then Shows the Flash button...
                                                                   'capi:show-pane 
solid-blue-button)

                                       (capi:display-message 
"Barf");;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;COMMENT 
OUT TO FAIL.......  WILL SEE NO BLUE FLASH...

                                       (sleep 
0.100) 
; Hangs around for awhile...

                                       (capi:apply-in-pane-process 
solid-blue-button                   ; Hides the Blue Flash Button...
                                                                   'capi:hide-pane 
solid-blue-button)

                                       (capi:show-pane 
self))))                                                  ; Re-Shows 
the Text Button... ...and all is as it was...


          (layout (make-instance 'capi:pinboard-layout

                                 :width 100
                                 :height 100

                                 :description
                                   (list button
                                         solid-blue-button)))

          (interface (make-instance 'capi:interface

                                    :best-width 100
                                    :best-height 100

                                    :layout layout)))




     (capi:display 
interface))) 
; Activate the button...
-----------------------------------------------------------------------------------------------------------------------------

The interesting thing - and hangup - is that if you run the above 
code (you will need that 50x60 pixel blue .bmp file), you will see 
the blue "flash" when you press the button. But, if you comment out 
the (capi:display-message) and rely solely on the (sleep 0.100), you 
do NOT see the blue "flash".

Thoughts???

What am I doing wrong in my narcotic-induced haze??

I appreciate any feedback.

Regards to the List,

Jack Harper
Secure Outcomes Inc
http://www.secureoutcomes.net

ps - If you know someone looking for a Lisp development position, 
please ask them to look at 
http://www.secureoutcomes.net/employment.html - direct hire or contract...



Re: (Lisp-HUG) Push Button Background Color...

At 03:51 PM 1/11/2010, Evan Patton wrote:
>This is due to the fact that you're updating the GUI on the same 
>thread as the rest of your code. When you sleep for 0.100, you are 
>preventing that thread from redrawing the screen by forcing it to 
>wait that 100 ms. What you could do instead is call 
>mp:process-run-function with a lambda closure that performs the 
>sleep and then performs a capi:apply-in-pane-process to change the 
>image a second time. This may give you better results.<snip>


....works perfectly with your suggestion Evan.

Thank You.

It is clear to me that the worst part of the CAPI learning curve is 
dealing with the multi-threading.

Regards to the List.

Jack Harper
Secure Outcomes Inc
http://www.secureoutcomes.net



Re[2]: (Lisp-HUG) Push Button Background Color...

Hello Jack,

> Please see http://www.secureoutcomes.net/livescan-products.html for
> the embedded system - written completely in LW Common Lisp (along
> with CLOS, CAPI & Friends).

Can you make a brief summary and post it here on why you use CL in
your products, why a (the :) commercial version of CL and how you came
to CL in your company? I'm asking this because it is hard to find
real-world up-to-date examples of use of CL for commercial applications;
and because as I see it there is a notion among some lispers that current
free implementations of CL are somewhat "better" than commercial ones.

Best,
 Art


Updated at: 2020-12-10 08:40 UTC