Making 2 windows appear simultaneously in Red language - window

How can I make these 2 separate windows appear simultaneously and remain open thereafter unless the quit button is pressed?
Red []
view/flags [ below
text "second view"
f2: field "f2 text"
] 'no-buttons
view/flags [ below
text "first view"
b1: button "Print f2 text" [print f2/text]
quitb: button "quit" [quit]
] 'no-buttons
I tried to put second view in a function and call it from first view- but it shows only second view (first view is shown after second is closed by Alt-F4).

A call to view is a blocking call that will run its own event loop, until it is closed. view/no-wait will open the window without a new event loop, so it will not block (still requires an event loop to process events). So you can open the first window as non-blocking, and the last one in blocking mode, for running the event loop:
view/no-wait/flags [
below
text "second view"
f2: field "f2 text"
] 'no-buttons
view/flags [
below
text "first view"
b1: button "Print f2 text" [print f2/text]
quitb: button "quit" [quit]
] 'no-buttons

Related

Hide and unhide a view in Red language

I am trying following code to have a second view which can be hidden and shown again repeatedly while preserving values in its fields:
Red []
secondFstr: ""
secondshownonce: false
secondshowing: false
secondview: does [
secondshownonce: true
if not secondshowing [
secondshowing: true
view [ below
text "second view"
f2: field secondFstr []
b3: button "Hide" [
secondshowing: false
unview ]]]]
view [ below
text "first view"
b1: button "Print f2 text" [
either not secondshownonce
[print "not shown"]
[print f2/text] ]
b2: button "Show 2nd view" [secondview] ]
It works all right if 'hide' button is used for second view. But if the second view is closed by clicking 'x' at its top right corner, it cannot be shown again. How can I solve this problem?
You need to add an handler to the close event on that child window, in order to reset your flag properly, like this:
view/options [
below
text "second view"
f2: field secondFstr []
b3: button "Hide" [
secondshowing: false
unview
]
][
actors: object [
on-close: func [face event][
secondshowing: false
]
]
]

MEL Querying a selected button

I am new to using MEL to write scripts.
I have two radio buttons, one and two. When radio button 'two' is selected, I want the script to select the two cube objects I have created in my scene (cube1 and cube2), so that when I use my 'rotate' button (a regular push button), both of the cubes rotate.
On the other hand, if the radio button 'one' is selected, then only one of them (cube1) should rotate when I press the rotate button.
I have my radio buttons as follows:
$radio1 = `radioCollection`;
//my radio buttons
$one = `radioButton -label "1 cube"`;
$two = `radioButton -label "2 cubes"`;
radioCollection -edit -select $one $radio1; //so that this one is selected by default
and for the rotate button I have this that rotates the cube object 'cube1' by 30 degrees. This is currently NOT linked to my radio buttons.
button -label "rotate" -command "setAttr cube1.rotateZ `floatSliderGrp -q -value 30.0`";
Thoughts? Should I query the radio button's state? This would be so much easier for me in another language! I could see myself saying something like "if $radiotwo.pressed, then cube1.rotateZ && cube2.rotateZ"
All Maya UI items are completely imperative: you have to issue commands and get results, there is no 'state': the 'button' or whatever will just be the string name of the object you'll use for issuing the commands
To get the state of the radiocollection you call radioCollection -q -select on the collection, which will return the name of the selected radio button; you'd use that to drive your logic.
string $w = `window`;
string $c = `columnLayout`;
string $radiocol = `radioCollection "radio buttons"`;
string $one_cube = `radioButton -label "1 cube"`;
string $two_cube = `radioButton -label "2 cubes"`;
radioCollection -edit -select $one_cube $radiocol;
showWindow $w;
global proc string get_radio_state(string $radio)
{
string $selected = `radioCollection -q -select $radio`;
return `radioButton -q -label $selected`;
}
print `get_radio_state($radiocol)`;
fiddle with the radio buttons and get_radio_state($radiocol); it should return the name of the selected button.
If you're already familiar with other languages, you should probably skip MEL and jump straight to maya python: it's much more capable and less tweaky. Lots of discussion here and here
For comparison, here's a python version of the same idea:
w = cmds.window()
c =cmds.columnLayout()
rc = cmds.radioCollection()
cmds.radioButton('one', label="1 cube")
cmds.radioButton('two', label = "2 cubes")
def print_selected(*ignore):
print "selected", cmds.radioCollection(rc, q=True, select=True)
btn = cmds.button("print selected", command=print_selected)
cmds.showWindow(w)
Here the button does the same thing as the print statement in the earlier example

Applescript Display Dialog User Input

I'm running an applescript program where I am asking for the user to type in their name. If the user clicks "OK", then the name gets stored to the variable I want. However, if the user clicks "Cancel", then the program just quits. How do I set this up to either hide the "Cancel" button, so it's not an option to click, or to set up a loop so that if cancel is clicked, it just continues to ask the user for his/her name until it's entered?
Thanks in advance.
display dialog "Please Enter Your Name." default answer " " with title "Enter Name"
simple solution
display dialog "Please Enter Your Name." default answer " " with title "Enter Name" buttons {"OK"} default button 1
Here's what I got:
display dialog "Please Enter Your Name." default answer "" buttons {"Submit"} with title "Enter Name" default button 1
if the button returned of the result is "Submit" then
set yourVariable to text returned of the result
end if
The way that you hide the cancel button is like this:
display dialog "Please Enter Your Name." default answer " " buttons {"ok"} with title "Enter Name"
set a to the text returned of the result
But if you wanted the repeat then use this (I have made it so they have to enter something too instead of just pressing ok to end it:
repeat
display dialog "Please Enter Your Name." default answer "" buttons {"ok", "cancel"} default button 1 with title "Enter Name"
set a to the text returned of the result
if the button returned of a is "ok" then
if the text returned of a ≠ "" then
exit repeat
end if
end if
end repeat

return a value when a button is clicked in shoes ruby

I have an app using shoes. In the model, I have
def run()
query = get_queries
executeQuery(query)
run()
end
Then this get_queries will append some buttons to stack, say
button "do 1"
button "do 2"
button "do 3"
button "do 4"
If the user clicks on the button, get_queries should return the corresponding query (Sometimes it may ask the user for more info, so basically, it returns an array containing query and info). And then the buttons are removed.
However, I am confused as to how to let the buttons return value for that function. I thought of using a variable and check if the variable is updated by busy waiting, but I don't think that is the efficient/right way to do it.
Any suggestions? Or is there another way to this?
I think you need to make your program work somewhat differently. Make get_queries append the buttons to the stack, as it does now, but move the other things from the run method into another method that is called only after the button receives a click-event.
def on_click(button_number)
executeQuery(button_number)
run()
end
button "do 1" do
on_click 1
end
button "do 2" { on_click 2 }
button "do 3" { on_click 3 }
...

Set bounds property for "choose from list" in AppleScript?

I'm making an applet that prompts users to choose from a list, and my list currently has 169 items. When the list is generated, the window extends from the top of the display to the bottom, a bit overwhelming for a user.
I'm wondering if anyone knows of a way to edit the bounds property of the window generated by "choose from list?"
Here's the code I'm using (not including separate code to compile the list and store it in "pkgList"):
set userChoice to (choose from list pkgList with title "Title" with prompt "Choose file:" OK button name "OK" cancel button name "Cancel" without empty selection allowed) as string
I'm very new to AppleScript, so detailed explanations and analogies are much appreciated. :)
You might use CocoaDialog instead:
set l to {"a a", "b"}
set l2 to ""
repeat with i in l
set l2 to l2 & quoted form of i & " "
end repeat
do shell script "/Applications/CocoaDialog.app/Contents/MacOS/CocoaDialog \\
standard-dropdown --title Title --text Text --items " & l2
set {button, answer} to paragraphs of result
if button is 1 then return
item {answer + 1} of l

Resources