[Pharo-project] Learning how to use Polymorph
Gary, I am looking at Polymorph examples, to start learning it.
From your example, I see you have this ExampleBuilderMorph class Is it a class I can use to build my application interface, or do I need to subclass another MorphicModel (this last class is pretty large) ?
I see you are using trait for this class also. Hilaire -- http://blog.ofset.org/hilaire
Hi Hilaire, The example builder is specialised so that the example dialogs are not opened modally, just so it is easier to explore using each. There are currently two "standard" ways of utilising Polymorph widgets, depending on whether you are working at the Morph or Model level. For Morph based things: Either include the trait TEasilyThemed that provides access to the api for the morph or subclass ComposableMorph, which does effectively the same thing (assuming it is a "from scratch" morph that does not need to inherit from elsewhere. As an alternative, you may use the "model" way below... For Model based things: Use UITheme newBuilder and request the api from that object (just a ComposableMorph). For example, a method to return a list for a model might look like: newWorkingCopyListMorph "Answer a new list morph for the working copy list." ^UITheme builder newListFor: self list: #workingCopyList selected: #workingCopyListIndex changeSelected: #workingCopyListIndex: help: nil Of course, if you want a window then you can use a StandardWindow (subclass of SystemWindow) that includes the TEasilyThemed trait and delegate requests for widgets to that instead. Hope that helps... Gary. ----- Original Message ----- From: "Hilaire Fernandes" <hilaire@ofset.org> To: "An open mailing list to discuss any topics related to an open-sourceSmalltalk" <pharo-project@lists.gforge.inria.fr> Sent: Thursday, September 11, 2008 9:09 PM Subject: [Pharo-project] Learning how to use Polymorph
Gary,
I am looking at Polymorph examples, to start learning it.
From your example, I see you have this ExampleBuilderMorph class Is it a class I can use to build my application interface, or do I need to subclass another MorphicModel (this last class is pretty large) ?
I see you are using trait for this class also.
Hilaire
-- http://blog.ofset.org/hilaire
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
2008/9/15 Gary Chambers <gazzaguru2@btinternet.com>:
Of course, if you want a window then you can use a StandardWindow (subclass of SystemWindow) that includes the TEasilyThemed trait and delegate requests for widgets to that instead.
Hope that helps...
Yep, I figure out during the week-end. I am now converting step by step to Polymorph. I see that Trait can really make such thinkgs easier. One think not obvious to me: how to pack a menu bar, toolbar in StandardWindow, as you did for your professionnal application. A canonical exemple will be very usefull Hilaire
Hilaire, try this. Menus are something that hasn't fully been addressed by Polymorph yet so looks a little cumbersome (though less so if the indivdual parts had their own methods, like #fileMenu...). exampleWindowWithToolbars "Open an example window with toolbars." |win fileMenu tools dock text holder| win := StandardWindow new. fileMenu := win newMenu. fileMenu addToggle: 'Open' translated target: nil "would be model" selector: #openFile. fileMenu lastItem font: win theme menuFont; icon: MenuIcons smallOpenIcon; keyText: 'Ctrl+O'. fileMenu addToggle: 'Save' translated target: nil selector: #saveFile getStateSelector: nil enablementSelector: nil. fileMenu lastItem font: win theme menuFont; keyText: 'Ctrl+S'. fileMenu addToggle: 'Print...' translated target: nil selector: #print. fileMenu lastItem font: win theme menuFont; icon: MenuIcons smallPrintIcon; keyText: 'Ctrl+P'. tools := win newToolbar: {win newButtonFor: nil "if we had a model it would go here" getState: nil action: #openFile arguments: nil getEnabled: nil label: (ImageMorph new image: MenuIcons smallOpenIcon) help: 'Open file' translated. win newButtonFor: nil getState: nil action: #saveFile arguments: nil getEnabled: nil label: (ImageMorph new image: MenuIcons smallSaveIcon) help: 'Save file' translated. win newButtonFor: nil getState: nil action: #print arguments: nil getEnabled: nil label: (ImageMorph new image: MenuIcons smallPrintIcon) help: 'Print' translated}. holder := StringHolder new. text := win newTextEditorFor: holder getText: #contents setText: #contents: getEnabled: nil. dock := win newToolDockingBar. dock add: 'File' translated font: win theme menuBarFont icon: MenuIcons smallOpenIcon help: 'File operations' translated subMenu: fileMenu; addMorphBack: tools. win addMorph: dock fullFrame: (LayoutFrame fractions: (0@0 corner: 1@0) offsets: (0@0 corner: 0 @ dock minExtent y)); addMorph: text fullFrame: (LayoutFrame fractions: (0@0 corner: 1@1) offsets: (0@dock minExtent y corner: 0 @ 0)). win themeChanged; openInWorld Having no real model to perform the actions you'll get a walkback if any menu/tool item is chosen. Apologies for the requirement of #themeChanged near the end, must get around to fixing that! Regards, Gary. ----- Original Message ----- From: "Hilaire Fernandes" <hilaire@ofset.org> To: "An open mailing list to discuss any topics related to an open-sourceSmalltalk" <pharo-project@lists.gforge.inria.fr> Sent: Monday, September 15, 2008 1:32 PM Subject: Re: [Pharo-project] Learning how to use Polymorph
2008/9/15 Gary Chambers <gazzaguru2@btinternet.com>:
Of course, if you want a window then you can use a StandardWindow (subclass of SystemWindow) that includes the TEasilyThemed trait and delegate requests for widgets to that instead.
Hope that helps...
Yep, I figure out during the week-end. I am now converting step by step to Polymorph. I see that Trait can really make such thinkgs easier.
One think not obvious to me: how to pack a menu bar, toolbar in StandardWindow, as you did for your professionnal application. A canonical exemple will be very usefull
Hilaire
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
participants (2)
-
Gary Chambers -
Hilaire Fernandes