TclApps Library Source Code
Check-in [77d4dd2a12]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:* askleo/askleo.tcl: Adjust code to the latest API changes on http://pda.leo.org and improve the UI.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 77d4dd2a126e6e13cfc52c7f2b003c6051a8dc8e
User & Date: rmax 2010-11-16 09:46:40.000
Context
2011-01-06
17:15
Add standalone support to askleo check-in: 21449c368f user: rmax tags: trunk
2010-11-16
09:46
* askleo/askleo.tcl: Adjust code to the latest API changes on http://pda.leo.org and improve the UI. check-in: 77d4dd2a12 user: rmax tags: trunk
2010-10-13
13:56
Fix multipart boundary detection check-in: 5800e8330a user: rmax tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to apps/tkchat/ChangeLog.





1
2
3
4
5
6
7





2010-09-17  Reinhard Max  <[email protected]>

	* tkchat.tcl (::tkchat::checkCommand):
	A single / at the start of a post is now rejected if it is not a
	known command. To send a literal slash at the beginning of a post,
	it has to be doubled.
	Improved detection and handling of the /tip command.
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
2010-11-16  Reinhard Max  <[email protected]>

	* askleo/askleo.tcl: Adjust code to the latest API changes on
	http://pda.leo.org and improve the UI.

2010-09-17  Reinhard Max  <[email protected]>

	* tkchat.tcl (::tkchat::checkCommand):
	A single / at the start of a post is now rejected if it is not a
	known command. To send a literal slash at the beginning of a post,
	it has to be doubled.
	Improved detection and handling of the /tip command.
Changes to apps/tkchat/askleo/askleo.tcl.
14
15
16
17
18
19
20

21
22
23
24
25


26
27
28
29
30
31
32
33
34
35
36
#	 Martin Scherbaum <[email protected]>
#
#############################################################

package require Tk
package require http
package require htmlparse


namespace eval ::dict.leo.org {

    namespace export query askLEO askLEOforSelection



    variable dialog .leo
    variable table ""
    variable last  ""
    variable Query ""
    variable td
    variable tdcounter 0
    variable leoURL http://pda.leo.org
}

proc ::dict.leo.org::parse {tag close options body} {
    variable td







>





>
>

|
|
|







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#	 Martin Scherbaum <[email protected]>
#
#############################################################

package require Tk
package require http
package require htmlparse
package require textutil

namespace eval ::dict.leo.org {

    namespace export query askLEO askLEOforSelection

    namespace import ::textutil::adjust

    variable dialog .leo
    variable table     ""
    variable Query     ""
    variable lastQuery ""
    variable td
    variable tdcounter 0
    variable leoURL http://pda.leo.org
}

proc ::dict.leo.org::parse {tag close options body} {
    variable td
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

84
85
86
87
88
89
90
91



92

93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109



110

111






112

113
114
115
116

117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
proc ::dict.leo.org::query {query} {
    variable table
    variable leoURL
    set enc [::http::config -urlencoding]
    ::http::config -urlencoding iso8859-15
    set query [::http::formatQuery search $query]
    ::http::config -urlencoding $enc
    set tok [::http::geturl $leoURL -query $query]
    foreach line [split [::http::data $tok] "\n"] {
	if {[string match "*ENGLISCH*DEUTSCH*" $line]} break
    }
    ::http::cleanup $tok
    set table ""
    ::htmlparse::parse -cmd ::dict.leo.org::parse $line
    return $table
}

proc ::dict.leo.org::max {a b} {expr {$a > $b ? $a : $b}}

proc ::dict.leo.org::askLEOforSelection {} {
    if {![catch {selection get} query]} {
	askLEO $query
    }

}

proc ::dict.leo.org::askLEO {{query {}}} {

    variable dialog
    variable textwidget
    variable last
    variable Query



    set query [string trim $query]

    if { $query ne "" } {
	set Query $query
    }
    if { $Query ne $last } {
        set w $textwidget
	$w configure -state normal
	$w delete 1.0 end
	$w configure -state disabled
	if {$Query != ""} {
	    $w configure -cursor watch
	    update
	    set table [dict.leo.org::query $Query]
	    set max 0
	    foreach c $table {set max [max $max [string length $c]]}
	    $w configure -state normal
	    if {$max} {
		set sep [string repeat = $max]



		set table [linsert $table 0 " English" " Deutsch" $sep $sep]

		foreach {c1 c2} $table {






		    $w insert end [format "%-*s  %-*s\n" $max $c1 $max $c2]

		}
	    } else {
		$w insert end {No matches}
	    }

	    $w configure -state disabled
	    if {![winfo ismapped $dialog]} {wm deiconify $dialog} else {raise $dialog}
	    $w configure -cursor ""
	}
    }
    set last $Query
}

proc ::dict.leo.org::init {} {
    variable dialog
    variable textwidget
    variable LEOlogo
    set NS {}
    if {[package vsatisfies [package provide Tk] 8.5]} { set NS ::ttk }

    catch {destroy $dialog}
    image create photo LEOlogo -data $LEOlogo
    
    toplevel $dialog -class AskLEO
    wm withdraw $dialog
    wm title $dialog "askLEO"
    wm protocol $dialog WM_DELETE_WINDOW [list wm withdraw $dialog]

    set f [${NS}::frame $dialog.main]
    ${NS}::frame  $f.top
    ${NS}::entry  $f.top.ent -background white -textvariable [namespace current]::Query

    ${NS}::button $f.top.but -text "ask LEO" -command [namespace code askLEO]

    grid $f.top.ent $f.top.but -sticky news
    grid columnconfigure $f.top 0 -weight 1

    ${NS}::frame $f.bot
    ${NS}::scrollbar $f.bot.vs -command [list $f.bot.text yview]
    ${NS}::scrollbar $f.bot.hs -orient horizontal -command [list $f.bot.text xview]
    set textwidget [text $f.bot.text -wrap no -font fixed -state disabled \
                        -yscrollcommand [list $f.bot.vs set] \
                        -xscrollcommand [list $f.bot.hs set]]
    grid $f.bot.text $f.bot.vs -sticky news
    grid $f.bot.hs   -         -sticky ew
    grid rowconfigure $f.bot 0 -weight 1
    grid columnconfigure $f.bot 0 -weight 1








|












|
|

>






|

>
>
>

>
|


|
|



<
|
|
|
|
<
|
<
|
>
>
>
|
>
|
>
>
>
>
>
>
|
>
|
<
<
|
>
|
|
|
<
<
<



















|
>








|







64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108

109
110
111
112

113

114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129


130
131
132
133
134



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
proc ::dict.leo.org::query {query} {
    variable table
    variable leoURL
    set enc [::http::config -urlencoding]
    ::http::config -urlencoding iso8859-15
    set query [::http::formatQuery search $query]
    ::http::config -urlencoding $enc
    set tok [::http::geturl $leoURL/?$query]
    foreach line [split [::http::data $tok] "\n"] {
	if {[string match "*ENGLISCH*DEUTSCH*" $line]} break
    }
    ::http::cleanup $tok
    set table ""
    ::htmlparse::parse -cmd ::dict.leo.org::parse $line
    return $table
}

proc ::dict.leo.org::max {a b} {expr {$a > $b ? $a : $b}}

proc ::dict.leo.org::askLEOforSelection {} {
    if {[catch {selection get} query]} {
        set query ""
    }
    askLEO $query
}

proc ::dict.leo.org::askLEO {{query {}}} {

    variable dialog
    variable textwidget
    variable lastQuery
    variable Query
    variable table

    set w $textwidget
    set query [string trim $query]

    if {$query ne ""} {
	set Query $query
    }
    if {$Query ne $lastQuery} {
        set lastQuery $Query
	$w configure -state normal
	$w delete 1.0 end
	$w configure -state disabled

        $w configure -cursor watch
        update
        set table [dict.leo.org::query $Query]
        set max 39

        $w configure -state normal

        set sep [string repeat = $max]
        if {![llength $table]} {
            $w insert end {No matches}
        } else {
            set table [linsert $table 0 " English" " Deutsch" $sep $sep]
        }
        foreach {c1 c2} $table {
            set a1 [split [adjust $c1 -length $max] "\n"]
            set a2 [split [adjust $c2 -length $max] "\n"]
            set indent ""
            foreach l1 $a1 l2 $a2 {
                set l1 $indent$l1
                set l2 $indent$l2
                $w insert end [format "%-*s  %-*s\n" $max $l1 $max $l2]
                set indent "  "
            }


        }
    }
    $w configure -state disabled
    if {![winfo ismapped $dialog]} {wm deiconify $dialog} else {raise $dialog}
    $w configure -cursor ""



}

proc ::dict.leo.org::init {} {
    variable dialog
    variable textwidget
    variable LEOlogo
    set NS {}
    if {[package vsatisfies [package provide Tk] 8.5]} { set NS ::ttk }

    catch {destroy $dialog}
    image create photo LEOlogo -data $LEOlogo
    
    toplevel $dialog -class AskLEO
    wm withdraw $dialog
    wm title $dialog "askLEO"
    wm protocol $dialog WM_DELETE_WINDOW [list wm withdraw $dialog]

    set f [${NS}::frame $dialog.main]
    ${NS}::frame  $f.top
    ${NS}::entry  $f.top.ent -background white -font {Helvetica 12} \
        -textvariable [namespace current]::Query
    ${NS}::button $f.top.but -text "ask LEO" -command [namespace code askLEO]

    grid $f.top.ent $f.top.but -sticky news
    grid columnconfigure $f.top 0 -weight 1

    ${NS}::frame $f.bot
    ${NS}::scrollbar $f.bot.vs -command [list $f.bot.text yview]
    ${NS}::scrollbar $f.bot.hs -orient horizontal -command [list $f.bot.text xview]
    set textwidget [text $f.bot.text -wrap no -font {{Dejavu Sans Mono} -14} -state disabled \
                        -yscrollcommand [list $f.bot.vs set] \
                        -xscrollcommand [list $f.bot.hs set]]
    grid $f.bot.text $f.bot.vs -sticky news
    grid $f.bot.hs   -         -sticky ew
    grid rowconfigure $f.bot 0 -weight 1
    grid columnconfigure $f.bot 0 -weight 1