Tk Source Code

Artifact [7e7dcbd5]
Login

Artifact 7e7dcbd508c46ef943fbc974f2917f1fc073d390:

Attachment "primary-selection-demo2a.tcl" to ticket [de156e9e] added by kjnash 2017-07-11 01:45:10.
#! /usr/bin/env wish

# Simple script with all the widgets that have -exportselection and can
# therefore write to the PRIMARY selection.

set script {
    package require Tk
    font configure TkCaptionFont -weight bold

    label .lab0 -text { } -font TkCaptionFont
    label .lab1 -text {text widget:}
    text  .text -width 25 -height 8 -bg white

    label .lab2 -text {entry widget:}
    entry .entry -width 20 -bg white

    label .lab3 -text {ttk::entry widget:}
    ttk::entry .ttkentry -width 20

    label .lab4 -text {listbox widget:}
    listbox .listbox -height 5

    label .lab5 -text "spinbox widget\n(modified entry widget):"
    spinbox .spinbox -from 0.00 -to 5.00 -increment 0.25 -format %5.2f -width 10 \
            -justify center -textvariable ::var

    label .lab6 -text "ttk::spinbox widget\n(modified ttk::entry widget):"
    ttk::spinbox .ttkspinbox -from 0.00 -to 5.00 -increment 0.25 -format %5.2f -width 10 \
            -justify center -textvariable ::var2

    pack .lab0 -pady {10 10}

    pack .lab1 -pady {10 5}
    pack .text

    pack .lab2 -pady {10 5}
    pack .entry

    pack .lab3 -pady {10 5}
    pack .ttkentry

    pack .lab4 -pady {10 5}
    pack .listbox

    pack .lab5 -pady {10 5}
    pack .spinbox

    pack .lab6 -pady {10 5}
    pack .ttkspinbox
    if {[interp issafe]} {
        .text insert end "This interpreter is safe.\n<<PasteSelection>>\
                to\nthis toplevel will fail.\n\nHowever, text selected\nhere\
                will be copied to\nthe PRIMARY selection."
    } else {
        .text insert end "This script can be used\nto test whether\
                its\nwidgets can write to the\nPRIMARY selection.\n\nMake\
                a selection\
                and then\ntry <<PasteSelection>>\nin any toplevel."
    }
    .entry insert end {hijklmn}
    .ttkentry insert end {opqrstu}
    .listbox insert end list1 list2 list3 list4 list5
    set ::var  0.75
    set ::var2 1.50
}


    # To run in the master interpreter.
    eval $script
    wm title . Master
    .lab0 configure -text {Master Interpreter}

    # To run in an unsafe slave interpreter.
    set int1 slave1
    interp create -- $int1
    $int1 eval $script
    $int1 eval {wm title . {Unsafe (Trusted) Slave}}
    $int1 eval {.lab0 configure -text {Unsafe (Trusted) Slave}}

    # To run in a safe slave interpreter.
    set int2 slave2
    ::safe::interpCreate $int2
    ::safe::loadTk $int2
    $int2 eval $script
    $int2 eval {.lab0 configure -text {Safe (Untrusted) Slave}}

    # To run in the master interpreter of a different thread.
    if {![catch {package require Thread}]} {
        set tid [thread::create {
            package require Thread
            thread::wait
        }]
        thread::send -async $tid $script
        thread::send -async $tid {wm title . Thread}
        thread::send -async $tid {.lab0 configure -text {Master In Another Thread}}
    }