 Hi everyone again, we are continuing the LPS class and today we are continuing with the TK session, so in the last lecture we saw some of the additional commands of TK, mainly we talked about the canvas how to create the canvas, what are the item attributes, how to what are the bindings of the tags and all those things. Today we are going to look at one example of using a canvas and this is one application that we are going to build and then I am going to take you walk it through that application and see like a man better we can make use of some of these concepts that we learned in our class, so again the canvas widget is it manages 2D collection of graphical objects, lines, circles, images, we actually went and like put some smiley face with a circle and then two small circles with black color in it and then we also drew like some arcs to represent the mouth and so we actually now have a fairly good understanding as to how to draw this, so I am going to go through this particular example, so the application that we will be building is this furniture arranger application, it is a simple app to help you to decide how to arrange the furniture and we also use some drawing primitives to represent pieces of furniture, so here there is an oval some squares and rectangle, so these represent the furniture top-down view and then we will use multiple tags per item and then we will implement the behaviors based on the forms, so let us see what how we can do it, so we define some procedures, so here like we are trying to proceed this up front, so here procedure called setup canvas, this is essentially like I mean the first erase everything all the windows attributes and then basically like we will build the canvas, so this is the create canvas command and then we create the canvas and the the widget is .c and then we select the fact command and then we create those chairs, so those are the small squares here, so we create them, so for each of these numbers essentially like I mean we create a small rectangle and essentially like I mean that is with the actual location basically that is what these represent, so and then we fill the thing with the red and then we will tags as chair and furniture, so in the furniture big picture this indicates the chair and then now we will set up the chair behavior for that we use the bind command and then the bind command is essentially the command say that basically capture the event enter and then we say basically it is current, so basically we take the chair to the current location and then fill it with blue and then if the leave command is given then we basically like we move it and then fill it with red, so that it can be moved, now the second one is we create the table that is those oval shape figure here basically, so for creating the table again we create the oval and now we fill it with pink and then we create some tags for it which is table, rotatable and furniture and then again we say similar kind of binding that we create which is the table behavior is basically based on the events, so it turns into sky blue and then back to pink and then the couch is actually represented as the rectangle in the in this picture this is this one, so this is our chair, this is the table and this is the couch, so the couch is actually filled with orange and then we have a couch also is rotatable and then it is furniture and then we have same way we define the bindings and then here the binding is basically filled with green instead of orange, now we need to also we since we are generating tags which are rotatable, so we need to define the tags also, so here we know notice that actually like on the mouse is actually these are all of how this is, so here we denote all these bindings here, so the rotatable is essentially going to bind it to button 2 and then that causes it to rotate, so this is one of the mouse key buttons and then we also need to set up the furniture behavior because that is the highest hierarchy, highest level of hierarchy in this tags basically this is all furniture, this is furniture and then in looked at chair chair is also furniture, so the way that we define the furniture behavior is the button 1 where we what is the current x and current y okay, so and then we also generate the motion which is like going to click on it and then you can grab it to move the particular furniture that move is represented as form basically we say that it is move from current to the or basically like I mean the current position is moved to whatever we captured the previous one the percentage x and percentage y from there to the current x and current y, so we just add that and then that is what your new position is and then that is set as the new current x and current y, so once we define this all these procedures all we are ready to actually move and then now we also want to do some rotate, so the procedure rotate is essentially we find what is the element that from that window like what is the selection and then we also like set the coordinates to that particular coordinates and then we basically move it or essentially like find the new coordinates based on this formula which is form we subtract the the original one by 2, so now that becomes the new coordinate essentially doing some more manipulation and that is the rotate function basically what that means is like you can grab something and then rotate it whichever way that you want, so that is what this procedure will do. Now that we define all the procedures we can now set up the canvas basically using setup canvas which is already defined as a procedure here which is what creates the canvas and then we the bind the top level window to control L and then that sets up the canvas and then we basically put the title as furniture arranger which is right here, so it is a fairly simple program I think you should be able to just go through it and understand this, so now let us look at some more topics essentially one thing that I want to introduce you introduce to you is this ticklets, ticklets are just plug-ins for your browser so that you can embed a tk program inside the browser in browser external and that actually now can work just like any other tk program, so there are some Netscape plugins which I don't know I mean so you know you can look at but mainly like I mean the programs run as ticklets inside the browser and it needs you need to remember a few things one is the file system access is severely restricted so you don't want to try to access some files where you don't have permissions for and then exe c using exe c is prohibited so you don't want to use that and the network access is also prohibited so you cannot go and find things in the network and grabbing this place also prohibited because you don't want to grab this place from during the execution of program so that it will never come back and then the direct window manager interaction is also prohibited so you don't want to interact directly with the window manager to gather anything and then there are no menu widgets so as long as you can keep track of this you can write your own tickle or ticklets which is embedded tk programs and what do you what can you do with ticklets basically like you can design tools like calculator on the fly you can do like graphical demonstration and games design games in the browser in the Nets so that is about ticklets and mainly like I mean for using a ticket the user needs to have the install the plugin ticklet file system access is limited to using source and load script directories so those directories are open for you so that you can source it or and load the scripts essentially and then you have to use open as a read only in the script directories so you can read from the script directories but not write to it and then using the new command make temp to create read write temporary directories so that is the bottom line basically so you can use only like these and then you cannot get a file listing and there is no standard in the standard or standard in some commands have extensions to help like for example the image data and come from a MIME encoded string so if you if you were to take the furniture mover and convert that convert that into a ticklet basically things that to do is one is the first of all the furniture mover application itself makes a perfect ticket anyone in the world could rearrange the furniture there is only one change to the source basically like this is the one which is if info exists embed args so the 0 then do the the window manager the embedded args is an array containing the parameters from HTML and use them as a command line arguments for the ticket so let us create a HTML page for running this furniture mover so here we call the title and then the body is essentially like here we embed so the furniture.tickle and then we specify the width and height and then we specify what it does this is the import now we need to place the furniture.tickle and the furniture.html in the same directory in the or in your area or in the web so and then using the HTML file with even like any browser which show the ticklet essentially if the plugin is installed so one thing that you can do is you can include the link to the tickle plugin page plugin home page and a brief explanation of each of the tickle enhanced page so that is pretty much on the ticklet now we will go into the next topic which is essentially how to extend tickle so the basic philosophy behind that is we focus on the parameters some of the basics we already talked about the interpreters and including steps the implementing new commands is another one and then the managing packages how do you do the dynamic loading and managing results string which is how do you pass the results and then the some of the usual library procedures like parsing variables list and hash tables so in general the philosophy basically it is better to write TITL scripts than C code mainly because it is a faster to faster development also it is higher level and no compilations so it is more flexible this section is what we saw when we introduced tickle in the very early stages why write in C so if we need to access the hardware facilities or any kind of facilities provided by the operating system then we need to use C and then if the program itself is big and basically there is a lot more efficiency to be then it is better to use C and the other thing is when the code becomes complex the structure becomes much more important so the way that definitely like I mean we need to have some structure how to write the subroutines things like that again in that case C will be a better language so the implementing the new tickle commands that provide a few orthogonal permutives there are some tickle commands that can actually use some extra one so the low level to provide independent access to all the key features the permutives and then it is also high level level of high enough level to hide the unimportant details and that allows an efficient implementation so here we are comparing like three different tickles for weather reports so the goal is to retrieve the weather reports over a network from various servers so the first tickle command is to use the retrieve report format and print on the standard output this is too high level and so it is inflexible now we can write another command which opens a socket to the weather server select the station and retrieve the first line of the report this is too low level so again like I mean we may not use this kind of information even though this is provided integral finally the command set three basically the algorithm that is followed is to return the list of all the available stations given station name retrieve report so this kind of thing is just right so how do we design new commands so a couple of useful tips basically choose textual names for objects so dialogue bottom okay and then use the hash tables to map to see structures object oriented commands essentially they are basically dialogue bottom okay and then use configure and then say foreground is read so these kind of object oriented commands are good for small number of well-defined objects and doesn't pollute the namespace and allows similar commands for different objects and then we also have action oriented commands like string compare x and y this one is useful if many objects are short lived for many objects or shortly what this commands now how do we format the command results couple of suggestions essentially like make an easy to pass with tickle scripts so here like temp 53 I 68 low 37 preset 0.02 sky part so here it is very hard if you are using these numbers so you got to convert them over to symbolic wherever possible so we don't use 53 58 37 0.02 and 7 instead we need to replace it by left high temp low temp things like that and then we can also use the package prefixes in command names and global variables to distinguish what where exactly it is coming from for example WTH stations denote the the packaging information for this particular command and whether report is another command and media is another one so these kind of naming convention can also allow packages to coexist without any new classes so now let us talk about the interpreters so again the tickle inter structure encapsulates the execution state captures the variables the commands implemented in C the tickle procedures and then the execution stack we can have many interpreters in a single application but just only one is active times and creating and deleting interpreters basically in tickle we can do like a star interrupt which creates an interpreter with the tickle interrupt command and then we can assign the interrupt to the tickle create interrupt this is another way to create one and then we can also delete it by just doing a tickle delete interrupt so now how do we execute tickle scripts essentially so here we have this variable declared and then we can use tickle eval inter with the set A equal to 1 this is one way to execute the tickle script the other one is essentially like we can mode put it into into a file on init.tickle and then we can just say tickle eval file interrupt and then that file name and then finally we can also specify in a different way which is using the bar eval command and then here we give like the interrupt set A and 1 as three four different objects the code itself contains whether there is a success or failure and it comes to like tickle okay if it is a normal completion and then generates tickle error if any error occur and there is a cut during the execution we can also point to the result to the interrupt arrow to result and that points to the string that is has whether it is a tickle okay or tickle and usually what we want is the application should be should display the result or message for the user now just to another thing is where do these scripts come from read from the standard input I think like I mean you can answer all these questions how do we read from the standard input read from the script file associate x events rate for events you know associated scripts and then embedded in C port so here is the one way to create new commands um so we call this eq command as an integer and here we specify like client data tickle interrupt interpreter and some argc and error card so if the argc is not equal to three basically we just throw the result as one of the arguments and then go on the tickle error now the the next one that we will see is form we do a string comparison between the data one and data two and if they are equal then we say basically that the commands are equivalent otherwise we will say that command is not equal and then we just return the tickle okay value so now to register with interpreter we need to do the tickle create command interpreter eq eq command client data and now so once we register then the command will be called whenever any eq is invoked in the inter so we just kind of a binding eq to eq command so that if you just type eq the interpreter knows that it needs to call the command and we can also delete the command through this another function which is tickle delete command so the tickle create command creates the the shortcut and then tickle delete command will delete that so here is the client data essentially so the create command we create that client data and then we say like eq command client data client data so usually we pass only one word value to the command procedures and their callbacks but the client data here is usually a pointer to data structure and placed by the procedure so we can pass the pointers in and out of the client data type basically for example like tickle create demo client data and then gizmo pointer the gizmo pointer we can define gizmo star and then client data so essentially it lets many object commands share one command so what are the conventions for defining packages in tickle so one is the goal is to make it easy to improve and use tickle actions tickle extracts so we can use the package prefixes to prevent the name conflicts so we basically like kind of pick a short prefix for a package for example the rdb is read and then we use in all global names essentially so see procedure will have rdb open see variable will have rdb more objects things like that and then tickle will have rdb query so this way like I mean if we follow this definite prefixes then we can be successful in using tickle tickle so here is another example of creating the package initialization procedure name of the packages rdb units to create packages commands and it creates the package commands and evaluates the startup script if there is any so how does it do it so rdb in it tickle interpreter and then we execute tickle commands one by one and then finally we return the ticky eval file so use the package essentially like I mean we just use the command this is some compile as a shared library sample on Solaris this will be just k-k pick that see the rdb or see and then we can also dynamically load tickle programs but mostly into tickle SH or wish these are the two shells that can load the programs and then tickle will call the rdb units to initialize the package command for dynamically loading the thing is basically load rdb.so and then leave it as rd now the load command that can have several forms load file name load file name package name load maybe it is file name and packaging whereas the file name is the it is tagged as a dot so it is the compiled form of library online and then the package name is XYG which and we can use the info shared live extension to decide between DLL or .so etc we can also use info loaded command to see what packages have been loaded and directed you can also load packages statically that is tickle static package tickle interpreter character what is the character and then proc we basically the package unit proc is just initialized here and then we just say load with an empty string XYG so managing the results string so we need conventions for the interpreter results are basically how the result is getting so one thing is it permits the results of any length so and then we have to avoid malloc overheads possible and then our storage reclamation problems and then keep it as simple as possible so the last one is earlier easier said than done but that is what we need to try and then finally then and then the normal state of the interpreter is to invoke this the interpreter essentially so here basically like the result form number here and then it is called free proc something can you pause the audio so as I mentioned we can register the with the interpreter and then we can use the command without pointing to any other place and then for the client data essentially live on so we did this and then we can actually cast pointers in and out of client data type by using these kind of commands actually like the create command where you are inside that and with more pointer and then we define the gizmo pointer outside is more as its class and then it's also belongs to the client data so the client data is usually a pointer to the data structure management so that's why we can do all these kind of things and then the many object oriented of the object commands share one command prop so we talked about this we talked about these things and then here we talked about this dynamic loading so the load command load command is essentially like a many forms one is load just file name we can also specify the name and then the package name or load everything in the package name which is we do not just hope here file name is any kind of SO signal SO file not SO package name is just exercise inside that you can also in use the info shared live extension for decide between DLL so etc you can also use info loaded to see which package packages are loaded in the system and also we can load the packages statically that is tickle static package tickle interpreter the characters in the package name then tickle package init proc basically set to the init proc and you know it's also using the safe init proc and if these conditions are met then something will take so easy which is one of the thing and then the dynamic loading is always reporting with the many tools and many areas we saw this essentially like I mean so we need conventions for the interpreter followed by the result here we want to avoid mall mallock overhead so mallock is a C function to allocate memory and you don't want to use that if possible and then we can avoid the storage with the mention problem that is the leaks essentially and then we want to keep the name as simple as possible so here one quick example this is the normal state of the interpreter that is the command procedure is not involved what is the state so it writes out the results and then it is free is the processes so by default the command that is an interesting so a static semi static result is option one where we can write out saying that the result is zero and that's about it option two is the reallocated space in the interpreter and then we can write it into that so s cross sprint for a sprint of print f into the interpreter result is value is %d and then i so that results in this kind of UI where we have the result as a pointer here and then free proc there is a value for that event all these things now so here and then the option third option is to allow the new space proposal which is the interpreter result equal to mallock 2000 then interrupt fresh proc is free or free proc is free and then the interpreter can put that as thing which is of zero space tickle will call this free proc is not null to dispose of the result so the result is created and then it is sent to the program for further processing while this program itself disappears so the mechanism supports storage allocators other than mallock and free so how do we manage results essentially like we can use the library procedures tickle result set result is interpreter and string and then we place with the old value tickle append result interpreter string string string and then character star and null this extends the old value tickle append its element and then interpreter and string extends the old value of a list and then finally there is a reset result which will just clear the old value so the utility passing is essentially like an incremental space to pass arguments so here in integer this is one type of thing that code equal to tickle get in and get into interrupt interpreter argue one and value and it stores integer values returns tickle tk or tickle error and then if there is a parse error then you can get like refund so in with our company and then for parsing there are other procedures tickle get double these are like double in the context of floating point numbers tickle experts and double get boolean double expr boolean and then expr long and expr string tickle get boolean accepts s false one or a zero expr is basically like variations of interpreter argument as an expression so some more things on the variables read write and unset so how do we do it is basically you set the value and then value equal to tickle get bar interpreter a whatever the value from that get it and then we just set the bar to a a to the interpreter and then we unset for any of the other variables and then we can set traces basically like I mean that is going from various things essentially so interpreter quotes a tickle trace reads that enables the tickle trace reads and then tickle trace writes basically goes to and then trace proc and the commanding the client data so the trace proc will be called during each read or write of a monitor and then it can write any override in a path that read or read it in the parsing assembling proper lists like this basically is one split list and then merge but the more importantly like the dynamics is another one we think there are you see like the split list essentially like this splits all these lists into multiple objects that tickle merge command actually merges a list files into a single data structure and then some flexible hash tables are initialized hash hash table tickle unit hash table create hash entry find hash entry delete hash entry and delete hash so these kind of procedures are like having associative arrays in C excel may store the client data records for obfuscating that command now comes to dynamic strings essentially these are strings that can be handled dynamically so destring in it you also have destring append destring append element destring value and then destring free so dynamic string strings actually grow efficiently without bounds this is like a good string class in C++ and used internally by tickle or result management etc I think I am going to stop at this point we will continue extending the tickle actually like I will just summarize this one section and then we will see that then the next section in the next class so finally on the summary essentially like interfaces to see are fairly simple tickle was designed to make this true so it has to be simple and then we want to focus on primitives use the tickle scripts to compose fancy features so today we saw like a couple of big topics one is we finished the canvas widget using and when demonstrated using a furniture mover program and then on the second part we actually went through how to interface with C language so how to extend tickle into C so I think that is pretty much it we will cover some more items in the next one and hopefully I will wrap up next session or you may need one more session to wrap up okay thank you very much