Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
need help about canvas and tags...

Posted by ganee (miss), 1 April 2004

Hello,

I ve seen that you were able to solve many problems then maybe you can help me...;

I ve got a strange problem...; or a stupid mistake in my code !

I ve got 2 canvas in 2 different frames in a window : $frame1.f.c and $frame2.f.c. In the fisrt one i create objects thanks to buttons : for example a squarre, which can be moved, with a name which can be changed and moved too thanks to nodes. This squarre and this title have different tags : « r » and « title ». Then I can save this drawing in a text file.

In the second tab I am able to reopen these kind of text files and to move the objects and their name ; so that i can place many drawing made in the first tab in this second canvas.

The problem is that their are problems when i work on both of this tabs : I create lists to controls the geometrics because their are squarres and rounds; But I think that the problems comes from the tk gestion of graphical geometrics elements;
For example at a time the squarre will move with a part of another object  which has not got the same tag ! ! and their are problems of saving in text files because an object with a tag « r » takes another tag !
When i look the identifiers gave by tcl tk I see that it can be the same in the 2 tabs, and when i add a drawing in the second tab they are changed or sometimes they disappear...;


Have you got any ideas to help me please, i m totally crazy about this !  
(I wish it is a bit clear, excuse me if i m not really understandable)



Posted by admin (Graham Ellis), 3 April 2004
I *think* I follow ...

1. An application in which you draw graphics and save to a file, with each element tagged.

2. Another appliaction in which you read that file, and when you move a tagged element something else moves with it when it shouldn't.

Is that a fair summary?

Can you reproduce the ppoblem in two short programs as described above?  If so, I can look at them and perhaps offer advise.  If  the example code doesn't show the problem, you can add in extra features until it does and you'll have a clue as to what's causing it.  If you get to something that's as big as your original code and does everything that it did - problem solved and you can put it down to a coding error

I would guess the problem migfht be down to the save and restore code and the tags - would be interested to see your code in that area in the sample programs!

Posted by ganee (miss), 4 April 2004
Hi Graham Ellis!

First of all thanks for helping me.


Indeed I only have 1 application with 2 tabs like this :




 I don t find how to insert an image.. ( maybe I can send you an email)

Elements are composed of several with different tags :

 I don t find how to insert an image there too..




When I work only in one of the 2 tabs /"drawing/"; or /"big drawing/" everything is ok : everything moves normally and the save and restore are working. But as soon as I have something in /"drawing/" called frame1.f.c  and /"big drawing/" called frame2.f.c  problems appears. For example moving S will also move R1 ; or moving S willmove name1 (which is ok because they are linked) but moving the circle will also move name1 !! and then name2 is still on screen but their is an error while acctioning on it.

(I think that many problems apears with the elements /"text/" and I have geometric elements which contains several /"text/"


Here are parts of my code :

To create a rectangle :

proc frame1::mkC { frame node1 long } {

     global nodeX
     global nodeY
     global nodeFirst
     global title
     global nodeTitre
     global S
     global type
     global Slength
     
     set Brown "#f4a873"
     set White "#ffffff"
     
     set longueur $long
     set largeur 10

     set nouvS [$frame.f.c create polygon $nodeX($node1) $nodeY($node1) \
                   [expr $nodeX($node1)+$longueur] $nodeY($node1) \
                   [expr $nodeX($node1)+$longueur] [expr $nodeY($node1)+$largeur] \
                   $nodeX($node1) [expr $nodeY($node1)+$largeur] \
                   -fill $Brown -tags canton]

     set nodeFirst($nouvS) $node1
     set nodeX($nodeFirst($nouvS)) $nodeX($node1)
     set nodeY($nodeFirst($nouvS)) $nodeY($node1)
     set nouvT [$frame.f.c create text $nodeX($nodeFirst($nouvS)) $nodeY($nodeFirst($nouvS)) -text "??" -tags name -fill $White]

     set S($nouvS) $ nouvS
     set type($nouvS) "S"
     set titre($nouvS) $nouvT
     set Slength($nouvS) $longueur
     set nodeTitle($nouvS) [mkNode $frame $nodeX($nodeFirst($nouvS)) $nodeY($nodeFirst($nouvS)) "false"]

}



To control events in a tab for instance in /"frame2.f.c/"

     $frame2.f.c bind S <Button-1> {
           set currentX %x
     }

     $ frame2.f.c bind canton <B1-Motion> {
           set modif 1
           set longueur [expr $Slength([$frame2.f.c find withtag current]) + %x - $currentX]
           ChgSLength $frame2 [$frame2.f.c find withtag current] $longueur
           set currentX %x
     }

     $ frame2.f.c bind canton <Button-2> {
           set modif 1
           deleteS $posteframe [$frame2.f.c find withtag current]
     }



I use the same functions for the 2 tabs but the name of the frame is passed as a parameter of it.



To save an element from the 1st tab in my text file :

append en_tete "RECTANGLE\n\n"

set lS [$frame1.f.c find withtag S]
set nbS [llength $lS]

for { set i 0 } { $i <= [expr $nbS-1] } { incr i } {
       set element [lindex $lS $i]
       append en_tete "\{-$nodeX($nodeFirst($element))-$nodeY($nodeFirst($element))\
               -[$ frame1.f.c itemcget $title($element) -text]-$nodeX($nodeTitle($title($element)))\
               -$nodeY($nodeTitle($title($element)))-$type($element)-$Slength($element)-\}   #### rectangle [expr $i+1] ~\n"
}
append en_tete "END_RECTANGLE\n\n"

and then :

puts $fileID $en_tete
close $fileID


Sometimes in my text file I can see &#8211;still while working in the 2 tabs- that the position of an element of a frame as taken the position of one of the other frame... ; I can also see that the tag of an element or that its name has changed !!!

Edit by Graham  Miss - I have edited two images from our website into your post as an example.  You can simply change the URL to point to images on your own webspace  

Edit by Miss  ok I ll have to create my own page... to replace this buses! thanks a lot!



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho