How do I use the -exists flag from "window" command? - mel

The maya manual does not describe how -exists flag in window command is used. I tried many ways of using it and it does not budge.
I've been fiddling and googling for 2 days, it wasn't going anywhere. I was only trying to detect if one of my window is opened or not.
Here's the test code I've got so far:
string $something = `window -title "name of the window" -widthHeight 200 150`;
columnLayout -adjustableColumn false;
button -label "detect this window" -command "dothis_1";
showWindow $something;
proc dothis_1()
{
if (`window -ex $something` == true)
{
print "window detected!\n";
}
else
{
print "window detection failed!\n";
}
}
//--------
So...I assumed I did something wrong somewhere or I simply misunderstood what -exists does? What did I do wrong and how do I detect whether my window is opened or not?

Your procedure has a variable scope issue, where it doesn't know what $something is, because it's defined outside of it.
You could make your procedure accept an argument for a window name you want to check against, create your window, then pass its name to the button's command:
string $something = `window -title "name of the window" -widthHeight 200 150`;
columnLayout -adjustableColumn false;
button -label "detect this window" -command ("dothis_1 " + $something); // Pass window name to proc.
showWindow $something;
proc dothis_1(string $win) {
if (`window -ex $win` == true) {
print "window detected!\n";
} else {
print "window detection failed!\n";
}
}
Alternatively you should be able to create a global variable so that it's accessible within the procedure too.
Although your use case is a bit weird. You can only click the button if the window exists!

Related

How to show and hide the on-screen keyboard "onboard" in mate-screensaver?

I'm trying to add a mate-screensaver, so that there would be a switch on and off the on-screen keyboard (onboard) right on the window. All the functionality is ready, I use 2 settings of the org.mate.screensaver schemas:
embedded-keyboard-enabled
embedded-keyboard-command "onboard --xid"
When switching the switch, I change the value of embedded-keyboard-enabled to true or false, respectively, but the keyboard appears or disappears only after restarting the mate-sreensaver window. As I understand it, the keyboard is created by an asynchronous process, but how do I hide or show it when I need it?
Of the functions, I use g_settings_set_boolean() to set the key parameter and g_settings_apply() to apply the changes.
I wrote a little script that I load at login which toggles hide and show using my middle mouse button. This works very when I want to hide/show it quickly.
You could copy and past the below script, give it execution permission, and run it at startup. (You may need to install xprintidle.)
Copy and paste below text in your favourite text editor.
#!/usr/bin/bash
if [[ "$(pidof -x $(basename $0))" != $$ ]] ; then exit;fi
rest=0
sleep 35;# (i need to wait 30-35 seconds at login for the physical mouse id to be assigned instead of the virtual mouse. It might go quicker for you.)
MOUSE=$(xinput --list --long | grep XIButtonClass | head -n 1 | egrep -o '[0-9]+');
toggle() { dbus-send --type=method_call --dest=org.onboard.Onboard /org/onboard/Onboard/Keyboard org.onboard.Onboard.Keyboard.ToggleVisible;
}
while :;do
idle3=$(xprintidle)
STATE=$(xinput --query-state $MOUSE);
if [[ $STATE == *"button[2]=down"* ]];then toggle;sleep .5;elif [ $idle3 -gt 3000 ] && [ $rest = '.14' ];then rest=3;else rest=.14;fi;
sleep $rest;
done

How to set nodes in a treeview to start off checked if a checkbox on a previous window is selected

First time Posting on this site. I hope I have the information formatted correctly.
I am designing a simple windows form to help create change control forms to track employee access. It is a 2 part form. The main form asks for some user input and there is a checkbox at the bottom that they can select if they are requesting a standard user setup. When they click next in the main form a child form window pops up that contains a treeview and a comments section for any special notes. What I am trying to do is have some nodes automatically checked if the 'Standard Setup' box is checked in the main form.
When I run the code I get a error stating "Method invocation failed because First[System.Windows.Forms.TreeView] does not contain a method named 'checknode'."
My standard setup box is $checkboxStandardSetup and if it has been checked then I want to have it place a checkbox next to these nodes in the treeview. If it isn't checked no other modification need to be made in the treeview. Here is a snippet of what I have.
if ($checkboxStandardSetup.Checked)
{
$treeview1.checknode("7")
$treeview1.checknode("8")
$treeview1.checknode("9")
$treeview1.checknode("10")
$treeview1.checknode("11")
$treeview1.checknode("12")
$treeview1.checknode("14")
$treeview1.checknode("20")
}
I have also tried to use
if ($checkboxStandardSetup.Checked)
{
$treeview1.node7.checked
$treeview1.node8.checked
$treeview1.node9.checked
$treeview1.node10.checked
$treeview1.node11.checked
$treeview1.node12.checked
$treeview1.node14.checked
$treeview1.node20.checked
}
But to no avail. The function below works to parse through and then output a list of the checked nodes but I can't get the standard setup box to apply those checks.
Function Get-CheckedNodes
{
param (
[ValidateNotNull()]
[System.Windows.Forms.TreeNodeCollection]$NodeCollection,
[ValidateNotNull()]
[System.Collections.ArrayList]$CheckedNodes)
foreach ($Node in $NodeCollection)
{
if ($Node.Checked)
{
[void]$CheckedNodes.Add($Node)
}
Get-CheckedNodes $Node.Nodes $CheckedNodes
}
}
To call the function I use
$checkedNodes = New-Object System.Collections.ArrayList
Get-CheckedNodes $treeview1.Nodes $CheckedNodes
foreach ($node in $CheckedNodes)
{
Write-Output $node.text | Out-File -append C:\Change\UserForm$(Get-Date -Format 'MM-dd-yy').csv
}
I expected the treeview list to have a checkbox next to the nodes that I coded but instead I get the above error. I don't understand what I am doing wrong. Any advice appreciated!

Is there a way to send events to the parent job when using Start-WPFJob?

I would like to launch a non-blocking UI from a parent Powershell script and receive UI messages like button clicks from the child job. I have this kind of messaging working using WinForms, but I prefer to use ShowUI because of how much less code it takes to create a basic UI. Unfortunately, though, I haven't found a way to send messages back to the parent job using ShowUI.
[Works] Forwarding Events When Using Start-Job
Using Start-Job, forwarding events from a child to a parent job is rather straightforward. Here is an example:
$pj = Start-Job -Name "PlainJob" -ScriptBlock {
Register-EngineEvent -SourceIdentifier PlainJobEvent -Forward
New-Event -SourceIdentifier PlainJobEvent -MessageData 'My Message'
}
Wait-Event | select SourceIdentifier, MessageData | Format-List
As expected, it prints out:
SourceIdentifier : PlainJobEvent
MessageData : My Message
[Does Not Work] Forwarding Events When Using Start-WPFJob
Using Start-WPFJob, on the other hand, does not seem to forward events from the child to the parent. Consider this example:
Import-Module ShowUI
$wj = Start-WPFJob -ScriptBlock {
Register-EngineEvent -SourceIdentifier MySource -Forward
New-Button "Button" -On_Click {
New-Event -SourceIdentifier MySource -MessageData 'MyMessage'
}
}
Wait-Event | select SourceIdentifier, MessageData | Format-List
Running this example produces this window:
Clicking on the button, however, does not yield an event in the parent job.
Why doesn't the Start-WPFJob example yield events to the parent job?
Is there some other way to use ShowUI to produce a button in a non-blocking manner and receive events from it?
I can't get engineevents to forward properly so far (actually, I can't even get them to do anything, as far as I can tell), I think your best bet is to run the WPFJob, and instead of New-Event, update the $Window UIValue, and then from your main runspace, instead of Wait-Event, use Update-WPFJob in a loop.
I would stick this function into the module (actually, I will add it for the 1.5 release that's in source control but not released yet):
function Add-UIValue {
param(
[Parameter(ValueFromPipeline=$true)]
[Windows.FrameworkElement]
$Ui,
[PSObject]
$Value
)
process {
if ($psBoundParameters.ContainsKey('Value')) {
Set-UIValue $UI (#(Get-UIValue $UI -IgnoreChildControls) + #($Value))
} else {
Set-UIValue -Ui $ui
}
}
}
And then, something like this:
$job = Start-WPFJob {
Window {
Grid -Rows "1*", "Auto" {
New-ListBox -Row 0 -Name LB -Items (Get-ChildItem ~ -dir)
Button "Send" -Row 1 -On_Click { Add-UIValue $Window $LB.SelectedItem }
}
} -SizeToContent "Width" -MinHeight 800
}
Every time you click, would add the selected item to the UI output (if you run that window without the job and click the button a couple of times, then close the window, you'll get two outputs).
Then you can do something like this in the host instead of Wait-Event:
do {
Update-WPFJob -Job $job -Command { Get-UIValue $Window -IgnoreChildControls } -OutVariable Output
Start-Sleep -Mil 300
} while (!$Output)

Maya MEL command to set focus to a particular tab in the Attribute Editor

How can I do this? I've looked through the Maya documentation and all I can see that's related are the commands refreshAE and updateAE, but they don't do the job I need.
Here is one way of doing it. This proc is tested in Maya 2009 and 2013.
// switch the tab by name string, note tab must be present
global proc switchAEtoTab(string $name ){
global string $gAETabLayoutName;
string $tabs[] = `tabLayout -q -tabLabelIndex $gAETabLayoutName`;
for ($i=0;$i<size($tabs);$i++){
if ($tabs[$i]==$name)
tabLayout -e -selectTabIndex ($i+1) $gAETabLayoutName;
}
}
Edit: updated script to contain the global name of the tab layout

PrintDialog.ShowDialog() not returning null

The ShowDialog method of the PrintDialog class in WPF is declared to return nullable bool (i.e. bool?), which is consistent with the documentation details:
"true if a user clicks Print; false if a user clicks Cancel;
or null if a user closes the dialog box without clicking Print or Cancel." from http://msdn.microsoft.com/en-us/library/system.windows.controls.printdialog.showdialog.aspx
However, in the code below, no matter how I close the dialog, (I tried the X and Alt-F4) I can never make it return null. Unless I press the Print button, it is always false. This is my test code:
PrintDialog pd = new PrintDialog();
bool? result;
result = pd.ShowDialog();
Do you get the same behaviour? Is the documentation wrong or am I misinterpreting it or not testing correctly? Perhaps this is OS related, I am running Windows 7 Enterprise.
Thank you.
L

Resources