From: normanwinn <nor...@on...> - 2004-09-16 19:53:40
|
Hi, I was having trouble getting Walkthough 3 to work. Having already posted I felt too guilty to admit I hadn't even got that far. I trawled the web for hints but didn't get anywhere. Then I played with 'FindFiles'. I soon wanted it to open resource files in the resource editor (no doubt someone will come back and tell me that was already possible). So I decided to see if I could add this functionality myself. First I had to find the '.rsrc' files. To do this I just searched for: { 'application':{ 'type':'Application', not elegant, but it worked. I first found where the highlighted file was opened which was inside this function (only showing the part I played with): > def editFile(self, filename, lineno=None): > if filename == '': > return > > log.debug("filename: " + filename + " lineno: " + str(lineno)) > # edit Python scripts with codeEditor > # everything else with textEditor > # the list of extensions and associated programs to > # open with should be user settable > if os.path.splitext(filename)[-1] in ['.py', '.pyw']: > program = os.path.join("..", "codeEditor", "codeEditor.pyw") > if not os.path.exists(program): > program = os.path.join("..", "codeEditor", > "codeEditor.py") > else: > program = os.path.join("..", "textEditor", "textEditor.pyw") > if not os.path.exists(program): > program = os.path.join("..", "textEditor", > "textEditor.py") > # throw an exception if textEditor can't be found? > log.debug('program: ' + program) I had made a copy of the 'FindFiles' directory content and put it elsewhere. It took me a while to fathom the FindFiles depends on hanging off the 'Tools' folder to work. I then moved my copy there and started to get somewhere. I tried adding a condition to so that I could operate on '.rsrc.py' files. The interactive shell is a great tool for learning. I imported 'os' and worked out what 'os.path.splitext' does. I copied a path and assigned it to a variable (still in the shell) and finally found that: os.path.splitext(filename)[0][-5:] gave me the '.rsrc' I was trying for. I was not successful at getting the resource editor to run so I tried assigning the above to a variable and just to show it with a 'print'. Evidently, this produced an error. I saw all those 'log.debug' lines so went about finding which of the imported modules it came from. Once I found it I imported this in the shell and looked for help on how 'log' worked. Nice and simple, so I put: log.enable() in the function 'on_initialize' and I had log information pouring out to me in the shell. This told me that I was extracting the right string. I then divined my error. I was using 'is' instead of '==' to test my string. I changed it and it worked. I felt real proud of myself when the resource editor opened up. So, if anyone is interested here is what those lines above became: > def editFile(self, filename, lineno=None): > if filename == '': > return > > log.debug("filename: " + filename + " lineno: " + str(lineno)) > # edit Python scripts with codeEditor > # everything else with textEditor > # the list of extensions and associated programs to > # open with should be user settable > rsrcFile = os.path.splitext(filename)[0][-5:] > log.debug('rsrcFile: ' + rsrcFile) > if rsrcFile == '.rsrc': > program = os.path.join("..", "resourceEditor", > "resourceEditor.py") > if not os.path.exists(program): > program = os.path.join("..", "resourceEditor", > "resourceEditor.py") > else: > if os.path.splitext(filename)[-1] in ['.px', '.pyx']: > program = os.path.join("..", "codeEditor", > "codeEditor.pyw") > if not os.path.exists(program): > program = os.path.join("..", "codeEditor", > "codeEditor.py") > else: > program = os.path.join("..", "textEditor", > "textEditor.pyw") > if not os.path.exists(program): > program = os.path.join("..", "textEditor", > "textEditor.py") I realise that using a variable to get my string is not very elegant but I did it that way to isolate my error. I am relating this partly as one test I have set myself is to see if I can learn PythonCard and Python 'top down'. I learnt Object Pascal in Delphi that way and had thought it would not be possible. Seems I am wrong, Norman PS I still can't get the child window to open. My script runs OK but as soon as I hit 'Increment' or 'Decrement' I get |