Version 204 of Ask, and it shall be given # 5

Updated 2007-05-04 12:31:45 by gold

This is the latest version of the Ask, and it shall be given pages. Please post your questions here.

For a list of all the Ask and it shall be given pages, see: Ask, and it shall be given -Index-.


Welcome to Ask, and it shall be given # 5

  • Starting on: 2 sept 2006
  • Ending on:

When asking your question, please put the date along with your name.

Once your question has been answered, please leave your question (and the answer of course :-)) on this page but copy it to the appropriate page on the Wiki so that all questions will be regrouped by subject-matter. If you cannot find a page, please create a new one.


gold May4 2007, many thanks !!!!!!,

   a. My iching generator apparently has a bad character

that locks up the saving page system. http://wiki.tcl.tk/17855 Can someone filter or otherwise clean the page????? I've tried about three hours and can seem to make the page save. Also, it would be nice to have line numbering on the edit window (and showing which line bombed 4May2007 )

  if that is a key to error checking.
  b.  Can two screenshots be loaded up in mini (for the iching)? tclhttp://mini.net/files/.4May2007 

I've got them stored on a free image service. Not sure how to get the free service linked correctly (which is expecting a " HTG .... real html" page). http://img175.imageshack.us/img175/5109/ichinggenerator5ab5.th.jpg [<a href="http://img175.imageshack.us/my.php?image=ichinggenerator5ab5.jpg " target="_blank"><img src="http://img175.imageshack.us/img175/5109/ichinggenerator5ab5.th.jpg " border="0" alt="Free Image Hosting at www.ImageShack.us" /></a>

<a href="]http://img144.imageshack.us/my.php?image=piechartchartxxxxed0.jpg " target="_blank"><img src="http://img144.imageshack.us/img144/2320/piechartchartxxxxed0.th.jpg " border="0" alt="Free Image Hosting at www.ImageShack.us" /></a>

 c. It'd be nice to have a   filter (for wiki) in http://wiki.tcl.tk/15280

(to filter out junk characters). If somebody has some tips for the convert procedure (I wrote) maybe a clean up line could be installed. 4May2007


Robert Abitbol October 27 2006

Nowadays all editors have a search function. But going one by one through records that match a criteria is a real drag.

Rapid File, the excellent DOS database manager had a function called Select Matching Records. You'd enter a criteria for a field: ex: Field: Country. Criteria (word to match): France and the database would select all the records with the word France in the field Country and it would put those records on the screen. This was a very useful function.

Now I'd like to do this on an editor: since an editor has no fields, the program would simply ask for the criteria then it would show on a screen all the lines containing the criteria without deleting them from the file. Ex: it would show all the lines where the word France appears.

Can anyone tell me what the algorithm or the code should be: asking the computer to show lines containing a specific word on a separate screen.

Thanks to all! And also many thanks for your excellent answers so far. They were very very helpful.

MG offers this (untested) solution

 set file "/path/to/my/file.txt"
 set pattern "*find this text*"
 pack [text .t]
 set fid [open $file r]
 while { [gets $fid line] >0 && ![eof $fid] } {
  if { [string match $pattern $line] } {
       .t insert end "$line\n"
     }
 }
 close $fid

Robert Abitbol This sounds just about right. A Do while function... Again, Mike, thanks so much for your great help and for another excellent answer. I really appreciate.


Note to RA - in the old days editors with "fold" capability allowed one to do something similar to what you are describing. I first encountered this functionality on MVS's ISPF. I could say "hide all the lines in this file" and the lines were replaced with a single dashed line, representing the entire file. Then I could provide a search term and the editor would represent the file as having dashed lines with the lines containing the matches being displayed.


(Josh) Thrilled the wiki is back! Pretty hard to live without it. Thanks JC and Colin MC for the fine work. Strange concept above. Strange but cool! I find older programmers come up with weird stuff sometimes. I tried it on an editor and it works just fine. I'd like to push the concept a bit further however but I can't seem to be doing it just right. I'd like the program to do a sort of multiple search done sequentially. I'd enter many search criteria one per line and the program will print them on the screen one by one: Example:

  • France
  • Sweden
  • Netherlands
  • Australia === (marks the end of the database query)

The code will look for France in the text and will come up with the following line:

  • Matching France
  • Paris is the capital of France

---

  • Matching Sweden
  • Sweden is not Norway

---

  • Matching the Netherlands
  • Dutch is spoken in the Netherlands

---

  • Australia
  • Colin does not live in Australia; rather in New-Zealand

Any help anyone? Thanks.


ABU 13-mar-2007 Using not-registered COM objects

I need to deliver my tcl-app; it includes some special COM objects driven by tcom. Of course, before using my app, COMponents should be registred on the new PC, and this is the first step towards the DLL-Hell ...

I've read an interesting article Simplify App Deployment with ClickOnce and Registration-Free COM [L1 ] and made some experiments with Tcl ... it works !! (no need to recompile anything or change your tcl-app) The bad news is that this solution forces you to add a .manifest to the Tcl Interpreter (wish.exe ?) and this is not in general a good idea.

I think (I'm not an Internal-Windows programmer) this should be a job for tcom or a similar package. I wish tcom were able to load COM-objects just by reading some kind of manifest files ....

Do you think is it possible, or can you suggest an alternative ?


Barry 9 March 2007: Hi, I'm getting stuck binding <Return> to several entry widgets so that action will occur with the widget that is altered.

 set x 0
 .
 . 
 while{1} {
 if {z1 == z2} {
   entry .e$x -text $text

   bind .e$x <Return> {lset listitem [.e$x get]}

   incr x
   }

Problem is, if a 2nd match to the if is found the bind selects the last entry created, not the one containing the cursor

EMJ 13 March 2007 - You have put your bind command in braces, so nothing in it is substituted until the binding is fired - at which point x has it's highest value, so the last entry is used. You need the substitution to happen when the binding is defined, so you could do

 bind .e$x <Return> "lset listitem [.e$x get]"

but it is usually safer to make the bind command a proc whose arguments are the things that need substituting at definition time:

 proc entrtn {ent} {
   lset ::listitem [$ent get]
 }
 ...
 bind .e$x <Return> [list entrtn .e$x]

LES on Feb 26 2007: In my Tcl/Tk apps, whenever another Tk window pops up, like an error or open/save dialogues, after it is closed, the main window gets that "hey look at me" blinking in the task bar and the title bar becomes greyed out - what my Linux window manager marks as a window without focus. That doesn't seem to happen to other applications, like Tkcon. It really seems that I am supposed to do something to prevent that, but I have no idea what it could be.


MG Feb 26 2007 - I'm trying to use the ftp package from Tcllib for some automated FTP tasks, but I've run into a few problems. There doesn't seem to be any (obvious) way of checking a) whether a given path exists, or b) whether a path refers to a file or a directory. And it seems, from the quick digging I've done, that this is something lacking from the FTP specs, not from the Tcllib package. All I can see that would be some help is the results of ftp::NList - which seem to be server-specific, and not follow any specific format. Can anyone offer any help or suggestions? Thanks in advance, Mike


Feb 13th 2007 (KBH) I've read how to Capture a window into an image, and have used image's "-format window" option to save a screenshot of a canvas. However, is it possible to save just a section of a canvas? Ideally, I'd like to be able to limit the capture with a set of coordinates in the canvas's coordinate system. Is there a simple way to do that? - RS: Like this?

 set im1 [image create photo -data $canvas]
 set im2 [image create photo]
 $im2 copy $im1 -from $x0 $y0 $x1 $y1
 image delete $im1

Is it possible to start a TCL Interpreter which will keep running, read and interpret commands from a pipe and return all output via the pipe? I have already implemented something similar, where the tcl interpreter opens a server socket and processes received commands via eval, but someone asked me this stupid question about pipes, and i can't provide an answer. fh-feb 6


I was wondering if someone could take a look at my script and tell me what I could do to make it work and/or optimize it. Its the first thing I've ever written in tcl, and im not sure about how things should go in the debugging stage. tcl-dicebot is based on picoIRC 0.2 script written by RS. modified so that the gui aspects are removed.

It's meant to be a stand-alone IRC bot that waits for users to type messages starting with *d* (ex: 1d20) and then generate a random number based on that starting string (in the case of 1d20, a (1-20)random number once.)

I've had a lot of trouble getting the irc parts of the script to work, even when they arent modified... Can anyone else get it to connect to irc.sorcery.net 9000 and join #omen-heart? My attempts have failed. Nor can I get pico to do it. Any and all help is appreciated davou-jan 31,8:20pm


rahul 1/17/2007

hi everybody, I have problem in loops like, can i pause loop for every certain gaps. here is i am trying but noe successful example:

 set var 3
 for {set i 1} {$i < 12} {incr i} {
 set rvalue [expr int($i *1000.000)/1000.000]
 set r1 [expr int(($rvalue/$var) *100)/100]
 if { [string is integer $r1] } {
 tk_messageBox -message "pause"
 }
 tk_messageBox -message "here is i=$i"
 }

To get to some of the machines I work on, I have to login in through a gateway. Since my password on the gateway and target machine is the same, I have an expect script that accepts my password (with echoing turned off, of course), uses the password to login to the gateway, talks through ssh to the gateway to login on the target machine using the password a second time, then goes into interact so I can do what I need to on the target machine.

This works great, except that when I do an "ls -l" in a large directory or anything that puts out around 80 or more lines of text, my session goes into an infinite loop, listing the text over and over.

Is anyone else aware of interact sometimes losing its mind like this, is it something I'm doing, or does anyone know of a fix for this problem? Thanks in advance...

tpb 2006-10-19


LES Dec 10, 2006

I was wondering if it is possible for a Tcl/Tk application to generate false key events that would surely be detected by the system but not really sent/produced in the application. My idea is to frustrate key loggers.


TCOM experts?

On Win XP, I want to simulate a drag and drop, via code, to a given application via COM objects. This has to simulate dragging an object (an image file) to a running instance of the applicaton. As if a tif file were dragged on to a running copy of Photoshop, for example, or some other graphic app. Whatever Explorer is telling the application when the drag/drop is done to its live window--I want to tell it via a command line. I realize this will likely require me to build some sort of drop object, including the file name. Does anyone have any fragments of code that can point me in the right direction?

- Daniel B. 10/19/06


GWM (Sep 12 2006) I'm using Itcl and have several classes which inherit from a basic class. If I have an instance of the derived class then I can use $instance info inherit to find if it inherits from thebase class. I can also use itcl::find classes to find all classes; how do I find all classes which inherit from the baseclass (I want to exclude the itcl classes which dont inherit from the baseclass)?


September 9th, 2006 Eugene Chang: Please help me with the following: I am using Windows XP Service Pack 2 and I get an error when doing [file mtime $new $dir]. Does setting the mtime only work for files?

MG When I try and change the modification time for a directory, I get a "permission denied". Is that the problem you had? (It's [file mtime $file $time], btw - you have the new time and the file/dir args the wrong way around above.)

LV I see the same thing as MG:

 (lwv27) 12 % file mtime mytest 0
 could not set modification time for file "mytest": permission denied

(and when I click on that error, I get:

 could not set modification time for file "mytest": permission denied
    while executing
 "file mtime mytest 0"
    ("uplevel" body line 1)
    invoked from within
 "uplevel #0 {file mtime mytest 0}"

The following are some questions which were never answered on the original Ask page. I suspect there are more - I just don't have time to read through the thousands of lines to find them. But it does seem like it would be useful if the unanswered questions could be on one page, and once questions were answered, they might be moved to another page (with a link perhaps on the unanswered page pointing off to where to find the info.

I don't know - maybe something that wikignomes could do....


6-Nov-2002

MacOS X problems : testtcl crashes wish under macOS X 10.2.1

I'm not an expert,so I have done the following, can anybody check/answer to see what is wrong ?

1) I downloaded TCL/TK 8.4.1. 2) Unzip created 2 directories ~/tcl and ~/tk (renamed from original tcl841 and tk841 3) cd ~ 4) run succesfully "make -C tcl/macosx deploy", "make -C tk/macosx deploy" 5) typed "sudo make -C tcl/macosx install-deploy", "sudo make -C tk/macosx install-deploy"

now my question:

a) I found in System/Library there is already a tcl folder with subdirectories containg the string tcl. do i have to remove this or what ? Why are there ? I thought that standard Jaguar did NOT have tcl installed, so what is these stuff ?

b) How do i install man pages for tcl ? This is not documented (and if it is in man page I cnnot read it)

c) To check installation I want to run test. The documentation is not very clear and the info in tcl/test/README is not clear/consistent (e.g. it says to run make ../unix (!?), it also says to source all.tcl (but i think it means running wish and use that to source it and so on). Anyway, if I start wish, then from the menu I choose source and then select all.tcl I get a crash as described in log below.

Can anybody help ?

Regards Michele Zundo

===CRASH Log attached ===

Tests running in interp: /Applications/Utilities/Wish Shell.app/Contents/MacOS/Wish Shell Tests located in: /Users/mzundo/Development/tk/tests Tests running in: /Users/mzundo/Development/tcl/tests Temporary files stored in /Users/mzundo/Development/tcl/tests Test files sourced into current interpreter Running tests that match: * Skipping test files that match: l.*.test Only running test files that match: *.test Tests began at Wed Nov 06 12:04:36 CET 2002 bell.test Bell should ring now ... bgerror.test bind.test

==== bind-15.7 MatchPatterns procedure, ignoring type mismatches FAILED ==== Contents of test case:

    setup
    bind .b.f <Double-1> {set x 1}
    set x 0
    event gen .b.f <Button-1>
    event gen .b.f <Key-Shift_L>
    event gen .b.f <ButtonRelease-1>
    event gen .b.f <Button-1>
    event gen .b.f <ButtonRelease-1>
    set x

---- Result was: 0 ---- Result should have been (exact matching): 1 ==== bind-15.7 FAILED

==== bind-22.10 HandleEventGenerate FAILED ==== Contents of test case:

    setup
    bind .b.f <Key> {set x "%s %K"}
    set x {}
    event gen .b.f <Control-Key-1>
    set x

---- Result was: 4 a ---- Result should have been (exact matching): 4 1 ==== bind-22.10 FAILED

bitmap.test border.test button.test canvImg.test canvPs.test /usr/bin/wish: line 2: 737 Segmentation fault "/Applications/Utilities/Wish Shell.app/Contents/MacOS/Wish Shell" "$@"


JES I'm trying to use the -bgstipple option for a tag. It works fine with predefined bitmaps, but doesn't seem to work with ones I've created with "image create"... image create returns 'image1,' for example, and I use this after -bgstipple and then: Error in startup script: bitmap "image1" not defined

suggestions? Thanks in advance


2004/10/20 sheila

How will I invoke package require if the pkgIndex file is byte-compiled? Will I need to alter tclPkgUnknown to also check for pkgIndex.tbc files? Should I call package unknown to get the handler name rather than assuming that it is handled by tclPkgUnknown?

For example, package.tcl has in one spot

 foreach file [glob -directory $dir -join -nocomplain \
  • pkgIndex.tcl] {

Which I can change to include pkgIndex.tbc, as below

 (test) 89 % ls
 C:/home/test:
 pkgIndex.tbc   pkgIndex.tcl
 (test) 90 % glob -directory [pwd] -nocomplain pkgIndex.tcl pkgIndex.tbc
 C:/home/test/pkgIndex.tcl C:/home/test/pkgIndex.tbc

I could go through tclPkgUnknown to scrub for places where pkgIndex.tcl is assumed.


Oct 9th 2004 - MG Does anyone know of a way to stop the console coming up, when you wrap a Tcl application with Freewrap on MS Windows? I'm using freeWrap 5.6.1. Right now, I've just been adding console hide or after idle {console hide} into the end of the script (I can't recall which I settled on, in the end), but it's kind've a pain to have to that with every script you want to wrap. Is there a command-line option to freeWrap, or something you can change with a resource-hacking program, to stop it doing it? Thanks for your help


2004/10/08 - Felipe Voloch

I am using Tcl/Tk (tclkit actually) on a Sharp zaurus C 860 with its original ROM and the XQt environment. It works fine except that buttons and labels default to huge sizes. This can be fixed by adding -padx 0 -pady 0 (or some other small number) in the definition of the widget. But it can be a pain editing a big file to change all such occurrences. Any suggestion to a workaround?


2004/10/02 - Satya I noticed something strange in the combox provided by Iwidgets. I am using Iwidgets version 4.0.1. I tried the following piece of code %iwidgets::combobox .c -editable true .c % eval .c insert list end {a b c} % pack .c

If I click on the pop-up cursor, it pops up the list box. Let's say I decide not to select anything from the selection list. So I left click my mouse on the entry field, the list box goes away. But the problem is that I don't see the cursor in the entry field. The entry field becomes uneditable. I tried several things, and found out that I can get back the cursor in the entry field only when I select something in the list box or when I press the escape key when the list box is open. Did anyone else notice this problem in combobox? Any combobox option I am missing here?

Thanks Satya


2004/10/02 - HZe

I tried to translate some text using babelfish from Altavista. This is the code I use:

    package require http

    proc translate {text from to} {
        # ::http::config -proxyhost proxy -proxyport 80
        set url "http://babelfish.altavista.com/tr"
        set query [::http::formatQuery doit done intl 1 tt urltext trtext $text lp ${from}_${to}]
        set token [::http::geturl $url -query $query]
        regexp {<td bgcolor=white class=s><div style=padding:10px;>([^<]*)</div></td>} \
            [::http::data $token] dummy translation

        if {1} {
            set name out.html
            set fp [open $name w]
            puts $fp [::http::data $token]
            close $fp
            global tcl_platform
            if {$tcl_platform(platform) == "windows"} {
                exec cmd /c start $name &
            } else {
                exec mozilla file://[pwd]/$name &
            }
        }
        return $translation
    }

    puts [translate "foot" en zh]
    exit

It works fine for european languages, but translating en (english) to zh (chinese - simple) gives no correct results. I assume it is something with the encoding of the page, which is UTF-8, I think. On Windows for debugging, a browser is started and shows the wrong translation in the complete page. Just pressing Translate in the Browser again shows the correct results.

What has to be changed to make it work for chinese, too?


2004/09/30 - LES

I want to run wikit in my Web site, which is hosted in a server that runs OpenBSD 3.3 i386. The only build of Tclkit for OpenBSD I found is here: [L2 ]. But this one doesn't work. I need a static build. I can't build one myself because I don't have OpenBSD or even the required expertise to build Tclkit on my own. Can anyone donate a static build of Tclkit for OpenBSD? The fine gentlemen of Equi4 [L3 ], perhaps?


2004/09/27

I'm looking for a "usb-cam-mksnapshot" tcl-package for Linux. vfwtcl-package works fine, but it's only win32-stuff.

PB


2004/09/20 - Breadcrust

Lately I have been experimenting with my own Mac OS X style menubar at the top of the screen. The menubar is basicly just a canvas inside a toplevel. I am using "wm overrideredirect .menubar true" so that the window manager forgets its there. I have some questions on how i should do some certain things.

1. How can I keep the menubar above all windows (except for stuff like popup menus)?

2. How can I stop windows from being under the menubar?

3. What would be the best way to 'intercept' calls to toplevel about the window's menubar so that my menubar can handle it? I have trying doing something like this before by renaming the widget's procedure to something else and creating a new procedure for the widget that passes all details to the real (renamed) widget proc except the ones I want to take care of my self, but this can get a little ugly and it would be good if there was a better way of doing it I knew of.

4. How can I stop a desktop environment/window manager from taking care of iconic windows? (Is this more of a question I should be asking on wm forum or wiki?)

5. How can I take care iconic windows though my program?

I am also looking for ways to take charge of the menubars on gtk/gnome and qt/kde apps, but that is a question I think will ask on a on wikis or forums for those librarys. If you happen to know anything about this, dont hestitate to email me tho.


Florian BABOGUS sch 26. Juli The hlist widget accepts an additional parameter for arbitary data associated with an entry. Neither the tlist nor the list widget accept such a thing otherwise. Do I miss it or is it realy so that it's tought to be a convinience function not worth the efford implementing it.

I also wonder how to do something like a table-view of data in tk ( see xforms table for a good example ).


Mark Schonewille 27 June 2004: I found an extension called OSAItcl. As I understand it, this extension should allow for using Tcl as an OSA component in MacOS 9 or earlier (PPC only). It comes with a Read Me file written by someone called Vince. Vince says he used the PowerPC C++ OSA Component Sample by Matthias Neeracher. The extension is also accompanied by a shared library named shared Tcl.

There are no installation instructions. I put the extension into the extensions folder of the system folder, together with the shared library. It becomes available to applications such as the Script Editor and HyperCard as it should. Yet, if I try to run a small Tcl script, I get an error similar to "OSA component not found".

I have four questions. Does anyone have experience using this OSAItcl extension? How should I install it correctly? Is there a good alternative? Where do I find more information about using Tcl as an OSA component? As to the last question, I searched this WIKI for "OSA" but got no results.

I'd rather not use AppleScript to tell the Tcl environment to run a script. I want to run Tcl scripts from within the script editor or HyperCard directly.

Help to solve this problem is highly appreciated!


Peter Newman 5 June 2004: I'm wondering if -cursor @filespec has a bug in it. Using:-

 $mywidget configure -cursor built-in-cursor-name

works fine on my Windows 95 Activestate Tcl 8.4. But:-

 $mywidget configure -cursor "@[file attributes {c:/temp/cursors98/link.cur} -shortname]"

causes a complete system lock-up after a few seconds. Has anybody else used this form of -cursor successfully? Has anybody else experienced problems with it? Many thanks.


24may04 Dossy

A second question: has this wiki been getting hit with lots of spam URL vandalism lately? The AOLserver Wiki [L4 ] has been getting hit nearly daily -- I'm about to implement registered editors only (confirm identify before being allowed to Edit pages) in response to this annoyance. But, it's a step I would really rather avoid, if possible. Suggestions on how to alternatively handle the vandalism would be appreciated, too.


5/23/04 - Hope this is on topic! Anyone have experience with VTCL and the output from it? What I'm worried about is the "final output" - whether it is completely transparent? I'm reading an older manual, and the manual (on visual TCL) says that a "competitor to visual TCL is Tk" (as if the "pure" Tk is a different beast from the output from vtcl). Anyone know anything about this? Is the output from vtcl "just the tcl" (with, of course, the internal name conventions for the program)? Is is it a different extension that is difficult to understand later without using vtcl.

Also, any other "visual" tools that are recommended would be of great help. Thanks. d


Vince 2004/04/20, Has anyone tried building TclKit from the 8.5a2 cvs sources of Tcl, Tk?


25-03-2004 MSH I have written a TK script to enable my collegues to generate executables from tcl scripts using a starkit/starpack and I would like a solution to prevent copying our standard libraries (eg BWidgets) into every xxx.vfs/lib directory, I tried making a BWidget.kit as per Starkit - How To's which works fine but generates a VFS erro when it is included in the executable (source $starkit::topdir/BWidget.kit). Does anyone know how to include xxx.kit in yyy.kit without extracting it first to /tmp or similar.


3-4-04 I am trying to call Tk functions from C program, the simple program below does not compile:

#include <tcl.h> #include <tk.h> int main () { }

g++ test.C tk.h: No such file or directory

I am using a Mac, OS 10.3 and I installed tcl/tk using fink as well as using dmg image I downloaded from apple.com. However, it seems the compiler still cannot find tk.h (but it can find tcl.h). Thanks for the help.


CT - Oh one other very important question... is here How to get tcl to run only one instance of a script/application?


Hi, I have a question about the canvas postscript method, or rather about the postscript it produces. I tried several examples to export a canvas to postscript, including e.g. the first example on http://wiki.tcl.tk/8483 about different scalings of text and graphics, but also other stuff. If I load the resulting file into ghostview I only get a blank page. Also other programs (CorelDraw, Adobe PhotoShop) were not able to show/print the postscript. I am using Tcl/Tk 8.4 as downloaded from ActiveState on a Windows system. There is probably something very dumb, that I do wrong. Any ideas anyone ?

Thanks, Daniel



SZ bgerror didn't invoked in child threads (Tcl 8.4, Windows).

I needed a log of errors in threads reported back into main thread. The following script illustrates this:

 package require Thread

 set th [thread::create]

 proc send {script} {global th; thread::send $th $script}
 proc asend {script} {global th; thread::send -async $th $script}
 send [list set owner [thread::id]]
 puts "owner [thread::id]"
 send {
        proc bgerror {msg} {
                global owner
                puts "bgerror 'puts '$msg'' into $owner"
                after idle [list thread::send -async $owner [list puts "bgerror: $msg"]]
        }
 }
 # separate outputs by time.
 after 1000 asend asdasdasd
 after 2000 {asend {bgerror aaaaaa}}
 vwait forever
 # press CtrlC to exit

(after idle added in the last hope to make it work...)

I expect that I will get something along the lines of

 bgerror 'puts 'Invalid command name "asdasdasd"'' into 12345
 bgerror: Invalid command name "asdasdasd"
 bgerror 'puts 'aaaaaa'' into 12345
 bgerror: aaaaaa 

if bgerror invoked correctly.

Instead I get two different results - in tclsh I get report "Error from thread 54321\nInvalid command name "asdasdasd"..." and result from direct call of bgerror. In wish I get only result of direct call of bgerror.

Quick glance at Tcl sources of Tcl 8.4.4 and Thread 2.5 tells me that they try to call bgerror.

Also, I use ActiveTcl as a main distribution and had recompiled tcl and tk for thread support.



i need to access a tcl procedure from a c function. the tcl procedure is written in mod_dtcl(server parsed Tcl, running under Apache). to access tcl procedure i am firstly creating an interpreter using Tcl_CreateInterp() and then calling Tcl_Eval to evaluate a command . but it as giving invalid reference to Tcl_CreateInterp() & Tcl_Eval. can you give me a example how to access the tcl function.

thanks neo


JES I'm trying to use the -bgstipple option for a tag. It works fine with predefined bitmaps, but doesn't seem to work with ones I've created with "image create"... image create returns 'image1,' for example, and I use this after -bgstipple and then: Error in startup script: bitmap "image1" not defined

suggestions? Thanks in advance



hi, I am a new user working with cgi-tcl. Using this for setting up cookie and getting back. but having problem while retriving back. First of all, I a form on a windows NT server. This form is used for authentication purpose. if the user is authenticated, than only the scripts on another server which windows 98 is executed. this is done using cookies. When the user is authenticated, cookies are set. And the scripts on another machine is executed using these cookie values. The program work fine when cookies are transfered from Windows NT to windows NT machine. But the problem comes when they are transfered from Windows NT to Windows 98 machine. I am using cgi_import_cookie

also what i found was that, it does give an error for cgi import, but when i print this cookie value. in p statement.

I am doing something wrong.

The following questions have had some degree of answer provided.


GWM how can I embed a tk_chooseColor (dialog) in another window? In particular I want to extend the colour picker to define both colour and transparency by adding a slider to the choosecolor window. I might also want to extend even further to set a colour for one of the OpenGL material attributes (diffuse, ambient specular and emissive colours can all be different in OpenGL).

MG On Windows, a native colour picker is used. Probably the easiest way to do it is to use the pure-Tcl/Tk one used on other platforms, which seems to be in tcl/lib/tk8.4/clrpick.tcl for me. If you copy the code out of that, you can customize it as much as you need, embed it into other windows (or other windows into it, to add your extra controls) and do pretty much anything you need. Then call that instead of the real tk_chooseColor.


(DB) on Wednesday February 28th 2007: I have a simple, almost silly question. On the app I am working on, I need to insert the name of the file that is going to be saved as. Let me be more precise. The command is: Save as. In the File name rectangle, no file name appears at the moment. I'd like to put in this File name rectangle the name of the file I am on (the one that will be saved with another name). How do I go about it? Thanks!

RS Have a look at tk_getSaveFile. It is most simply called like this:

   set filename [tk_getSaveFile -initialfile default_filename]
   if {$filename ne ""} {
      #... save content to $filename
   } else {# user canceled the save selection}

(DB) Thanks (RS), week-end projecteer extraordinaire!


(DB) on Wednesday February 28th 2007: Yet another question. I'd like to code a function that would do the following: the user will select a range of lines with the right click of the mouse. He would do a block in other words. Afterwards, when he'll click on Sort, the selected lines will be sorted by alphabetical order or by numerical order. Any suggestions for coding such a function? Thanks again! RS Here's a sketch that I tested to work - make sure you understand how it works, what it does :^)

 proc tsort {w} {
   foreach {from to} [$w tag ranges sel] break
   if ![info exists from] return
   set lines [split [$w get $from $to] \n]
   $w delete $from $to
   $w insert "$from - 1c" [join [lsort -dic $lines] \n]
 }

(DB) Thanks again (RS)! I'll analyze your code line by line to make sure I understand it.


(DB) February 24th 2007 As soon as the user clicks on an hyperlink, I'd like the program to verify if the user has modified the page or not. If so, if the page has been modified, a box will appear and ask him to save or not to save. How do I go about it? How can I tell if the user has entered a character or not? Thanks in advance.

MG I think if you want something along these lines:

  set ans no
  if { [$textWidget edit modified] } {
       set ans [tk_messageBox -message "Save changes?" -type yesnocancel]
       if { $ans == "yes" } {
            #save
          }
     }
  if { $ans != "cancel" } {
       exit;
     }

(DB) This sounds pretty OK. Thanks so very much MG!


(DB) February 24th 2007 Yet a second question. Does Tcl have arrays like the C language? I am talking specifically of reading a database and keeping the appropriate data in arrays. Does/Can Tcl proceed this way also?

MG Tcl does have arrays, but they're a little different from C arrays. There are some pages on the wiki already explaining the differences, and how Tcl arrays work - the array page is probably the best place to start out. But, in their most basic form:

 % set myArr(foo) bar
 bar
 % set myArr(baz) boing
 boing
 % puts "foo is $myArr(foo) and baz is $myArr(baz)"
 foo is bar and baz is boing
 % parray myArr
 myArr(baz) = boing
 myArr(foo) = bar

At least some of the Tcl extensions for working with databases provide mechanisms already for retrieving results from the db and putting them straight into a Tcl array, so it would be worth checking the docs for whichever you're using.

Tcl 8.5's dicts may be of some use to you, too. I've never used them myself, though, and am not entirely sure what differences/benefits/etc they provide over arrays, so they may not be :)

(DB) Well I'll try them both. Thanks again MG for the valuable information.

Lars H: Don't forget lists -- being indexed by an integer, they're the closest Tcl analogue of C vectors/arrays.

As for arrays vs. dicts, the main difference is that a dict is a value, but an array is a variable.

  • You can put dicts as elements in a list, array, dict, etc. or pass them by value to a command. In order to do something similar with an array, you effectively need to convert it to a dict first (using array get).
  • You can put traces on elements of an array, but not on the elements of a dict.
  • Elements of an array are valid in most places where a command wants a variable (e.g. scan and regexp). There is no corresponding syntax for an element of a dict, so you'll need to use the dict command explicitly for accessing these.

LV Check to see if the database of interest provides any natural relationship for you. If not, perhaps discuss with those supporting the tcl binding for the database whether something like you are envisioning might be implemented - sort of tie for Tcl...


(DB) February 21st 2007 I am trying to code a function that would register where the user has left from when he clicked on a link so that he would go back to this particular part of the start page when he clicks Home. As for example: he clicks on a link called: My Sql located on the bottom of the page. He then edits the page and he goes back to the start page (the page he has left from, the page where the link was located). The bottom of the start page will be shown. How do I code such a function? Not easy! Thanks in advance for anything that would put me on track.

CJL needs to know what the browser in question is. Firefox exhibits the required behaviour if the 'back' button is used, and any other path back to a page returns the user to the top, which feels correct to me. But of course that has nothing to do with Tcl... If the browser in question is implemented on a Tk canvas, then keeping a record of URLs and last known values of yview (and maybe xview?) should be trivial.

(DB) There is no browser. It is a stand-alone editor that does hyperlinks on a local level. Not on the internet.

CJL : "It is a stand-alone editor..." written in pure Tcl/Tk? Without a more precise definition of it, guessing an answer is going to prove tricky.

MG Assuming you're using the Tk text widget, when the user clicks your hyperlink (which in this case would be a <1> binding on a text-widget tag), you need to have the proc include the coordinates of the character clicked. Then your proc which takes them back can jump to that point. For example...

 pack [text .t -width 40 -height 5 -yscrollcommand ".s set" -wrap word] -side left ; pack [scrollbar .s -command ".t yview"] -fill y -side right
 .t tag configure foo -foreground blue
 .t tag configure normal -elide 0
 .t tag bind foo <1> {doStuffWith .t [.t index current]}
 .t insert end "this is normal text\n\n\n\n\n\nn\n\nnormal text " normal
 .t insert end "hyperlink" [list normal foo]
 .t insert end " more normal text\n\n\n\n\n\nmore text" normal

 proc doStuffWith {w index} {
  $w tag configure normal -elide 1
  $w tag configure goback -foreground blue
  $w tag bind goback <1> [list goBackTo $w $index]
  $w insert end "This is temporary text displayed because you clicked at $index. When you're done reading this, " tmp
  $w insert end "go back." [list tmp goback]
 }
 proc goBackTo {w index} {
  eval \$w delete [$w tag ranges tmp]
  $w tag configure normal -elide 0
  $w mark set insert $index
  $w see $index
 }

The $widget see $index line is the one which scrolls the widget so you can see the place where they clicked the hyperlink, and the index to go to is passed all the way through the process, from where they first click to the end, where it returns to that spot.

If that's nothing like what you're doing, though, then more info would really be needed, as CJL says, before anyone can really offer more help.

(DB) This seems very OK. It's what I needed. I'll try it. Thanks so very much for your help, MG.


MPE February 3rd 2007.

I am tearing my hair out with a TCL problem I am experiencing. The application is a network client. Intermittently, the application locks up, runs at 99.9% CPU (top) and strace-ing the PID shows no output at all - not even a blocking system call. I believed for a while this might be to do with load over the network interface causing problems in the event loop, but recently this has been disproved as the issue occured with only a couple of people on the system. Previously, it had only shown up with high load and a large number of concurrent clients running.

I would be very grateful for some assistance in identifying the right place to look for a solution or workaround to this issue.

Mark

CJL responds, A socket closed by the other end will cause a client to 'see' a fileevent, which if not handled properly will lead to 100% cpu usage. Maybe that's it? Run this example (of how not to do it) in a 'wish', then do 'telnet localhost 12000', then disconnect. Proper handling of the situation is described on a page around here somewhere.

  proc readable { ch } {
    while { [gets $ch buffer] != -1 } {
        puts "Client said : $buffer"
    }
  }

  proc server { ch addr port } {
    puts "Connection from $addr:$port"

    fileevent $ch readable [list readable $ch]
  }

  socket -server server 12000

(MZ) January 29th 2007.

When using the edit on this wiki, I notice that I cannot retrieve back text I have deleted when I hit Undo. Each character of the old text appears one after the other, one at a time. Why so? Why can't I get the whole text back? Is there a bug?

Lars H: I presume you're accessing the wiki over the Web. Then you don't actually get the wiki involved in the editing until you click the "Save" button; everything up to that happens inside your web browser. Hence it is probably the web browser that only undoes one character at a time.


JM 1/20/2007

I just installed the libpgtcl1.5 in my linux PC, the folder contains three files:

  • libpgtcl1.5.so
  • pgtcl.tcl
  • pkgIndex.tcl

doing "package require Pgtcl" is not working, even that the auto_path variable includes the path to these files, I am a Tcl novice but I notice that the tcl files are basically empty, there is nothing but comments, and I was expecting to see some "package provide" stuff. could someone give me a hint?

MG The pkgIndex.tcl (check the case of the filename, btw - some packages in the past have been distributed with 'pkgindex' or 'PKGINDEX', which doesn't work) should contain a line somewhere along the lines of...

  package ifneeded Pgtcl 1.5 [list source [file join $dir pgtcl.tcl]]

or

  package ifneeded Pgtcl 1.5 [list load [file join $dir libpgtcl1.5[info sharedlibextension]]]

There should be (the equivilent of) a 'package provide Pgtcl 1.5' somewhere, but it could be done by the .so when it's loaded. One way to test if it's a problem with the package or with your auto_path is to do something like this...

  cd /path/to/pgtcl/package
  set dir [pwd]
  source pkgIndex.tcl
  package require Pgtcl

If it finds the package OK after doing that, your auto_path is most likely the problem. Otherwise, the package could be missing a file or something like that.

JM thanks, looks like a file is missing, I just tried writing the 2nd line suggested to the pkgIndex.tcl, then I got the following message:

 % package require Pgtcl
 couldn't load file "/usr/local/atcl/lib/pgtcl1.5/libpgtcl1.5.so": libpq.so.4: cannot open shared object file: No such file or directory

libpq.so.4 ?

LV That would be the name of the PostGres library. Sounds to me like a real mess - the binary is linked against some version of postgres and the creator just figured anyone who wanted the binary would already have the original database library.


naveen 12/1/2007

hi i had earlier asked some questions about a script that calculates runtime. the script which i wrote is pretty lengthy; moreover it has some flaws in it. i.e: if i start my run on a month end then i'll be in a fix to decide how much time has elapsed (if the run completes in next month beginning), as i'll have to consider many parameters like leap year,no of days in that month etc..

do you have any suggestions so that i can make my script to work round the clock without any problem!

i saw the material about date and time on http://mini.net/tcl/948 . but there is no such example which shall give the time difference.

i am trying to develop a script which can give the difference between 2 dates eg.

 Thu Jan 31 09:13:41 IST 2007 # the time i start my run
 Thu Feb 01 09:23:44 IST 2007 # the time my run finishes

now i need to get the difference in time in hours:mins:secs

i.e my output shall be

The total time taken for this run is x hours: y minutes:z seconds

please do help me with the same....

Answer

The command clock scan timestring returns the number of seconds since some fixed day. Example:

 % clock scan {Thu Jan 31 09:13:41 IST 2007}
 1170215021
 %

The command clock format seconds converts the number of seconds to a date. Example:

 % clock format 1170215021
 Wed Jan 31 04:43:41 W. Europe Standard Time 2007
 %

Btw January 31, 2007 is not on Thursday.

LV Check out [L5 ], which discusses calculating time between two dates.


DF asked the following question on other pages ([L6 ] and [L7 ])

Help

All I want to do is to launch a simple TCL program from C++ code. Is there a simple example or step by step instructions on how to do this? My second application is to pass data from an array into the TCL program. Any help would be appreciated. Thanks DF

LV Do you mean launching a program like execlp("abc.tcl", "arg1", "arg2", (char *)0);?

Invoking Tcl from C++

Hello Robert (directed towards [L8 ]), I really could do with some help in invoking a simple Tcl prog from C++. Is this possible? I have been through all the relevant web pages but there is not one page which simply describes how to do it withough out going into geek speak. Can you help? Thanks

RLH I know nothing about C/C++ at the moment sorry.

LV Would you mind explaining, in different words, specifically what it is that you are trying to do? Launching a simple Tcl program is done the same way that you start any program in C or C++. There is nothing unique about Tcl in this regard.

Generally one uses a C or C++ call such as fork and execlp, or system, to tell the operating system to start a program. Of course, perhaps on Windows there are other calls one has to make - you've not told us what operating system you are using yet.

If you are just wanting to exec a Tcl program, you won't be able to pass in an array - you can pass a fixed number of arguments (often a small number), OR, you could write a file containing the data and have your tcl program read and interpret the data in some fashion.

Why not take a step back and tell us what it is that you are wanting to accomplish after the program is written, and let us see if we can provide you pointers on how to write code to reach that goal?

GWM perhaps you want to add to your C/C++ program something like this which loads a Tcl interpreter into your program, then evaluates a script with Tcl in it.

  int cballoon (ClientData cd, Tcl_Interp *interp, int argc, char **argv)
  { // this routine is executed in response to a button...
        int i;
        fprintf(stderr,"Hoo this is C ok\n");
        for (i=0; i<argc; i++) fprintf(stderr," %d %s",i,argv[i]);
        fprintf(stderr,"\n");
        return TCL_OK;
  }
  int myAppInit(Tcl_Interp *interp)
  {
        int status = Tcl_Init(interp);
        int status = Tcl_Init(interp);
        if (status != TCL_OK) { return TCL_ERROR; }     /**/
        status =Tk_Init(interp);// add Tk options
        if (status != TCL_OK){  return TCL_ERROR;}
        Tcl_StaticPackage(interp, "Tk", Tk_Init, (Tcl_PackageInitProc *) NULL);
        Tcl_CreateCommand (interp, "balloon", (Tcl_CmdProc *)cballoon,  NULL, NULL);
        //Tcl_EvalFile(interp, "simple.tcl"); // if you want to load a script file.
        Tcl_Eval(interp, "button .inc -text \"from C\" -command \"balloon 2 76 ferret\"");
        Tcl_Eval(interp, "pack .inc -side left -expand 1");
        /* here we do any other initialisation, add new functions which will be called as & when needed....*/
        /* here we do any other initialisation, add new functions which will be called as & when needed....*/
        return TCL_OK;
  }
  int main(int argc, char ** argv)
  {
        Tk_Main(argc,argv,myAppInit); // Tcl_Main calls myAppinit when it is ready.
        return 1;
  }

Read the manual for details of linking C procs to script commands as in the proc cballoon above. Preferably use the Tcl_Obj versions as they are faster (but less obvious hence my use of char **argv form). As mentioned above, use fork or execlp to launch as a separate program (these functions are the same under Windows & Linux ??And Mac??).


naveen 9/1/2007 p.s i have removed the script. if anyone needs the same plz mail me @ [email protected]

hi i wrote a script for runtime calculation. it was working fine for other start time and endtime values. but i got this error when i executed it. [ plz see the timing below].could you please tell me how i can set it right? here the time is 09 hrs, but i guess my Tcl script is trying to read the same as octal. can i do some declaration so that it can be read as an integer?

 09:13:41 #start time
 09:23:44 #end time
 0

 Error: expected integer but got "09" (looks like invalid octal number)
        Use error_info for more info. (CMD-013)

runtime.txt has the following data

 Thu Jan 11 09:13:41 IST 2007
 Thu Jan 11 09:23:44 IST 2007

Answer

After splitting the time string, you got a string hr = 09. Leading zeroes are interpreted as octal numbers, not decimal numbers. Solution:

 % set hr
 09
 % set hr [string trimleft $hr 0]
 9
 %

Now, you can calculate with the decimal number 9. - RS Warning: string trimleft trims as much as it can:

 % string trimleft 09 0
 9
 % string trimleft 00 0

returns an empty string, which is bad to do calculations with. scan however returns a valid integer:

 % scan 09 %d
 9
 % scan 00 %d
 0

naveen 9/1/2007

hi to my previous question you had provided the following answer:

could you please explain the program in brief? i couldn't figure out few commands. i have commented on the same. i am extremely sorry for the inconvenience caused.

 proc cat file {
    set p [open $file r]
    set contents [read $p]
    close $p
    set contents
 }

 set doneList {}
 set max -

 foreach {word1 word2 word3 num} [cat data.txt] {
    if {[lsearch $doneList [list $word1 $word2 $word3 $num]] < 0} then {  ;# does this write strings that match to doneList ??
        lappend doneList [list $word1 $word2 $word3 $num]
        if {$max eq "-" || $num > $max} then {                            ;#why have we used $max == "-" here
            set max $num
        }
    }
 }

 puts "done:\n[join $doneList \n]"

 puts "maximum area is $max"

please explain the entire program in brief. Thanks for the Nth time for your support and help...

MG In the if/lsearch, it checks to see if the line from the file has appeared before. If the line hasn't appeared (ie, if the lsearch returns -1), the code adds the line into $donelist, then checks to see if the number is the highest so far.

The variable $max is set to "-" before the foreach starts. So, if $max is still set to "-", you know that you're running the loop for the first time (so whatever $num is, it's definately the highest number you've seen so far - because it's the only number you've seen so far).

Hope that helps.


Anton 8/1/2007

I have a Bluetooth USB adapter. How can I read data that is sent to PC through this adapter?

LV Shouldn't it be the same way you would read data sent to a PC through any means?


naveen k n 8/1/2007

Error: value '' for option '<range_value>' not of type 'float' (CMD-009)

could you please explain what i have to do to correct such errors?

Answer First reproduce the error, then input "puts $errorInfo". The variable shows the function call trace.


naveen k n 8/1/2007 hi, thanks for the Tcl code you came up with. i am a beginner in Tcl. ur site has been extremely resourceful. i have another request.

question:i need to source few Tcl files till a variable becomes zero:

eg: say a is my variable. i derive the variable a from another Tcl file

i need to do the following function

 if(a=0)
 {
 exit
 }
 else
 {
 source xyz/abc/reduce.tcl
 source def/ghi/time.tcl
 ..etc
 }

could u guys please help me out with the same. thanks a ton in advance..!!

Answer

 set a 1

 foreach file {
    one.tcl
    two.tcl
    three.tcl
 } {
    if {$a == 0} then exit
    source $file
    puts "a is $a"
 }

2006-01-06 gg - I looked on the wiki already and could not find an answer (also did some other research). I am working on a commercial piece of software which should be available as shareware and activateable using license keys (the shareware version would have a license key which expires on a certain date, the non-shareware version would have a license key which expires after a year or so).

The thing is, of course there is the danger of multiple users making use of the same license key - even when a license server based model is used, since files could be copied. So, the solution is: unique computer IDs.

Question: how can I, in a cross-platform compatible manner (i.e. pure-Tcl) or at least supporting *NIX and Windows, generate unique computer IDs which will not change (best would be if they cannot be manually changed, but I don't think that this would be an issue)?

Thanks!

Answer:

LV Tcl doesn't have a function like that built in. However, on Linux at least, there should be a command similar to the unix "hostid" command which supposedly returns something like this to you. Check for its source code and see if it might be possible to turn that into a Tcl extension.


naveen k n 5/1/2007 hi , i need a piece of Tcl code with the following functions:

1]it must read a file in which data is dumped eg:lets say a file /usr/temp/area_report.txt has the following data

 the area is 100
 the area is 100
 the area is 100
 the area is 60
 the area is 60
 the area is 60
 the area is 10

etc.

2]i need to read the data only once. ie i want to delete the repeated lines in the report so my new report shall be

 the area is 100
 the area is 60
 the area is 10

3]i need to extract the max value out of the report and set it to a variable

eg:

 set max_area = 100

it was easy fopr me to achieve the same in shell using sed & awk. but i need to do the same in Tcl. please do HELP me with the same. Thanks in advance!!!

Answer

 proc cat file {
    set p [open $file r]
    set contents [read $p]
    close $p
    set contents
 }

 set doneList {}
 set max -

 foreach {word1 word2 word3 num} [cat data.txt] {
    if {[lsearch $doneList [list $word1 $word2 $word3 $num]] < 0} then {
        lappend doneList [list $word1 $word2 $word3 $num]
        if {$max eq "-" || $num > $max} then {
            set max $num
        }
    }
 }

 puts "done:\n[join $doneList \n]"

 puts "maximum area is $max"

wdb 03 Jan 2007 On my Emacs, the speed bar can show me all Tcl procs made with proc and Tcl methods made with method, but neither self-defined xproc nor fully qualified ::snit::method with arguments differing from Itcl.

Is there any explanation on the web or elsewhere how to manage this on the fly (i. e. without learning elisp)?

LV Tcl doesn't have a method built-in. Certain itcl has them, and I suspect that snit, xotcl and several others do. So that doesn't really tell us what you are using. I don't know what an xproc is. Check with the snit mailing list about ways to see its methods.


Aditya 29 Dec 2006

While trying the following code, i am getting this error. Please advise if i am missing something.

 % package require http 2.5
 2.5.3
 % http::geturl http://www.google.com/
 couldn't open socket: connection timed out

2006-12-30 gg - I do not get that error. The code appears correct to me. I recommend saving the output of the command anyway, because otherwise the command will have been useless (save the result and then call ::http::data $result to obtain the actual HTML).

You should check if you can access that URL using a browser. Maybe your internet access is crippled?

MG Check and make sure your firewall is set up to allow wish/tclsh to access the internet, too.

2007-01-02 gg - And if your browser is set up to use a proxy like HTTP or SOCKS.

LV 2007 Jan 02 - try http://www.tcl.tk/ or some other well known and working web site. Are you able to access any site from your program?


GreenAsJade 24 Dec 2006

I'm having problems with packing in an iwidgets::scrolledframe. The "-fill" doesn't seem to be being obeyed:

 package require Iwidgets
 namespace import -force iwidgets::*

 scrolledframe .sf -relief raised -labeltext "test" ;# comment me out
 set frm [.sf childsite]                            ;# comment me out

 #set frm [frame .sf]   ;# uncomment me to see the right behaviour
 label $frm.lab -text "Enter name:"
 entry $frm.ent
 label .but -text "below"
 pack $frm.lab  -side left -fill x
 pack $frm.ent  -side right
 pack .sf -fill x -expand yes
 pack .but

If you comment out the scrolled frame, and instead use a normal frame (by uncommenting that line) you will see the two different behaviours.

How can I get the "normal frame" behaviour in a scrolled frame?

Thanks!

MG Jan 3rd 2007 - It looks like the Iwidgets scrolledframe works by embedding a frame widget in a canvas (and then scrolling the canvas). And, while your label is filling the frame, the frame isn't filling the canvas (and from looking briefly at the canvas command's docs, there doesn't seem to be a way to make it do so). You can see that by giving the widgets all bg colors:

  $frm.lab configure -bg orange ;# label
  $frm configure -bg blue ;# frame
  [winfo parent $frm] configure -bg green ;# canvas

I'm pretty sure there are other scrolledframes around that work differently, though - maybe one of those will allow the fill you want.


Ben Dec, 20 2006

Hello! I have a problem with my embedded tcl interpreter. I would like to issue a warning to the user if he has done something which may be incorrect. However I currently am struggling to find out how to issue a linenumber with my warning. If I flag an error I can get the line number from the interp->errorInfo variable however that stops the execution of the script. Is there anyway to get the line number without stopping execution?

Thanks in advance.

Ben


SL Dec 19, 2006

Where is autoconf? I try to build an extension using TEA on winXP, but I need autoconf to do so. Why is that not included in msys_ming8, which I can find on tcl/sourceforge. I downloaded the autoconf-package and this needs perl! Am I wrong? I don't want to install perl and all this instead I really need to do so. Thanks.

LV autoconf is not a tcl program. It is one of a series of GNU programs designed for determining system configuration info. If you don't have it, your choices are:

  1. Locate and use a binary version of the package you are wanting to build
  2. check to see if someone has already packaged all the relevant dependencies pieces relating to autoconf for your OS/hardware
  3. start downloading and building pieces that you need.

See http://www.gnu.org/software/autoconf/ for literally the autoconf package. However, I don't know what additional packages you might need - perhaps m4, perl, maybe automake or libtool. These are all a part of a suite of programs commonly used for code and Makefile generation.


EMC Dec 19, 2006

What's the easiest way to provide a console comment entry field? I would like the user to add a comment when inside the console (no need for GUI) and this returns back to my script so I can append it to a README file. Thanks.

LV I was confused by this question. An entry field is a GUI widget. You said, in parens, there was no need for a GUI. So what is it you really want to do? Are you really wanting to get some input from the user? If so, you could do something like

 puts -nonewline stdout "Enter your comment now: "
 gets stdin comment

EMC Jan 12, 2007 Thanks for the response. When I execute tclkit-win32.exe in windows I see a console window and a grey blank gui box. When my script is running I would like it to ask for my comment as you show above. Problem is, it does not wait for the user to enter the comment. The script finishes and another command line prompt % is given in the console.

LV I don't know how well stdin and stdout work in a Windows based Tk console. Check over in the stdin page to see what you can find.


Gattu Dec 1, 2006

I'm using special characters , and in my program. If I edit the program code directly in the database manually, it works fine. But when I import the program from the file, these characters are replaced. I also tried to use [format %c 164] in the program to avoid the character replacement, but even this did not work. Can anyone please help me? Thanks.

Richard RS has documented most facets of that here on the wiki. Start with Unicode and UTF-8 and Unicode file reader.


WK Nov 24, 2006 - How do I print a variable to my local printer? Can Tcl display the Windows "Print" dialog box? Can you give me an example? Thank you.

2007-01-02 gg - read the printing wiki page


MG Nov 8 2006 - In the docs for the Img package's handling of MS Windows Icons (ICO), it says: The format name ico is recognized by the option -format. In addition the value for the option is treated as list and may contain any of the special options listed in section ICO OPTIONS. That section mentions -index <int> and -verbose <bool> as the new options. Just using

  image create photo imgName -format ico -file myicon.ico -index 3

returns an error, though (unknown option "-index") The only thing I could think of that the In addition line there could mean was

  image create photo imgName -format [list ico -index 3]

which isn't right. Does anyone have any experience of using these extra options, or can understand the help text better than I do and explain it? Thanks in advance for your help.

2007-01-02 gg - I know nothing about the Img package, but one thing I notice about that second attempt of yours is the fact that the appears to be no -file option specified.


JM in a Minimal Console Richard left some homework when he says "this can be expanded with colors to distinguish stdin/out/err, an entry with a history, menus (see Menus made easy), whatever.

it is probably very simple, but, how can I distinguish between stdin/out/err? ...or, just give me a hint.thanks.

HE You can find an answer on a Minimal Console now.


Ben wed 1 Nov

Hello, I am interested in writing c commands to extend the tcl parser I have embeded in my application.

  • I have various c++ objects in my program which are identfied by name.
  • I would like to write a function which takes a tcl regular expression and matches object names based on this regular expression.
  • I am using Tcl_EvalFile to run the commands in a file through the tcl parser.

My problem is that by the time the tcl object reaches one of my functions it has already had the backslash substitution performed on it. So for example if the user had typed ball\. this would become ball. so when I pass this string to the tcl regular expression engine it would match ballany char instead of ball. Does anyone know how to prevent this backslash substituion occuring. I have searched the web and looked at the code for regexp and am none the wiser. Any help would be great! (p.s many thanks to all the contributors to this wiki page it has already helped me out a lot.)

Edit - Actually I realised that I was not correctly bracing my regular expressions to protect them from the tcl parser. However is it possible to modify the tcl parser so that it "knows" about regular expression and does not perform standard substitutions on them but instead performs subsititutions with its own set of rules distinct from the tcl standard???

Lars H: Short answer: No, that's not possible. Long answer: If you really hack the Tcl core you might be able create something to that effect, but don't do that. The uniform substitution rules, combined with the ease with which you can prevent substitutions (99.9% of the cases just wrap it up in braces), are important parts of what makes Tcl such a radically simple language that still can exercise the power of all sorts of little languages.

Ben The languages I have used before all have complicated syntaxs like perl or c because of this I was initially worried by the effect detailed above. However from the links you provided I can see that a lot of thought and effort have gone into this "radically simple" approach.

Thank you for your answer. Ben.


(13 October 2006) Thanks to the person who started this new Ask and it shall be given page. However, we start a new page in April usually (for spring; spring = renewal). But I understand # 4 got too big already so you had to break the tradition.

I have a little problem with the following algorithm. I am trying to create a file that would hold all the deleted text a user deletes during a session. Why? Because the Undo in my editor is very unreliable and I'd rather delete the Undo function. I believe the Undo function is mainly useful to retrieve deleted text. This is why I want to have the above programmed.

Anyone has a clue as to the algorithm needed to create a file with deleted text?

MG Sounds like the real solution would probably be to fix your undo code - assuming you're using a text widget in 8.4 or above, support for undo/redo is built in. But if you take a look at the bindings for <Delete> and <BackSpace> in the text widget, they show you what text will get deleted. Basically, you want something like:

  text .t
  bind .t <Delete> {copyDeleted %W Delete}
  bind .t <BackSpace> {copyDeleted %W BackSpace}
  proc copyDeleted {w key} {
    if { [$w nextrange sel 1.0 end] ne ""] } {
         doSomethingWith [$w get sel.first sel.last]
       } elseif { $key eq "BackSpace" } {
         if { [$w compare insert != 1.0] } {
              doSomethingWith [$w get insert-1c]
            }
       } elseif { [$w compare insert != end] } {
         doSomethingWith [$w get insert]
       }
  }

where doSomethingWith is a proc that prints it's arg to a file. (Not tested, but something along those lines should work.) Though that won't really help you with undoing anything, since you'll just get a whole mess of deleted text all strung together (though it could be made more complete to include where text was deleted from and when). (Oh, and it won't include text deleted because of overtyping, either, but you could check the text-widget binding for KeyPress and factor that in). Reworking your undo code is probably a much simpler (and more effective) solution, though, IMHO.

Thanks a lot! Since the editor saves automatically, the Undo unsaves; also since it hyperlinks, undoing a hyperlink is deleting the text in a page. All these functions get in conflict with each other when I click Undo and the program simply goes out after deleting the contents of a page. Not a good thing! I believe the best would be to take out the undo button. Unless you see a way to undo just the text and not the hyperlink and the saving functions. A sort of filtered Undo.


Anonymous: i have a file in which the data is of the format

-root MOD -parameter NUM_COUNTERS 2 -parameter NUM_COMPARES 4 -parameter TBEXT_UNIT 1 MOD -revised

I need to take all the integers in various variables and also need to take

-root MOD -parameter NUM_COUNTERS 2 -parameter NUM_COMPARES 4 -parameter TBEXT_UNIT 1 as one parameter and MOD -revised as another parameter..

Can someone help me out ?

pcam It is nice to sign messages, or tell who you are. My attempt (although you need to explain a bit more than that)

    # supposing you have a fixed number of variables
    set myVarList [list var1 var2 var3 var4 var5]
    set line "-root MOD -parameter NUM_COUNTERS 2 -parameter NUM_COMPARES 4 -parameter TBEXT_UNIT 1 MOD -revised"
    foreach val $line {
    if {[regexp {[0-9]} $val]} then {
    lappend myVarList $val
    }
    }
    lappend myVarList [lrange $line 1 [expr [llength $line] - 3]]
    lappend myVarList [lrange $line [expr [llength $line] - 2] end]

Note: the regexp test is really weak, I assumed your input does not have a mix of digit and chararcters This is far from optimal, but should give you a starting base.


thread starting on 3sep2006

problems with Refrigerator magnetic Poetry, fairly well solved , thanks, closing out section-goldshell7.

Can someone delete page Refrigerator_Magnetic_Poetry from the current system.http://mini.net/tcl/16037 I found out "Magnetic Poetry" is a trademark, so I'm starting a new page called Refrigerator_Pinyin_Poetry. thanks, goldshell7.23Sep2006

LV we can't delete pages on the wiki - just blank them out.


(Hans-Albert Schneider, Sep 22 2006): We are running a Tcl interpreter in a sub-thread (this thread is not created with Tcl methods), and we have replaced the "exit" command to do some application specific stuff. The main thread passes strings to the sub-thread, which in turn calls Tcl_Eval() on them. Now consider a file containing the following lines:

  puts "Hello"
  exit
  puts "Still there"

If that file gets sourced, both "puts" commands are executed. What must we do so that the interpreter stops after the exit command? (If the "exit" is the last command, all works as expected, so the basic stuff is in place.)

Tcl_Exit() is not an option, as it calls exit(), and we are experiencing crashes if exit() is called in a sub-thread. So I tried Tcl_Finalize(), but this leads to a crash when the second "puts" is to be executed (if I understand correctly what I have found so far on the web and in the docs, Tcl_Finalize() has cleaned up stuff that is needed by the "puts" to (re)open the output channel).

 The solution (Hans-Albert Schneider, Dec 22 2006):

This seems to have been a tough one; nobody replied :-)

We are now doing essentially this (in C/C++; actually, it's Qt that does it for us):

    pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
    pthread_cancel(pthread_self());
    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
    pthread_testcancel();

 Mike Stout 9/26/05

I've built a simple circuit board with 680 ohm limiting resistors in series with 1.4V LEDs and connected that to GND and a data channel on the parallel port. I've tried both versions of lpttcl on my IBM thinkpad laptop and can't seem to get any digital outputs to go low. The lights are always lit (i.e. the data is always high) when I'm attempting to control the parallel port outputs through tcl. When I boot up the computer, the lights flicker on and off in a determined fashion, so I think the board works just fine. With lpttcl version 3, the base address always becomes -68 (decimal) and not 0x3BC or something sensible. I checked the bios and my parallel port is set for bidirectional. I tried to use the version 1 of the software, but didn't see any changes.

Any ideas? Also, two pics on the "Applying the parallel port to drive a LED..." webpage aren't visible. Namely the schematic (kind of important if I'm supposed to be connecting something I'm not) and pin layout (not important, I found that just fine).

Any help would be appreciated!

Cheers, Mike

Updata 10/1/06 I figured out what was wrong... several things. For some reason the base address of the parallel port always came up as something crazy like -68 decimal. I had to manually set it to 0x3bc once I forced the BIOS to assign the port to that address. Also, I was tinkering with the port settings and accidentally did not have it in BIRECTIONAL mode. Once I set it back to this mode, things were nearly cool. I then realized that I had wired the ground to the connector chassis and not pins 18-25. So in quick summary...

 BIOS:  BIDIRECTIONAL, Ox3BC
 CKT:  Data port to 1k resistor to LED to pin 18-25 (all are ground)
 LPTTCL: lpt_setba 0x3bc , lpt_wrctrl 0 , lpt_wrdata 0x00 to 0xff

Cheers, Mike


2006-08-28 thema

What's the difference between

  uplevel #0

and

  namespace inscope ::

Lars H: namespace inscope adds a level to the the context stack (you can [uplevel 1] out of it), whereas uplevel #0 goes back to an already existing level in the stack (thus hiding everything that was added to the stack afterwards).


I am stumped. I am writing a test to simulate a user checking out of an online store. The store is in beta so I have been using www.fao.com as a model, since they will be very similar. The problem is this: I cannot, for the life of me, get TCL or tclwebtest to recognize the buttons.... AHhhh!!

Here is an example of the code from the fao page (since it is public and I can share it):

 <div id="atc"><input name="submittag" class="formbutton" onclick="javascript:setAddTo(1, personalization)" value="Add To Cart >>" type="button"></div>

and the URL I got it from is:

http://www.fao.com/catalog/search_command.cmd?form_state=frmKeywordSearch_ln&sortByColumnName=NAME&keyword=834363

Basically, all I need is to push the button and have the cart have the item in it. ***ANY*** advice would be greatly appreciated. My thanks in advance.

- Austin A

  10/12/06

Lars H, 13 Oct 2006: From the look of it, that web site seems to rely on the browser having a built-in javascript interpreter. That seems to make the issue of using Tcl for testing a bit tricky... Presumably one should have to handle the exact javascripts sent by the server just like a browser would do, for the test to make sense. (Had the aim instead been to have Tcl talk to the server, one could have ported the javascripts to Tcl instead and handled it that way.)

Lars H, 14 March 2007: Selenium sounds as if it's meant for this kind of thing.


Active Script

The Active Script page needs updating. I'd do it but I'm actually in need of the information it could supply. There's a [Provide relevant URLs to define and further discuss this area\] and MHo has already annotated it with "any additional examples or links to any documentation???" The company I work for wants me to convert their language to an Active Script aware one. Where do I start???

BMA 2006-11-06

fr see tclcontrol and [L9 ] for HTML and VB examples


gjs The language on my PC is set to English, and all TCL apps think that it is German, I have tried different builds and versions of tclsh and wish. Is there a way to correct this?

LV I'm not certain, but I think that tcl gets its idea of the language to use from an environment variable. Ask over in the wiki's chatroom or on comp.lang.tcl to get more info.


tb How can I use the unix file selection dialog with windows? The one that comes with windows doesn't browser vfs.

CJL - The script version of the file dialogs works with vfs (but is ugly) - see near the top of tk_getopenfile

tb - Thanx! - Ugly or not, it hast to work :)

MG Also see the page on a File selection dialog for Tile, which includes (presumably native-looking, as it's Tile) selection dialogs which can work with a vfs.


Category Discussion - Category Development


DO NOT CLICK THIS LINK. It is a trap for badly behaved bots. If you follow this link, you will be unable to use the site afterwards.