Page 1 of 2

com.livecode.widget.ColorPicker

Posted: Mon Aug 20, 2018 1:00 am
by pink
Is there such a widget as "com.livecode.widget.ColorPicker"?

I was trying to follow the "PopupWidget" example:

Code: Select all

private variable mColor as Color

public handler OnClick()
	variable tProperties as Array
	put the empty array into tProperties
	put mColor into tProperties["currentColor"]

	popup widget "com.livecode.widget.ColorPicker" at the mouse position with properties tProperties
	if the result is not nothing then
		put the result into mColor
		redraw all
	end if
end handler

public handler OnPaint()
	...
	set the paint of this canvas to solid paint with color mColor
	...
end handler
all I get is a faint grey rectangle

Re: com.livecode.widget.ColorPicker

Posted: Tue Aug 21, 2018 2:45 pm
by pink
I still can't find any other reference to "ColorPicker"

Re: com.livecode.widget.ColorPicker

Posted: Wed Aug 22, 2018 3:53 pm
by livecodeali
There is no such widget - I think the docs were intended to be illustrative rather than literal there. It would be better to replace with a working example though, so it could be changed to "com.livecode.widget.iconpicker" with selectedIcon instead of currentColor.

If you are asking because you actually want a color picker, we don't have one that's pure LCB - there's "com.livecode.widget.colorswatch" but currently it's a little useless to pop up as it is coded in the IDE to 'answer color' on mouseUp, rather than directly in LCB to execute script.

Re: com.livecode.widget.ColorPicker

Posted: Wed Aug 22, 2018 3:59 pm
by livecodeali
In general widgets require specific coding to handle the case when they are popped up by some other script

Re: com.livecode.widget.ColorPicker

Posted: Wed Aug 22, 2018 6:50 pm
by pink
I was mostly just trying to make the example work, though a color picker would be a great widget

so for a popup widget... do i need to program the widget separately to return the value to the parent? I'm ssuming I can't just use any widget since there needs to be some way to get a specific value...

Re: com.livecode.widget.ColorPicker

Posted: Fri Aug 24, 2018 10:56 am
by livecodeali
It doesn't have to be a whole new widget, but yes, within the widget you need specific logic for returning a value - see the 'currently popped up' syntax in the dictionary, or the code in the icon picker.

Re: com.livecode.widget.ColorPicker

Posted: Fri Aug 24, 2018 12:36 pm
by [-hh]

Re: com.livecode.widget.ColorPicker

Posted: Fri Aug 24, 2018 5:21 pm
by pink
Is it working in LC9 yet?

Re: com.livecode.widget.ColorPicker

Posted: Sun Aug 26, 2018 7:03 pm
by [-hh]
pink wrote:Is it working in LC9 yet?
I tried today. The widget works in LC 9 but it crashes LC immediately when saving.

This was my last trial with widgets and LC 9.0, sorry.
(It's so frustrating, most widgets that worked in LC 8 crash now LiveCode 9. Obviously there are several undocumented LCB changes from LC 8 to LC 9. I cannot work this way.)

Re: com.livecode.widget.ColorPicker

Posted: Mon Aug 27, 2018 12:24 am
by bwmilby
I’m sure there are a few that would look at the code to help track down where the issues are.

Re: com.livecode.widget.ColorPicker

Posted: Mon Aug 27, 2018 1:50 am
by [-hh]
Here is the source code.
The attached demo stack works perfectly in LC 8 but crashes LC 9 when saving.
Looking into the lcb file may hopefully help 'pink' for his own picker.

Re: com.livecode.widget.ColorPicker

Posted: Mon Aug 27, 2018 6:11 am
by bwmilby
I think it just needs one or both of these handlers (probably just the first one):

Code: Select all

public handler OnSave(out rProperties as Array)
	put the empty array into rProperties
	return rProperties
end handler

public handler OnLoad(in pProperties as Array)
end handler
When I added them, I was able to save the demo stack to another location and it retained the changed colors. Before I made the change, a corrupted version of the stack was left (with the ~ version also remaining).

I'm not sure if this is a bug or an intended change. I wouldn't think LC should crash if the OnSave handler is missing (since in this case it was omitted on purpose). I did look at the docs, and it just says that the core handlers should be included.

Re: com.livecode.widget.ColorPicker

Posted: Mon Aug 27, 2018 11:11 am
by [-hh]
Many thanks for solving this.
bwmilby wrote:I'm not sure if this is a bug or an intended change. I wouldn't think LC should crash if the OnSave handler is missing (since in this case it was omitted on purpose). I did look at the docs, and it just says that the core handlers should be included.
I think none of the widgets on github (livecode/extensions/widgets/) has all core handlers included. For example colorswatch.lcb contains not OnSave() nor OnLoad().
bwmilby wrote:Before I made the change, a corrupted version of the stack was left (with the ~ version also remaining).
The stack bears possibly another problem because it contains the LC 8 widget. But without the OnSave() the widget crashed LC 9 also with a new stack.

Anyway: As soon as the widget is installed in LC 9 it is removed for LC 8. So it is impossible to develop for LC 9 and LC 8 at the same time.

LC 8 is much more stable than the regularly crashing LC 9. I had no crash with final widgets until now with LC 8.
Of course, one could do an automatic recompiling/reinstalling when switching LC8/LC9 as LC does. But by that one cannot use one of the (recently very rare) new LCB-features ...

So currently it is, sadly, better to stay with LC 8.

Re: com.livecode.widget.ColorPicker

Posted: Mon Aug 27, 2018 11:36 pm
by bwmilby
The release of LC 9 fixed the recompile issue. What you need to do is update the source code and install in LC 8. When you launch LC 9 it will recompile the widget for LC 9 but leave the working code for LC 8 as long as the lcb file is present. The files are "module.lcm" and "module.2.lcm"

Re: com.livecode.widget.ColorPicker

Posted: Tue Aug 28, 2018 11:04 am
by [-hh]
Brian wrote:The release of LC 9 fixed the recompile issue. What you need to do is update the source code and install in LC 8. When you launch LC 9 it will recompile the widget for LC 9 but leave the working code for LC 8 as long as the lcb file is present. The files are "module.lcm" and "module.2.lcm"
1.
This is no good solution because it should only check whether there is already a .lcm or .2.lcm file respectively. The installed widget needs only lcm, not lcb. But excluding the lcb file from the package is currently the only way to 'protect' the widget.

2.
This makes only sense for code that runs both in LC 8 and LC 9. This is sadly a strong LCB subset of *both* LC 8 and LC 9:
There is LCB 8 code that doesnt't compile with LCB 9 and there is LCB 9 code (not only new features) that doesn't compile with LCB 8.

Until this isn't solved I see no way to write a more than simple widget for both LCB 8 and (the still 'unfinished') LCB 9.