Dynamic GUI possible?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Dynamic GUI possible?

J. P. L. Martín
Hi, I'm trying to display buttons only if a condition is true on the same window, making the condition is easy but I can get the conditional to run again when a change is done so it displays the row with the buttons, here is the code:

open
    | builder content |
    builder := UITheme builder.
    content := builder
        newColumn:
            {(builder
                newRow:
                    {(builder
                        newButtonFor: self
                        action: #listaPrestamos
                        label: 'Prestamos'
                        help: 'Listar Prestamos').
                    (builder
                        newButtonFor: self
                        action: #listaMateriales
                        label: 'Material'
                        help: 'Listar Material').
                    (builder
                        newButtonFor: self
                        action: #listaSocios
                        label: 'Socios'
                        help: 'Listar Socios').
                    (builder
                        newButtonFor: self
                        action: #listaEjemplares
                        label: 'Ejemplares'
                        help: 'Lista de Ejemplares')}).
            (builder
                newColumn:
                    {((PluggableMultiColumnListMorph
                        on: self
                        list: #listado
                        selected: #seleccionado
                        changeSelected: #seleccionado:
                        menu: nil
                        wrapSelector: #wrap:at:) extent: 600@600)})}.
            #listado = Prestamo database ifTrue: [builder
                newRow:
                    {(builder
                        newButtonFor: self
                        action: #addPrestamo
                        getEnabled: nil
                        label: 'Nuevo Prestamo'
                        help: 'Ingresar nuevo prestamo').
                    (builder
                        newButtonFor: self
                        action: #devPrestamo
                        getEnabled: #selecciono
                        label: 'Devolver'
                        help: 'Devolver').
                    (builder
                        newButtonFor: self
                        action: #addEjemplar
                        label: 'Agregar Ejemplar'
                        help: 'Ingresar nuevo ejemplar').
                    (builder
                        newButtonFor: self
                        action: #addMaterial
                        label: 'Agregar Material'
                        help: 'Ingresar nuevo material').
                    (builder
                        newButtonFor: self
                        action: #addSocio
                        label: 'Nuevo Socio'
                        help: 'Ingresar nuevo socio').
                    (builder
                        newButtonFor: self
                        action: #remover
                        getEnabled: #selecciono
                        label: 'Remover'
                        help: 'Ingresar nuevo prestamo').
                    (builder
                        newButtonFor: self
                        action: #guardar
                        label: 'guardar'
                        help: 'Ingresar nuevo socio')}] ifFalse: (Transcript show: 'Flase'; cr).
    (content openInWindowLabeled: 'Babel') extent: 600 @ 600.
    self changed: #listado;
    changed: #open.
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic GUI possible?

Ben Coman
I've never tried that, however using Tools > Finder > Selectors to
search for 'visible', I see Morph>>toggleVisible and friends.
Since #newButtonFor... eventually returns PluggableButtonMorph, perhaps
you try....

----
newRow:
        {button1 := (builder
        newButtonFor: self
                action: #listaPrestamos
                label: 'Prestamos'
                help: 'Listar Prestamos').

----
...and then later try
    button1 toggleVisible.

No guarantees this will work, but at least something to chew on.

cheers -ben

J. P. L. Martín wrote:

> Hi, I'm trying to display buttons only if a condition is true on the same
> window, making the condition is easy but I can get the conditional to run
> again when a change is done so it displays the row with the buttons, here
> is the code:
>
> open
>     | builder content |
>     builder := UITheme builder.
>     content := builder
>         newColumn:
>             {(builder
>                 newRow:
>                     {(builder
>                         newButtonFor: self
>                         action: #listaPrestamos
>                         label: 'Prestamos'
>                         help: 'Listar Prestamos').
>                     (builder
>                         newButtonFor: self
>                         action: #listaMateriales
>                         label: 'Material'
>                         help: 'Listar Material').
>                     (builder
>                         newButtonFor: self
>                         action: #listaSocios
>                         label: 'Socios'
>                         help: 'Listar Socios').
>                     (builder
>                         newButtonFor: self
>                         action: #listaEjemplares
>                         label: 'Ejemplares'
>                         help: 'Lista de Ejemplares')}).
>             (builder
>                 newColumn:
>                     {((PluggableMultiColumnListMorph
>                         on: self
>                         list: #listado
>                         selected: #seleccionado
>                         changeSelected: #seleccionado:
>                         menu: nil
>                         wrapSelector: #wrap:at:) extent: 600@600)})}.
>             #listado = Prestamo database ifTrue: [builder
>                 newRow:
>                     {(builder
>                         newButtonFor: self
>                         action: #addPrestamo
>                         getEnabled: nil
>                         label: 'Nuevo Prestamo'
>                         help: 'Ingresar nuevo prestamo').
>                     (builder
>                         newButtonFor: self
>                         action: #devPrestamo
>                         getEnabled: #selecciono
>                         label: 'Devolver'
>                         help: 'Devolver').
>                     (builder
>                         newButtonFor: self
>                         action: #addEjemplar
>                         label: 'Agregar Ejemplar'
>                         help: 'Ingresar nuevo ejemplar').
>                     (builder
>                         newButtonFor: self
>                         action: #addMaterial
>                         label: 'Agregar Material'
>                         help: 'Ingresar nuevo material').
>                     (builder
>                         newButtonFor: self
>                         action: #addSocio
>                         label: 'Nuevo Socio'
>                         help: 'Ingresar nuevo socio').
>                     (builder
>                         newButtonFor: self
>                         action: #remover
>                         getEnabled: #selecciono
>                         label: 'Remover'
>                         help: 'Ingresar nuevo prestamo').
>                     (builder
>                         newButtonFor: self
>                         action: #guardar
>                         label: 'guardar'
>                         help: 'Ingresar nuevo socio')}] ifFalse:
> (Transcript show: 'Flase'; cr).
>     (content openInWindowLabeled: 'Babel') extent: 600 @ 600.
>     self changed: #listado;
>     changed: #open.
>
>  


Reply | Threaded
Open this post in threaded view
|

Re: Dynamic GUI possible?

Gary Chambers-4
In reply to this post by J. P. L. Martín

You might investigate using a Groupbox with a getContentSelector.
That way your model can replace the group content depending on your conditions.
 
A simple example is attached.
 
File in and doit on
 
ExampleModel new
 open;
 inspect
 
 
In the inspector bottom pane doit for:
 
self aVariable: #one
 
or
 
self aVariable: #two
 
or
 
self aVariable: #blank
 
(or anything else for that matter)
 
 
Your model should implement
a method that answers the content (morph) for the group depending on your conditions.
Doing "self changed: <selector>" (<selector> being the name of that method) in the model object
will cause the group to change its contents appropriately.
 
Hope that helps! Any questions, do ask, though not around at weekends!

Regards, Gary
----- Original Message -----
Sent: Friday, January 11, 2013 3:50 PM
Subject: [Pharo-project] Dynamic GUI possible?

Hi, I'm trying to display buttons only if a condition is true on the same window, making the condition is easy but I can get the conditional to run again when a change is done so it displays the row with the buttons, here is the code:

open
    | builder content |
    builder := UITheme builder.
    content := builder
        newColumn:
            {(builder
                newRow:
                    {(builder
                        newButtonFor: self
                        action: #listaPrestamos
                        label: 'Prestamos'
                        help: 'Listar Prestamos').
                    (builder
                        newButtonFor: self
                        action: #listaMateriales
                        label: 'Material'
                        help: 'Listar Material').
                    (builder
                        newButtonFor: self
                        action: #listaSocios
                        label: 'Socios'
                        help: 'Listar Socios').
                    (builder
                        newButtonFor: self
                        action: #listaEjemplares
                        label: 'Ejemplares'
                        help: 'Lista de Ejemplares')}).
            (builder
                newColumn:
                    {((PluggableMultiColumnListMorph
                        on: self
                        list: #listado
                        selected: #seleccionado
                        changeSelected: #seleccionado:
                        menu: nil
                        wrapSelector: #wrap:at:) extent: 600@600)})}.
            #listado = Prestamo database ifTrue: [builder
                newRow:
                    {(builder
                        newButtonFor: self
                        action: #addPrestamo
                        getEnabled: nil
                        label: 'Nuevo Prestamo'
                        help: 'Ingresar nuevo prestamo').
                    (builder
                        newButtonFor: self
                        action: #devPrestamo
                        getEnabled: #selecciono
                        label: 'Devolver'
                        help: 'Devolver').
                    (builder
                        newButtonFor: self
                        action: #addEjemplar
                        label: 'Agregar Ejemplar'
                        help: 'Ingresar nuevo ejemplar').
                    (builder
                        newButtonFor: self
                        action: #addMaterial
                        label: 'Agregar Material'
                        help: 'Ingresar nuevo material').
                    (builder
                        newButtonFor: self
                        action: #addSocio
                        label: 'Nuevo Socio'
                        help: 'Ingresar nuevo socio').
                    (builder
                        newButtonFor: self
                        action: #remover
                        getEnabled: #selecciono
                        label: 'Remover'
                        help: 'Ingresar nuevo prestamo').
                    (builder
                        newButtonFor: self
                        action: #guardar
                        label: 'guardar'
                        help: 'Ingresar nuevo socio')}] ifFalse: (Transcript show: 'Flase'; cr).
    (content openInWindowLabeled: 'Babel') extent: 600 @ 600.
    self changed: #listado;
    changed: #open.

ExampleModel.st (3K) Download Attachment