Listbox in tk/tcl - listbox

Help me please to decide problem with listbox in TCL.
I created the next listbox:
listbox .lb1 -height 6 -width 10 -selectmode browse
.lb1 insert 0 "String 1" "String 2" "String 3" "String 4" "String 5" "String 6"
label .label1 -text [.lb1 get active]
button .butt1 -text "enter" -command {.label1 configure -text [.lb1 get active]}
pack .label1 .lb1 .butt1 -expand yes -fill both
How I can change automatically contents of label "label1" without use button "butt1" ?
I want the contents of "label1" will change immediately when I click on one of the list items.
Thanks!

When you select an item in the listbox, it sends the <<ListboxSelect>> to itself. You can bind to this to react to selection changes:
bind .lb1 <<ListboxSelect>> {.label1 configure -text [.lb1 get active]}
Note that you're also getting very close to the point where using a helper procedure is advised. Even for something simple like this, it makes things easier to write, test and debug.
proc SelectionHappened {listbox label} {
set activeItem [$listbox get active]
$label configure -text $activeItem
}
bind .lb1 <<ListboxSelect>> {SelectionHappened .lb1 .label1}

Related

Adding hyperlink to image in Indesign with Applescript

I'm trying to create an AppleScript that creates hyperlinks on every linked image in InDesign.
This is what I have come up with so far.
tell application "Adobe InDesign CC 2017"
activate
tell active document
set grphicBoxs to all graphics of layer activeLayer
set myLinks to {}
repeat with I in grphicBoxs
set iLink to item link of i
set end of myLinks to iLink
end repeat
repeat with theLinkRef in myLinks
set theLinkName to ((name of theLinkRef) as string)
display dialog "theLinkName: " & theLinkName
set myHyperLink to "www.myURL"
set myHyperLinkName to "myURL name"
try
set hyperLinkPreSet to make hyperlink URL destination with properties `{name:myHyperLinkName, destination URL:myHyperLink}`
on error
set hyperLinkPreSet to hyperlink URL destination myHyperLinkName
end try
try
set hyperLinkObject to make hyperlink page item source with properties `{name:myHyperLinkName, source page item:rectangle theLinkName, hidden:false}`
on error
set TheHS to hyperlink page item source myHyperLinkName
end try
display dialog "hyperLinkObject:" & hyperLinkObject
make new hyperlink with properties `{destination:myHyperLink, source:hyperLinkObject, visible:false}`
end repeat
end tell
end tell
The expected result is that the hyperlink preset that is created is applied to the chosen object. But I get this error message.
Invalid value for parameter 'source' of method 'make'. Expected page
item, but received nothing.
Is there anyone here who has successfully created hyperlinks on linked objects who can help me?
Problem solved
set activeLayer to "Layer 1"
set counter to 1
tell application "Adobe InDesign CC 2017"
activate
tell active document
set grphicBoxs to all graphics of layer activeLayer
set myLinks to {}
repeat with i in grphicBoxs
set iLink to item link of i
set end of myLinks to iLink
end repeat
repeat with theLinkRef in myLinks
set theLinkName to ((name of theLinkRef) as string)
set theLinkNameNoext to text 1 thru ((offset of "." in theLinkName) - 1) of theLinkName
set myHyperLink to "http://macscripter.net"
set myHyperLinkName to theLinkNameNoext & " " & counter
make hyperlink with properties {name:myHyperLinkName, source:make hyperlink page item source with properties {source page item:rectangle counter}, destination:make hyperlink URL destination with properties {destination URL:myHyperLink}}
set counter to counter + 1
end repeat
end tell
end tell

Sublime 3 key binding for "Views -> Groups -> Max Columns: 2"

In Sublime text editor, there no key binding for group by columns.
What will be the key binding JSON for "Views -> Groups -> Max Columns: 2"?
The easiest way to determine the command and arguments needed to bind a key to a menu item is to open the console with View > Show Console, then enter the command sublime.log_commands(True) and pick the menu item that you want to bind to and see what the console says.
In this case, the result is the following:
>>> sublime.log_commands(True)
command: set_max_columns {"columns": 2}
With that information, you can create a binding something like this (replace the key as appropriate):
{
"keys": ["ctrl+alt+t"],
"command": "set_max_columns",
"args": {"columns": 2}
},
Once you make the change, you'll see the menu item showing you the keyboard shortcut that you selected as a reminder.
The command logging will remain in effect until you run the same command again with False as a parameter or restart Sublime.

How to create an hyperlink in tcl tk?

Im a using Tcl-Tk 8.6.4 and I am a begginner, I would like to create hyperlinks in my texts.
I am looking for a procedure which could have the url of a website in argument, this url will be displayed in blue and underlined in my text. Of course, by clicking on the url, it will open the website.
I have found the following code, but I am not sure that it will do what I want.
proc hyperlink { name args } {
if { "Underline-Font" ni [ font names ] } {
font create Underline-Font {*}[ font actual TkDefaultFont ]
font configure Underline-Font -underline true -size 12
}
if { [ dict exists $args -command ] } {
set command [ dict get $args -command ]
dict unset args -command
}
label $name {*}$args -foreground blue -font Underline-Font
if { [ info exists command ] } {
bind $name <Button-1> $command
}
return $name
}
Anyone can help me?
Update 2
The thing I want is to display hyperlinks in the text of my window like that:
Further informations are given following those links:
https://ccrma.stanford.edu/~jos/NumericalInt/Lumped_vs_Distributed_Systems.html
https://ccrma.stanford.edu/~jos/NumericalInt/NumericalInt_4up.pdf
With the first code shown I am able to display that:
The codes used are:
in a procedure to read files I have tags like HTML tags such as
"<hypLink>" {
gets $infile inln
hyperlink .hl${counter} -command [list eval exec [auto_execok start] "$inln"] -text "$inln"
pack .hl${counter}
incr counter
}
in my file I write
Semi-conductors:
<hypLink>
https://en.wikipedia.org/wiki/Semiconductor
<hypLink>
http://electronics.howstuffworks.com/diode.htm
What can I do to have what I want?
Note The first update have been delated for copyright protection
You can use the proc you found. If you have:
hyperlink .hl -command [list puts "clicked"] -text "Click Me"
pack .hl
in your code and click on the 'hyperlink', you will get the text clicked to stdout.
If you want to open the default browser and go to the url specified by the hyperlink, you would have to change the code to:
hyperlink .hl -command [list eval exec [auto_execok start] "http://www.example.com"] -text "Click Me"
pack .hl
You can also play around with the proc a bit, maybe changing the font size (from -size 12) or change the font itself.
Post edit:
You can add the 'hyperlink' to your code by adding the below to the switch in the dispFile proc:
"<hypLink>" {
gets $infile inln
.fr.txt insert end "$inln" "link lk$lkcount"
.fr.txt insert end "\n" Normal
.fr.txt tag bind lk$lkcount <1> [list eval exec [auto_execok start] "$inln"]
incr lkcount
}
This should create text similar to the text which open files, but instead of opening files will open the link in the default browser.

Setting returned text to open an app in applescript

I have a apple script program that I am programming and I want the text the user sends to open an application, But I keep getting error messages saying "Can't get application {"name_of_app"} of <>. The code I very simple and I cant figure out the problem
set deReturnedItems to (display dialog "How many spam messages?" with icon stop default answer "" buttons {"Quit", "OK"} default button 2)
set xpp to text returned of deReturnedItems
set theReturnedItems to (display dialog "How many spam messages?" with icon stop default answer "" buttons {"Quit", "OK"} default button 2)
set amt to the text returned of theReturnedItems
set daReturnedItems to (display dialog "Last thing, what should the spam message say?" default answer "" buttons {"Quit", "OK"} default button 2)
set msg to the text returned of daReturnedItems
repeat [amt] times
tell application [xpp]
activate
tell application "System Events"
keystroke [msg]
keystroke return
end tell
end tell
end repeat
Get rid of those square brackets. Don't use them for variables. Use underscores before and after if you must, like:
repeat _amt_ times
…
end
Also, you need to check to make sure your variable is an integer before you use it in the repeat block.
Incidentally, when you set a variable and then include it in brackets, that's applescript syntax for set the string to a list. For example:
set [x, y, z] to "123"
return x
-- returns "1", and y is set to "2", and z is set to "3"

.NET Multiline Textbox Make Shift+Enter working instead of Enter key

I have a Windows Form Multiline Textbox.
I want to use Shift+Enter Instead of using Enter key to make a new line in textbox, and the traditional Enter key will be used to focus on the next control.
I mean Shift+Enter will work exactly like Enter key on normal multiline textbox (Regard to textbox maxlength --> So you cant enter newline, or current selected text will be delete when you insert newline,...)
I've tried to override OnKeyDown, to insert newline on Shift+Enter, but it doesn't work as I expected.
you'll need to override OnKeyDown and check for enter key using the KeyDownEvent's KeyCode property.
If enter was pressed and the keydownevent's modifiers property does not equal Keys.Shift you'll need to suppress the key press. Here's the documentation on how to do that:
http://msdn.microsoft.com/en-us/library/system.windows.forms.keyeventargs.suppresskeypress(v=vs.110).aspx
If shift+enter was pressed you'll need to insert Environment.NewLine at the cursor position, then move the cursor after the inserted Environment.NewLine. Here's how to do that:
How to paste text in textbox current cursor?
Here is my implementation in VB .NET.
Regard to Maxlength of the textbox and current selected text
Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs)
If (Me.Multiline AndAlso e.KeyData = (Keys.Shift Or Keys.Enter)) Then
Dim intRemainCharCount As Integer = Me.MaxLength - Me.Text.Length + Me.SelectedText.Length
'' Check if have enough space to place NewLine
If (Environment.NewLine.Length > intRemainCharCount) Then
MyBase.OnKeyDown(e)
Return
End If
Dim intPos = Me.SelectionStart
Me.Paste(Environment.NewLine)
'' Reset selection start (Reset cusor position)
Me.SelectionStart = intPos + Environment.NewLine.Length
e.Handled = True
e.SuppressKeyPress = True
Return
End If
MyBase.OnKeyDown(e)
End Sub
Change the property for Accept Return for the Multiline doesn't even require coding anything, unless you have an event listening to the KeyDown, in which case you can put a condition to check if the Textbox is focussed.

Resources