Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

[JS CS3/4] ScriptUI How to color a button ?

People's Champ ,
Oct 20, 2009 Oct 20, 2009

Is it a way to get a colored button in the ScriptUI DOM ?

I tried

dlg.button1.graphics.backgroundColor = dlg.button1.graphics.newBrush(dlg.button1.graphics.BrushType.SOLID_COLOR,[0.7,0.7,0.7],1);

But although the dialog is drawn, the button is not styled in best case, not visible in the worst case.

Is that possible to get a colored button ?

Hope so.

Do you have any tip ?

TIA

Loic

TOPICS
Scripting
36.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Oct 23, 2009 Oct 23, 2009

> To get that to work, you need to stack three objects like I've done here:

or add three lines, like I've done here ...

function customDraw()

{ with( this ) {

graphics.drawOSControl();

graphics.rectPath(0,0,size[0],size[1]);

graphics.fillPath(fillBrush);

if( text ) graphics.drawString(text,textPen,(size[0]-graphics.measureString (text,graphics.font,size[0])[0])/2,3,graphics.font);

}}

var dlg = new Window('dialog', 'Test');

var pnl = dlg.add('panel', undefined, 'My Panel');

var btn = pnl.add('button', undef

...
Translate
People's Champ ,
Dec 14, 2012 Dec 14, 2012

Hi guys,

As far as I am concerned, this problematic even has decided me to turn from scriptUI to ( what was then PatchPanel ) extensions. I still do ScriptUI once in a while but and it's really my humble opinion, I always found cumbersome to have so many lines of code for the simpliest UI behaviour. However I deeply admire how far Peter and Marc ( and a few others guy btw ) have pushed ScriptUI to the limits.

But I realise how troll-ish this post could be and I apologize for that. I just wanted to share my experience and how this colored button consideration affected my poit of view

Best to all,

Loic

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 15, 2012 Dec 15, 2012

Loic,

Could you give us an outline of what you can do in Extensions that you cannot do in ScriptUI?

Thanks,

Peter

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Dec 15, 2012 Dec 15, 2012

Hi Peter,

As far as I am concerned too, Loïc is right in that Flex provides a huge collection of native and pre-built widgets and controls that would need a lot of code to be mimicked in ScriptUI: many kinds of buttons and containers, date controls, menus, repeaters, validators, formatters, effects, not to mention chart controls, advanced datagrids, media loaders and web-friendly components. There is no doubt that Flex-based UI is much easier to design. Cf. http://examples.adobe.com/flex3/componentexplorer/explorer.html

However—as you know—I'm still a big supporter of ScriptUI despite its Spartan side. Its main advantage is to be instantly available to ExtendScript programmers, it does not require JS-AS bridge(s), does not relies on a Flash player, and does not involve complicated bricks and libraries when you need to interact with the DOM from your UI, which after all is our main purpose. Last point: ScriptUI is part of the basic Creative Suite, while FlashBuilder + CS ExtensionBuilder are additional products.

My personal feeling is that Flash/Flex/ActionScript technologies in Adobe apps involve a high density of dependencies. As soon as we try to develop some advanced functionality, there are too many bricks to handle and connect, and too many constraints to be aware of. Dealing with both ActionScript, MXML, Flex compilation issues, CS ActionScript Wrapper Library (CSAWLib and/or csaw_indesign.swc), CS eXtensible Services (CSXSLibrary), and/or HostObject, and/or id_host_adapter, and/or ExternalInterface, and/or SWFLoader, etc., is simply too much for me, while my goal is just to make some “scripted plug-in” available to ID CS4/CS5/CS6 users. As I have a very limited memory, I just want to focus on the core of my project—which is basically to turn the InDesign DOM into a cultivated variety! ExtendScript-JS is an integrated module that offers all what I need and only what I need, including ScriptUI.

@+

Marc

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Dec 15, 2012 Dec 15, 2012

Hi Marc, Peter,

Yes I agree. My intention never was to pretend some technology is better than the other. My switch was a personal statement based on the efforts to get nice and advanced UI.

I think Marc described well the advantages and disadvantages of both solutions. but I don't think you need so many dependancies.

- CSAW libs intend to allow developers to call the host dom directly in AS3. But can keep on scripting jsx files and call them from Flex thus splitting what deals with UI and what deals with application scripting. Besides, sometimes I did used wrappers but then later realized it might not be so useful and turned back to calling external jsx files ( mostly cause to doScript ).

- CSXS Library allows you to get access to extension properties such as skin, size…You can never have to play with that library.

- Host Adapter are really great as they extend access to some core events you don't have in the DOM. I am doing some Illustrator development and the list of events is amazing.

Unless I am wrong, you cannot monitor a document_changed with the InDesign DOM. The only workaround I found in ScriptUI was to use teh flashplayer and loads a SWF file that internally looks regularly for document states. Besides, is having timers in ExtendScript possible ? Don't know.

- ExternalInterface is only really useful when you combine ScriptUI and Flash. I don't remember to have used it in a extension context.

So you may not want to use any of them if you don't want to

But yes, the biggest bone is that this all relies on Adobe support for such "plug-ins". But it seems that C++ developers are also invited to use Flex for UIs instead of C++ UIs ( not a C++ developer myself so sorry for unreliable info on that field ). So I guess AS3 UIs are going to take more and more importance. Anyway, as we can call jsx files, it doesn't change a lot of things.

@Peter, what I can do in Extensions that I wn't be able to do in ScriptUI ? I don't knwo exaclty because I did'nt explore all the ExtendScript depths. So I won't tell i can't do it. I just say I can't imagine right now how I could do it. But here are a few topics I can think of :

- Webservices : I am implementing SOAP webservices for an extension project. In Flex, calling webservices is really easy. I have no clue how to deal with this in pure ExtendScript

- Integration

- UI IDE : I can build Uis almost exactly as I want without many lines of code so I can concentrate on the code for application functions

- States :  I like this one in Flex, you can switch from one view to another just by calling the state to display. But I think it's nothingunfeasible in ScriptUI.

- Controls & dataprovider : It's really easy to feed items such as datagrids. As a comparison, I amm trying to develop a ScriptUI product these days with a list that should display the content of a CSV file. The logic with subItems.add…Ok but you have to feed every line, one by one. Or I miss something ? in Flex, I just declare a dataprovider and sets it and voilà…

I have no need to precise how admirative I am of Marc's work with ScriptUI and I am not pretending ScriptUI is bad in any way. I just say that I felt more cumfortable to get nice UIs with Flex while keeping ExtendScript for driving apps. It's a personal statement, nothing less nothing more

And in the end, t's probably what matters, that every one finds its pace

Best,

Loic

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Dec 15, 2012 Dec 15, 2012

I totally agree.

Thanks for your input about CSAW, CSXS libs, HostAdapter, ExternalInterface and so on. For sure I've mentioned things that are not actually relevant in developing an extension (in fact, I'm lost in this complexity). What I can say is just that at a given time I was faced with either of these bricks, especially when the problem was to deal with multiple versions of InDesign. The time I spent trying to understand how (or whether) they fit together leads me to give up.

To go back to the topic (customizing a button), I think an important property is not seen, or overlooked: since CS4, most of ScriptUI widgets and containers fully support regular mouse events (click, mousedown, mouseup, mouseover, mousemove, mouseout). And you can attach listeners to a Group or a Panel as well. This means you really can—with some effort—emulate button-like components, based on nested groups, images and/or statictexts. This is not easy, but a number of approaches are available, and work fine. For example, every button you see in the below ScriptUI dialog are built from scratch using such techniques:

ingutter.png

Playing with background colors during mouse events allows to mimick interactive colored buttons with various effects. The user really feels like s/he is interacting with regular buttons, while there is not a single actual ScriptUI button in that interface.

Peter's Dummies guide and Dirk's snippets show many other tricks to manage colors and widgets dynamically. Also, we have the “sprite” trick — http://www.indiscripts.com/post/2011/04/sprite-buttons-in-scriptui —, we can play with onDraw, we can shift the content of a group, etc.

So many ways to customize buttons in ScriptUI!

@+

Marc

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 15, 2012 Dec 15, 2012

There's not a whole lot that you "Can't" do in ScriptUI, but there's a lot that's much harder.

I wrote an article a little over a year ago which touches on the topic:

http://in-tools.com/article/thoughts-on-extending-the-creative-suite/

Loic's list is good. Bindings in Flex is very valuable. It takes away a lot of the plumbing work. Of course, some of the real biggies are native panels and focus issues. CSXS panels and dialogs do not have the focus issues in Script UI. Another nicety is the ability to modify the DOM while modal dialogs are active.

The stuff Marc has done in ScriptUI is simply amazing, but very few people could achieve the UIs he's done.

Harbs

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 16, 2012 Dec 16, 2012

Thanks for these thoughts, Loic, Marc, and Harbs. I've been playing around with the Flex explorer that Marc gave that link to, and it's quite impressive (Dirk has been telling me for ages that I should look turn to Flex). The ease of building interfaces is remarkable, the flexibility of the various controls compelling, and I've been eying especially the TextArea control jealously.

One point Marc made, though, is a strong one. He seems to suggest that Flex is a closed system in that it's not easy -- if at all possible -- to extend it. For instance, there's ComboBox (the equivalent of ScriptUI's dropdownbox) and TextInput (ScriptUI's edittext). Neither Flex nor ScriptUI have a control that combines these two controls to provide an input field that you can populate from a dropdown list (examples in InDesign's UI are Weight in the Stroke panel and point size and leading in the Character panel). In ScriptUI you can build these (as indeed Harbs has shown); could you do that Flex? In other words, ScriptUI allows some rummaging under the hood, and I don't know if that's possible in Flex. And Marc's ScriptUI-based interface tools as shown by the IndexMatic and InGutter interfaces show how far you can go with customising interfaces.

But anyway, Harbs's eloquent argument for both approaches -- use Extensions or ScriptUI-based scripts depending on what is required -- makes perfect sense.

Peter

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 16, 2012 Dec 16, 2012

Flex allows for much more rummaging under the hood than ScriptUI ever could. Flex components are all open source, so you can create a new component based off an old one, you can extend components to change behavior, or you can create a totally new component from scratch.

For example, I needed a tri-state checkbox in a Flex UI, so I took the standard checkbox, and extended to to support tri-state control. I have extended the Flex numeric stepper to act more like the standard InDesign one, etc.

The only real arguements I see for ScriptUI are:

1) The ease in creating native looking UIs. Making nice ones in Flex isvery easy, but totally native looking ones is very hard.

2) The ability to include everything in a script file. CS Extensions must be installed (one way or another).

If you want to see what can be accomplished in text areas, I'll be happy to send you my CSS panel (which I REALLY need to release already...) In have line numbering, autocomplete, auto indenting, etc...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 16, 2012 Dec 16, 2012

Of course pre-CS5 compatibility is another issue with Flex.

For the In-Tools Dashboard, I have two versions, one for CS3 and CS4 and a second for CS5 and later. They look more-or-less the same, but the CSXS version requires much less jumping through hoops and there's focus improvements:

InTools Dashboard 2012-12-16 14-03-18.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 16, 2012 Dec 16, 2012

Peter Kahrel wrote:

For instance, there's ComboBox (the equivalent of ScriptUI's dropdownbox) and TextInput (ScriptUI's edittext).

Actually, this is a good example to illustrate the strength of the Flex approach. Combobox has an editable property which does combine the functionality of the two components. Set the combobox to editable and you can just type in the text field. There's even various autocomplete components out there that filter a dropdown as you type.

Another very useful feature in Flex is itemRendereres and itemEditors. These are basically dropin compound components that are "magically" populated by data (or edit data) within lists and data grids.

Besides the use of Flex in InDesign, I highly recommend learnig ActionScript and Flex for another reason. Even though Flash is no longer popular by the masses, AIR is a very poweful developing platform -- both for desktop and mobile. Apache Flex is also quite active, and it looks like there will be cross compilers to javascript and html in the future (maybe Java and Objective C too), so it will likely be a popular framework for web and mobile development. I'm very happy I put in the effort to learn it when I did.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 16, 2012 Dec 16, 2012

Thanks Harbs.

> I'll be happy to send you my CSS panel

Yes, please.

> Flex allows for much more rummaging under the hood than ScriptUI ever could.

Good!

Peter

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 16, 2012 Dec 16, 2012

I sent you an email.

Harbs

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Dec 16, 2012 Dec 16, 2012

@Peter,

Yep, I think everything has been said. I thought about itemRenderers/itemEditors also but Harbs was quicker

As for extending components, you can easily override native components if necessary and the spark paradigm let you envision to make anything being anything. I mean a component becomes more generic, it just sets a certain number of "parts" that can be anything. I don't do spark components myself and stick for mx.

Besides, it's a pity that Flash Catalyst was drop down so quickly because it was the perfect bridge between UI conception in creation programs such as Illustrator and code generation for using it within Flash Builder. My former company was able to generate AIR apps in a couple of days with that workflow.

Loic

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 16, 2012 Dec 16, 2012

Thanks Loic. That's the Xmas holidays sorted out!

Peter

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 07, 2013 Jan 07, 2013

Hi there, in relation to post 35 - Yes,  I suppose you can't activate when it's disabled.

So I'm using onActivate and then using onDeactivate to close the win. It doesn't look amazing - but I need to colour code the buttons dynamically etc.

PS - I'm scripting After Effects, and some of the layering solutions here work, but loose the "button" appearance

when run in AFX. Run through the ESTK they have the button appearance.

This thread has been very helpful - 50 times more than the manual!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines