Tcl Tk hide Objects when user press Radiobuttons - radio-button

I cant find anything about Events in Gui-Programming in TK. If a user click on the Radio Button "automatic", the other RadioButtons should be invisible.
here is the code:
set base .example1;
toplevel $base
wm geometry $base 1920x1080
set frame_RadioBtnAuto [labelframe $base.frame_RadioBtnAuto \
-text Search \
-font {Calibri -12 bold} ];
place $frame_RadioBtnAuto -x 250 -y 135;
set rbl [radiobutton $frame_RadioBtnAuto.rbl \
-text "Automatic"\
-variable "[namespace current]::optionVariable" -value one ];
#Standardwahl beim start
$frame_RadioBtnAuto.rbl select
pack $rbl -side left -anchor nw;
set rb2 [radiobutton $frame_RadioBtnAuto.rb2 \
-text "UserDef"\
-variable "[namespace current]::optionVariable" -value two ];
pack $rb2 -side top -anchor nw;
set frame_RadioBtnUserW1 [labelframe $base.frame_RadioBtnUserACC \
-text Window\ 1\
-font {Calibri -12 bold} ];
place $frame_RadioBtnUserACC -x 250 -y 170;
set rba1 [radiobutton $frame_RadioBtnUserW1.rba1 \
-text "Test1"\
-variable "[namespace current]::optionVariable1" -value three ];
pack $rba1 -side top -anchor nw;
set rba2 [radiobutton $frame_RadioBtnUserW1.rba2 \
-text "Test2"\
-variable "[namespace current]::optionVariable1" -value four ];
pack $rba2 -side top -anchor nw;

Making the UI respond to a radiobutton change is fairly easy. You can either add a script via the radiobutton's -command option or you can set a write trace on the variable so that changing the variable triggers the UI change. I think you will find the latter is more reliable in anything like a complex UI:
trace add variable [namespace current]::optionVariable write optionVariableWritten
proc optionVariableWritten args {
variable optionVariable
if {$optionVariable eq "one"} {
# Conceal the UI here
} else {
# Reveal the UI here
}
}
You'll need to think carefully about exactly how to hide and show the UI; sometimes it gives a better (i.e., less surprising) experience to just disable the complex UI instead of hiding it entirely.

Related

Adding a variable to applescript within obj-c

Not sure if this one is possible in objective-c without having the script as a file and running it that way.
NSAppleScript *appleScriptGetHH = [[NSAppleScript alloc] initWithSource:#\
"tell application \"System Events\"\n \
tell process \"Grabee\"\n \
with timeout of 0 seconds\n \
get value of attribute \"AXValue\" of text area 1 of scroll area 1 of window \"Demo Window 1" \n \
end timeout \n \
end tell \n \
end tell"];
This works perfectly, but what I would like to do is replace "Demo Window 1" with a string (as it will be changed dynamically in the program)
When I use something like this
NSString *windowName = #"Green Window4";
And then replace this line:
get value of attribute \"AXValue\" of text area 1 of scroll area 1 of window \"Demo Window 1" \n \
With:
get value of attribute \"AXValue\" of text area 1 of scroll area 1 of window \"%#" \n \
And
end tell", windowName];
I receive an error that there are too many arguments, is there a way to do this without having the script separate?
Build the string like this;
NSAppleScript *appleScriptGetHH = [[NSAppleScript alloc] initWithSource:
[[NSString alloc] initWithFormat:#\
"tell application \"System Events\"\n \
tell process \"Grabee\"\n \
with timeout of 0 seconds\n \
get value of attribute \"AXValue\" of text area 1 of scroll area 1 of window \"%#" \n \
end timeout \n \
end tell \n \
end tell", windowName]
];
or build the string as a separate step for a bit more readability.

Take a result set (eg. listofcomputers.txt) and run a copy-item command on every item of result set

Hi all: This is what I'm trying to do....
Take a result set (eg. listoffailedcomputers.txt) and run a copy command on every item inside the result set.
The logic is to run a copy command on all the computers in that failedlistofcomputers.txt so that the end result will have that folder copied down locally on all computers on that list.
I can do this by using a remote console on all those computers but that would not be efficient.
Thank You.
Here is the code that I wrote so far.......
$failedcomputers = gc c:\listoffailedcomputers.txt
foreach ($failedcomputer in $failedcomputers)
{
$failedcomputer | copy-item \\server\patch\*.* -destination c:\patch\
}
And this is the error I'm getting......
Copy-Item : The input object cannot be bound to any parameters for the command
either because the command does not take pipeline input or the input and its
properties do not match any of the parameters that take pipeline input.
At copypatchtofailedcomputers.ps
+ $failedcomputer | copy-item <<<< \\server\patch\ -destination c:\patch\
+ CategoryInfo : InvalidArgument: (mycomputername:PSObject) [Copy-
Item], ParameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Command
s.CopyItemCommand
If I remove the pipe between the $failedcomputer variable and the copy-item command on my statement, I'll get a unexpected token error.
You can't just pipe a computername into any cmdlet and expect it to understand how to use it. Copy-Item doesn't even include a -ComputerName parameter. You could try two approaches
You could remote execute copy-item on each computer, like this:
$failedcomputers = gc c:\listoffailedcomputers.txt
foreach ($failedcomputer in $failedcomputers)
{
Invoke-Command -ComputerName $failedcomputer -ScriptBlock { copy-item \\server\patch\*.* -destination c:\patch\ }
}
Or, if you have file access to all remote computers from your computer, you could try to copy directly from one network share to another(the destination computer), like this:
$failedcomputers = gc c:\listoffailedcomputers.txt
foreach ($failedcomputer in $failedcomputers)
{
copy-item \\server\patch\*.* -destination "\\$failedcomputer\c$\patch\"
}
Another possibility:
$failedcomputers = gc c:\listoffailedcomputers.txt
$CmdParams =
#{
ClassName = 'Win32_Process'
MethodName = 'Create'
Arguments = #{ CommandLine = 'copy \\server\patch\*.* c:\patch\' }
}
Invoke-CimMethod #CmdParams -ComputerName $failedcomputers
That should multi-thread it, without the overhead of spinning up a bunch of remote PS instances just to do a file copy.
If you look at the Get-Help Copy-Item -full in ISE it tells you what it can accept on the pipeline. You can pipe a string that contains a path to Copy-ItemProperty. You are actually piping a hostname in this instance, which is why you are getting that error.
Try this:
copy-item \\server\patch\*.* -destination \\$failedcomputer\C$\patch

Linux enscript -- footer doesn't work (final purpose is to add pager number at footer for PDF)

Does anybody know how to add page number at footer for PDF? Followed is an example to show how to add page number at header by using enscript, ps2pdf pdftk. It works.
#!/bin/bash
input="$1"
output="${1%.pdf}-header.pdf"
pagenum=$(pdftk "$input" dump_data | grep "NumberOfPages" | cut -d":" -f2)
enscript -L1 --header='|Page $% of $=|' --output - < <(for i in $(seq "$pagenum"); do echo; done) | ps2pdf - | pdftk "$input" multistamp - output $output
According to enscript's manual, changing --header to --footer will work for footer. But in fact, no matter how I set the option for --footer, there is no footer at all. What's the matter? Does --footer work for enscript?
Someone posted a good example of a working .hdr file on askubuntu along with alternative ways to invoke the new header file.
https://askubuntu.com/questions/544606/printing-footers-using-enscript
% -- code follows this line --
%Format: fmodstr $D{%a %b %d %H:%M:%S %Y}
%Format: pagenumstr $V$%
%HeaderHeight: 38
%FooterHeight: 15
/do_header { % print default simple header
% Footer
gsave
d_footer_x d_footer_y HFpt_h 3 div add translate
HF setfont
user_footer_p {
d_footer_x d_footer_y moveto user_footer_left_str show
d_footer_w user_footer_center_str stringwidth pop sub 2 div
0 moveto user_footer_center_str show
d_footer_x d_footer_w add user_footer_right_str stringwidth pop sub
d_footer_y moveto user_footer_right_str show
} if
grestore
% Header
gsave
d_header_x d_header_y HFpt_h 3 div add translate
HF setfont
user_header_p {
5 0 moveto user_header_left_str show
d_header_w user_header_center_str stringwidth pop sub 2 div
0 moveto user_header_center_str show
d_header_w user_header_right_str stringwidth pop sub 5 sub
0 moveto user_header_right_str show
} {
5 0 moveto fname show
45 0 rmoveto fmodstr show
45 0 rmoveto pagenumstr show
} ifelse
grestore
} def
To get this to work, I modified one of the existing header files (simple.hdr) and then passed the parameter --header-files=name-of-new file on the command line. then remove the --header option in teh command line.

bash script: apache processlist for specific user where C = 0

I'm writing a bash script and need to retrieve the process list from apache for a specific user where the C value (processor utilization) is zero. I then want to kill just those processes. my script currently looks like this:
process_user=myuser
max_instances=10
poll_interval=60
while true; do
count=$(ps -u $process_user | wc -l)
echo "count: $count"
if [[ $count > $max_instances ]]; then
killall "$process_user"
echo "Found $count $process_user processes. Killed."
fi
sleep "$poll_interval"
done
The above works fine for identifying the processes for a specific user and killing them. But I don't know how to further limit by whether processor utilization is 0.
Here's a solution:
process_user=myuser
max_instances=10
pool_interval=60
while sleep $pool_interval;do
ps -o pid,c -u $process_user --no-headers \
| awk ' \
$2 > 0{top=top " " $1} \
{count++} \
END { \
if(count > '$max_instances' && top){ \
system("kill " top); \
print "killed: " top \
} \
}'
done
Some explanations:
ps -o pid,c -u $user --no-headers
Show pid and processor utilization (c) of processes owned by $user. Skip the header (PID C)
$2 > 0 - this {} block will be executed only for lines where the second field (processor utilization) is greated then 0.
{ top = top ' ' $1 } append pid (first field - $1) to variable top separating with space
{count++} count all the lines = user processes
END { this block will be executed after all the lines were processes

How to prompt for target-specific Makefile variable if undefined?

This is similar to another issue, but I only want make to prompt for a value if I'm running a specific target and a mandatory variable has not been specified.
The current code:
install-crontab: PASSWORD ?= "$(shell read -p "Password: "; echo "$$REPLY")"
install-crontab: $(SCRIPT_PATH)
#echo "#midnight \"$(SCRIPT_PATH)\" [...] \"$(PASSWORD)\""
This just results in the following output and no prompt:
Password: read: 1: arg count
#midnight [...] ""
The important point here is that I have to ask only when running this target, and only if the variable has not been defined. I can't use a configure script, because obviously I shouldn't store passwords in a config script, and because this target is not part of the standard installation procedure.
Turns out the problem was that Makefiles don't use Dash / Bash-style quotation, and that Dash's read built-in needs a variable name, unlike Bash. Resulting code:
install-crontab-delicious: $(DELICIOUS_TARGET_PATH)
#while [ -z "$$DELICIOUS_USER" ]; do \
read -r -p "Delicious user name: " DELICIOUS_USER;\
done && \
while [ -z "$$DELICIOUS_PASSWORD" ]; do \
read -r -p "Delicious password: " DELICIOUS_PASSWORD; \
done && \
while [ -z "$$DELICIOUS_PATH" ]; do \
read -r -p "Delicious backup path: " DELICIOUS_PATH; \
done && \
( \
CRONTAB_NOHEADER=Y crontab -l || true; \
printf '%s' \
'#midnight ' \
'"$(DELICIOUS_TARGET_PATH)" ' \
"\"$$DELICIOUS_USER\" " \
"\"$$DELICIOUS_PASSWORD\" " \
"\"$$DELICIOUS_PATH\""; \
printf '\n') | crontab -
Result:
$ crontab -r; make install-crontab-delicious && crontab -l
Delicious user name: a\b c\d
Delicious password: e f g
Delicious backup path: h\ i
no crontab for <user>
#midnight "/usr/local/bin/export_Delicious" "a\b c\d" "e f g" "h\ i"
$ DELICIOUS_PASSWORD=foo make install-crontab-delicious && crontab -l
Delicious user name: bar
Delicious backup path: baz
#midnight "/usr/local/bin/export_Delicious" "a\b c\d" "e f g" "h\ i"
#midnight "/usr/local/bin/export_Delicious" "bar" "foo" "baz"
This code:
treats all input characters as literals, so it works with spaces and backslashes,
avoids problems if the user presses Enter without writing anything,
uses environment variables if they exist, and
works whether crontab is empty or not.
l0b0's answer helped me with a similar problem where I wanted to exit if the user doesn't input 'y'. I ended up doing this:
#while [ -z "$$CONTINUE" ]; do \
read -r -p "Type anything but Y or y to exit. [y/N] " CONTINUE; \
done ; \
if [ ! $$CONTINUE == "y" ]; then \
if [ ! $$CONTINUE == "Y" ]; then \
echo "Exiting." ; exit 1 ; \
fi \
fi
I hope that helps someone. It's hard to find more info about using user input for an if/else in a makefile.