Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I need to change property of window when button gets pressed. There are pretty enough examples on Wolfram's website, but all they bind predefined function "Print[]" and I have no problems with binding Print function. But I can't bind something different.

I need call my own function and methods of Widgets.

This is a window whose property I want to change:

widget4 = Widget["TextPanel", {
"preferredSize" -> 
Widget["Dimension", {"width" -> 800, "height" -> 660}],
"contentType" -> "text/html",
"editable" -> False, "path" -> html1path}, Name -> "MainOutput"] 

 functio[]:=(Print["fffff"]);

This is my button:

html2path="some text which I want to change";
butto = Widget["Button", {
"Text" -> "Update",
BindEvent["Action",
Script[    {SetPropertyValue[{"MainOutput", "path"}, html2path] , 
  Print["fdfdf"], ref@InvokeMethod[{"Frame", "getX"}], functio[] } ]]
}]

I launch it all together so:

ref = GUIRun[ Widget["Frame", {widget4, butto}, Name -> "Frame" ]];

As result out of all my tries only function Print["fdfdf"] was called. enter image description here

I got stuck with it.
Thanks in advance.

share|improve this question
    
GUIKit has not been maintained for a long time and suffers from many bugs. You might like to try David Bailey's super widget package as an alternative. But bear in mind I say this having not seriously used either of them. –  Oleksandr R. Nov 28 '13 at 20:32
    
sadly, it seems it is not so new as well as GUIKit –  gekannt Nov 28 '13 at 20:37
1  
Are you working in a version higher than 5? If so, I'd suggest dropping GUIkit and work with the dynamic controls introduced in version 6 and later. –  Sjoerd C. de Vries Nov 28 '13 at 22:08
    
I'm working in 9th Version. it's sad. Application would look better using GUIkit. It can render CSS. Until now I got this minus.com/ldan2YzBYKV5N . I'd not like to leave it. –  gekannt Nov 28 '13 at 22:23

1 Answer 1

After trying to solve it for a day. I came to the point that looking for source code is necessary.


The most interesting files I found here: /home/sh/po/mathematica_installed/AddOns/Packages/GUIKit/GUI/AuthorTools

(i.e. you need check this path "/AddOns/Packages/GUIKit/GUI/AuthorTools" in the folder where Mathematica is installed to)

These files have pretty good examples of Mathematica's GUIKit usage:

HelpBrowserSearchScriptCode.m
DirectorySearchScriptCode.m
DirectorySearch.m

They prove that GUIKit can work good.

The problem was that for changing GUI's elements Script which handle's button's pressing MUST be executed in the Java ATW Thread.

So now I have such working code:

Needs["GUIKit`"];
ref = GUIRun[ 
Widget["Panel", {
 Widget["Button", {
  "text" -> "Run",
  BindEvent["action",
   Script[
    SetPropertyValue[{"button", "enabled"}, False, 
     InvokeThread -> "Dispatch"];

    SetPropertyValue[{"label", "text"}, 
     "New Text! Huuuraaaaaaaaaaa!!!!!!!!", 
     InvokeThread -> "Dispatch"];

    SetPropertyValue[{"button", "enabled"}, True, 
     InvokeThread -> "Dispatch"];
    ], 
   InvokeThread -> "New"]
  }, Name -> "button"],
Widget["Label", {
  "text" -> "Press Button to see changes      "
  }, Name -> "label"]
}]  ]

It's explained here also.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.