PhAB widget library

I am not using template at this time. All I am doing is creating a
new window and changing its class to PtMyWindow.
The window title is still not set to “DSI2” even when I run the
application. Also in PhAB, it doesn’t matter if I minimize the
maximize or in test mode of edit mode, I don’t see my PtMyWindows’s
default value.

I have done exactly the same thing with my PtMyButton, and it works as
I expected. If possible, can you send me your tested code for window
widget?
Thanks

I must have been in a sleep when I wrote above reply. I will correct
couple of things:

Also in PhAB, it doesn’t matter if I minimize or maximize or be in
test mode or edit mode, I do not see the default values being loaded
in the resource editor window and the window widget is still looks
the same as original. However, if I treat my window as normal widget
and place it inside a normal window or container, I do see my
PtMyWindow with all the default value correctly. But in this case, I
can not use this PtMyWindow widget in anyway.

jinma wrote:

Also in PhAB, it doesn’t matter if I minimize or maximize or be in
test mode or edit mode, I do not see the default values being loaded
in the resource editor window and the window widget is still looks
the same as original. However, if I treat my window as normal widget
and place it inside a normal window or container, I do see my
PtMyWindow with all the default value correctly. But in this case, I
can not use this PtMyWindow widget in anyway.

If you just create a new window module in PhAB, its title and fill
colour are overridden by PhAB’s own “defaults” for new modules. Notice
that their names are displayed in a bold font in the resource list –
that’s how PhAB tells you that those resources have been set to values
different from their widget defaults. (In some cases, it’s possible for
PhAB to have a bold entry for a value that doesn’t actually differ from
the default; PtWindow’s fill colour seems to be one of those cases. You
can get rid of it by picking some other colour, clicking on Apply, and
then on the Default button.)

When you change the class of a widget, PhAB preserves any of the bold
resource settings. If you want your new widget’s defaults to show,
you’ll need to open the resource editor for any such resource and set it
to the widget’s default value by clicking on the Default button.

If this is what I have to do, I don’t see any advantage of creating a
separate PtMyWindows class compared to just using PtWindows in my
case, if I have to specify default values from PhAB. What I want to
accomplish from this experiment was to create my own PtMyWindow class
with predefined default values set within the Class code and not from
PhAB or Momentics IDE .wgtw file. Then once I create my application
using this PtMyWindow class without changing the default values, I
would like my application to inherit new default values when I
recompile my PtMyWindow class with different sets of default values.


For example, today we might have decided to have all our window widget
with fill color blue, but a year from now we might change all our
window widget to have green. If we have just used the standard PhAB
building approach we have to manually change all the window widget in
our application to make this change. But if we can just change one
master copy (PtMyWindow) and have all the window widget changed, this
what I am looking for here. I was able to do this with other widget
classes such as button, and label by creating my own Ptmybutton and
ptmylabel, and as soon as I make change to those classes, I don’t
even have to recompile my application to have those changes applied
because ptmybutton.so file is linked at runtime and it’s default
values are being set at runtime by the default function in the code.


Is this possible with PtWindow? I know I can do this with widget
database but I would like to create inherited widget classes so that
I can use PhAB to design my GUI and have more flexibility.

Thanks

jinma wrote:

If this is what I have to do, I don’t see any advantage of creating a
separate PtMyWindows class compared to just using PtWindows in my
case, if I have to specify default values from PhAB. What I want to
accomplish from this experiment was to create my own PtMyWindow class
with predefined default values set within the Class code and not from
PhAB or Momentics IDE .wgtw file. Then once I create my application
using this PtMyWindow class without changing the default values, I
would like my application to inherit new default values when I
recompile my PtMyWindow class with different sets of default values.

The short answer is that PhAB was not designed to support anything like
that. Any resource that PhAB knows about must have its default value
specified in the palette file. If you cheat and give PhAB a value
that’s not really the default, that may cause PhAB to misbehave. Of
course, depending on how much you know about how PhAB works, you may be
able to guess how badly PhAB will misbehave in certain cases and how to
work around it; but in general, that’s unsupported territory.

For example, today we might have decided to have all our window widget
with fill color blue, but a year from now we might change all our
window widget to have green. If we have just used the standard PhAB
building approach we have to manually change all the window widget in
our application to make this change. But if we can just change one
master copy (PtMyWindow) and have all the window widget changed, this
what I am looking for here. I was able to do this with other widget
classes such as button, and label by creating my own Ptmybutton and
ptmylabel, and as soon as I make change to those classes, I don’t
even have to recompile my application to have those changes applied
because ptmybutton.so file is linked at runtime and it’s default
values are being set at runtime by the default function in the code.

The difference between your MyPtButton and your MyPtWindow is that PhAB
actually attempts to load your library and use your real MyPtButton, but
always uses a PtContainer to display your MyPtWindow. A real MyPtButton
will display its real default colour if it hasn’t been overriden in
PhAB; a fake PtMyWindow will display the colour that your palette file
tells PhAB is the default. Since PhAB never creates a real MyPtWindow,
it has no way to find out what its defaults really are.

Is this possible with PtWindow? I know I can do this with widget
database but I would like to create inherited widget classes so that
I can use PhAB to design my GUI and have more flexibility.

You could use a template to set up a MyPtWindow that has its fill colour
set to its default, as defined by the palette file. It won’t update
itself automatically inside PhAB when you change the default in your
library; but if you also change it in your palette file, I think PhAB
should display it accordingly. As far as I can tell, that’s the closest
to what you want that PhAB “almost officially” supports.

Ok, I guess I will be working in the unsupported territory for a
while. And I got my PtMyWindow to work theh way I like it, even
though it doesn’t show the right PtMyWindow widget in PhAB, if I
don’t edit anything and compile it, I do see the correct custom
widget.

But now I am having trouble setting the size of my custom widget. Can
you tell me how I can specify the default size of my custom widget
(for example PtMyButton). I tried setting PhDim_t structure and used
PtSetResource() on Pt_ARG_DIM in my widget class default function but
it doesn’t seem to take it. I don’t know where else PhAB is getting
this size information because I don’t see it in my pal file either.
right now PhAB is making my PtMyButton to be 50x50.

Thanks

jinma wrote:

But now I am having trouble setting the size of my custom widget. Can
you tell me how I can specify the default size of my custom widget
(for example PtMyButton). I tried setting PhDim_t structure and used
PtSetResource() on Pt_ARG_DIM in my widget class default function but
it doesn’t seem to take it. I don’t know where else PhAB is getting
this size information because I don’t see it in my pal file either.
right now PhAB is making my PtMyButton to be 50x50.

I haven’t checked how exactly PhAB sets up the size, but my
understanding is that PhAB doesn’t need to know from the palette what
default size the library sets the widget to. Instead, you can tell PhAB
how big to make a new widget, using the t= and d= syntax in the palette
(see docs). For PtButton, the ptpalette.pal that comes with PhAB says
t=1 and never specifies an initial size, causing the widget’s resize
policy to grow it to a reasonable size. Does your PtMyButton have a
resize policy?

I don’t have any resize policy for my PtMyButton, at least that’s what
I have tried to do. And I know this is true because when I type a
long string name for my PtMyButton, the string is cut offed and the
button doesn’t resize automatically.
I have tried following your solution but it still doesn’t change the
size of my widget. I have also tried to change the default value of
PtButton by editing the ptpalette.pal as follows

t=1
d=PtButton,1
1005
dim
100,100

but this doesn’t create 100 by 100 button in PhAB either. I thought
that if I don’t have not specify default size for my widget shouldn’t
PhAB take it from my default function for that widget?

do I need to set the dimension values in my PtMyButton realized_f
method?
Where can I set this value so that PhAB takes this value rather than
putting it’s own?
I will also be setting t=4 on this widget so that the size can not be
changed in PhAB.

jinma wrote:

I have also tried to change the default value of
PtButton by editing the ptpalette.pal as follows

t=1
d=PtButton,1
1005
dim
100,100

but this doesn’t create 100 by 100 button in PhAB either.

Yes, I can see that too. I’ll investigate it.

I thought
that if I don’t have not specify default size for my widget shouldn’t
PhAB take it from my default function for that widget?

What normally happens for most widgets is that the defaults function
leaves the size unset (i.e. set to one pixel) but then the proper size
is set by the extent function during realization, based on the widget’s
contents and resize policy. For widgets that don’t have any resize
policy by default, it makes sense for the defaults function to set up a
size that corresponds to the widget’s default contents.

jinma wrote:

do I need to set the dimension values in my PtMyButton realized_f
method?

No, it’s the job of the extent method.

Where can I set this value so that PhAB takes this value rather than
putting it’s own?
I will also be setting t=4 on this widget so that the size can not be
changed in PhAB.

It used to work as documented; I’ll have to investigate to find out why
it doesn’t and what to do about it.

“Wojtek Lerch” <Wojtek_L@yahoo.ca> wrote in message
news:dobsbi$m6p$2@inn.qnx.com

jinma wrote:
Where can I set this value so that PhAB takes this value rather than
putting it’s own?

It used to work as documented; I’ll have to investigate to find out why it
doesn’t and what to do about it.

It turns out that the d= stuff doesn’t work any more because widget creation
is completely template-based now. Even the default set of widgets in PhAB’s
control panel are all pre-defined templates. The writers already know that
this needs to be updated in the documentation.

hmmm I am getting confused now. In my new widget class (PtMyButton),
I created extend method and have set my dimension in there. This seem
to work and when I use PtMyButton, it drew the correct button in PhAB.
But one downside of this is that I could not adjust the dimension in
PhAB anymore. It is now preset to the dimension that I set in that
extend method.

Knowing this, if you are saying that everything is now template-based,
how can PhAB change dimension ? Are you saying that the only way to
predefine a dimension of any widget is to make it a template?

I believe, abpal.def and abpalu.def are the files to update when you
create templates in PhAB, can I update these files to set the
dimension?. Where are the parameters stored for pre-defined
templates for the default widgets?

jinma wrote:

hmmm I am getting confused now. In my new widget class (PtMyButton),
I created extend method and have set my dimension in there. This seem
to work and when I use PtMyButton, it drew the correct button in PhAB.
But one downside of this is that I could not adjust the dimension in
PhAB anymore. It is now preset to the dimension that I set in that
extend method.

That’s because the extent method always wins. Its purpose is to let
you override the size that an application (such as PhAB) tries to apply
to your widget. (That’s how the resize policy is implemented, for
instance.) If you want to let people resize your widget however they
want, your extent method must respect that.

Knowing this, if you are saying that everything is now template-based,
how can PhAB change dimension ? Are you saying that the only way to
predefine a dimension of any widget is to make it a template?

Pretty much. More accurately, since you can’t create a widget straight
from its palette entry any more, the dimension defined in the palette
file is meaningless. The only ways to create a PtMyButton widget are by
using a template, copying an existing PtMyButton, or changing the class
of some other widget to PtMyButton; in all those cases, the size is
inherited from the existing widget or the template.

I believe, abpal.def and abpalu.def are the files to update when you
create templates in PhAB, can I update these files to set the
dimension?. Where are the parameters stored for pre-defined
templates for the default widgets?

Don’t modify any files directly. Just create a PtBasic in PhAB, change
its class to your widget, set up its resources the way you want, and
save it as a template.