Well, two things have pop'd up that are really important. The first is very important – the definition of “RegID”. I said that Dabo will assign a unique RegID if one is not assigned by the programmer. This is WRONG! “RegID” must be assigned by the programmer. It was my misunderstanding. However, it is still a very cool and simple way to reference an object on a form as long as the RegID is unique. The fact that the RegID has to be unique presents problems when you folks start creating re-useable classes. But for now creating re-usable classes are beyond this tutorial.
The second is I used the word 'variable' while describing my code segments. In python everything is an object or a reference to an object. Ed has provided several code examples that explain what and why it's important to make sure everyone understands. But I like the way Paul explained it in words. So I'm going to quote him: “I don't think it is frowned upon to call them 'variables', however when people start asking whether arguments are passed by reference or passed by value, and whether variables are pointers etc. then it starts becoming apparent that they are in the c mindset and need a tutorial on names and namespaces in Python. Calling them 'variables' in the tutorial is fine IMO, since everyone from other languages understands what a variable is, but give a sidebar explaining that Python really doesn't have variables how they probably understand them, but merely names in local namespaces bound to objects.” So let's continue with tutorial. Just please don't dismiss the comments made by others on the mistakes I have made in this tutorial. They are important and will make you better Dabo programmers if you follow the advise. I asked two questions in the last installment. First what was a the short cut way of binding an event to an object and the other was how to get the selected file name into the textbox. Ed and Paul are programmers and by definition are lazy (we all are). So they have created short cuts for many of the things that you'll do daily while programming with Dabo. There are many so I'll only show two and let you explore/find the others for yourself. The first deals with sizers. Recall that when I'm appending to a sizer I have pass two parameters as in: Vsizer.append(dabo.ui.dButton(self, Caption='Button'),1,'x') also written as Vsizer.append(dabo.ui.dButton(self, Caption='Button'), proportion=1, “expand”) You will type the last two parameters (proportion=1 , “expand”) often. Ed got tried of doing that and created a short cut: Vsizer.append1x(dabo.ui.dButton(self, Caption='Button')) simple right - note the "append1x". The second has to do with binding an event. In my code I did the following: ourButton=dabo.ui.dButton(self,RegID="selectButton",Caption= "...") ourButton.bindEvent(dEvents.Hit, self._openDialog) hs.append(ourButton,0) The easy way and all on one line is as follows: hs.append(dabo.ui.dButton(self,RegID="selectButton",Caption= "...",OnHit=self._openDialog),0) Notice I added “ OnHit=self._openDialog”. This does exactly what the other three lines do. When we get into using bizobjects we will use more short cuts. Just remember that short cuts are just that – short cuts for typing. They do not change the way the code works. The last question was how to fill the textbox with the filename selected in the file dialog. Here is the code: def _openDialog(self,evt): # need to receive the evt (in this case a click or Hit) evt.stop() theDialog=dabo.ui.dFileDialog(self) theDialog.show() if sys.platform == 'win32': myseperator = "\\" # someone should post why I needed two slashes else: myseperator = "/" myReturnFileValue= theDialog.FileName myReturnDirectory = theDialog.Directory # recall “filename” is the RegID of the textbox self.filename.Value= myReturnDirectory + myseperator + myReturnFileValue It's easy to read but you must be asking yourself how did he know about “theDialog.FileName” and “theDialog.Directory”. Fact is I've used dFileDialog in the past. But there was the first time I had to use it and I haven't forgotten how I found the return values. The first thing I did was check the DaboDoc's for a description of dFileDialog. I didn't find it - but there are lots of things covered in those html documents. So that's always the first place I check. Then I checked the source code for dFileDialog. Dabo source code has all the properties of the object gathered together (all in one spot within the source). What do I see but two properties - “FileName” and “Directory”. Pretty descriptive – but still I don't know what's in them. At this point I could just place a few print statements around and that would tell me. And sometimes I do just that. But Dabo has a very neat feature to help us discover values of the attributes and properties of objects. Run our form or any Dabo form and type a “control-d” (might be something different for the Mac). Wow! A “dShell” opens up. A python shell that knows about all your current objects (that are in scope) and that includes the Dabo objects. Try typing in “app.” and wait a faction of second. See the properties and attributes appear? Finish with “app.BasePrefKey” you should get 'fileTutor' for a response. You can thank Ed and Paul for that little goodie. Our instance of “dabo.ui.dFileDialog()” will not be in scope if you try it in dShell. Can someone figure a way to get it in scope (hint change the source code). And did anyone notice how I assigned the property values of dFileDialog to the textbox using the RegID? #!/usr/bin/env python # -*- coding: utf-8 -*- import os import sys import dabo import dabo.dEvents as dEvents import dabo.dException as dException dabo.ui.loadUI('wx') class MainForm(dabo.ui.dForm): def afterInit(self): self.Caption = "File Tutorial" self.Sizer =hs= dabo.ui.dSizer("h") hs.append(dabo.ui.dLabel(self, Caption= "Select a file"),0) hs.append(dabo.ui.dTextBox(self,RegID = "filename"),1) #didn't use the short way - you might want to try it! ourButton=dabo.ui.dButton(self,RegID="selectButton",Caption= "...") ourButton.bindEvent(dEvents.Hit, self._openDialog) hs.append(ourButton,0) self.layout() def _openDialog(self,evt): # need to receive the evt (in this case a click or Hit) evt.stop() theDialog=dabo.ui.dFileDialog(self) theDialog.show() if sys.platform == 'win32': myseparator = "\\" # some should post why I needed two slashes else: myseparator = "/" myReturnFileValue= theDialog.FileName myReturnDirectory = theDialog.Directory self.filename.Value= myReturnDirectory + myseparator + myReturnFileValue if __name__ == "__main__": app = dabo.dApp() app.BasePrefKey = "fileTutor" app.setAppInfo("appName", "File Tutorial ") app.MainFormClass = MainForm app.start() -- John Fabiani _______________________________________________ Post Messages to: Dabo-users@leafe.com Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users Searchable Archives: http://leafe.com/archives/search/dabo-users This message: http://leafe.com/archives/byMID/dabo-users/[EMAIL PROTECTED]