Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: [SOLVED] Can I delete python's cache?

  1. #1
    Join Date
    Dec 2006
    Beans
    160
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    [SOLVED] Can I delete python's cache?

    I've created a layout in Glade 3 and saved it as filename.glade
    My code is:
    Code:
    #!/usr/bin/env python
     
    import sys
    import gtk
    import gtk.glade
     
    class TutorialApp:
     
      def __init__(self):
      
        self.wTree = gtk.glade.XML("filename.glade")
     
        dic = { "on_window_destroy" : gtk.main_quit }
        self.wTree.signal_autoconnect(dic)
        self.wTree.get_widget("window").show()
     
    if __name__ == "__main__":
      app = TutorialApp()
      gtk.main()
    I get this error:
    Code:
    Traceback (most recent call last):
     File "/home/user/Documents/Programming/tutorial.py", line 18, in 
    app = TutorialApp()
     File "/home/user/Documents/Programming/tutorial.py", line 15, in __init__
    self.wTree.get_widget("window").show()
    AttributeError: 'NoneType' object has no attribute 'show'
    I know what the problem is: previously I had called my window win_, saved it and ran a similar python script, with win_ instead of window. It worked. But gtk.glade.XML cached the glade file, and the change I made to the window's name isn't acknowledged.

    So my question is, how can I clear python's cache?

    (I've just started to learn python and glade.)

  2. #2
    Join Date
    Aug 2007
    Location
    127.0.0.1
    Beans
    1,800
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Can I delete python's cache?

    Quote Originally Posted by Jadd View Post
    I know what the problem is: previously I had called my window win_, saved it and ran a similar python script, with win_ instead of window. It worked. But gtk.glade.XML cached the glade file, and the change I made to the window's name isn't acknowledged.

    So my question is, how can I clear python's cache?

    (I've just started to learn python and glade.)
    I'm pretty sure that gtk.glade.xml does not cache anything. My guess is that you didn't save correctly on glade, as glade is kinda weird for it's things, like you have to type the name, hit enter to change it, and then save. Trust me with this one, as I've experienced similar problems like. "I renamed my button, hit Ctrl+S, shift desktop, try to get the widget, and fails, then I go back to glade and see that the name didn't change at all"

    And your application does not exist correctly, I just tried it and didn't work, connect it manually, and also, I recommend to move the gtk_main loop inside the class, but that's just me.
    "Just in terms of allocation of time resources, religion is not very efficient. There's a lot more I could be doing on a Sunday morning."
    -Bill Gates

  3. #3
    Join Date
    Dec 2006
    Beans
    160
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: Can I delete python's cache?

    Quote Originally Posted by Can+~ View Post
    I'm pretty sure that gtk.glade.xml does not cache anything. My guess is that you didn't save correctly on glade, as glade is kinda weird for it's things, like you have to type the name, hit enter to change it, and then save. Trust me with this one, as I've experienced similar problems like. "I renamed my button, hit Ctrl+S, shift desktop, try to get the widget, and fails, then I go back to glade and see that the name didn't change at all"

    And your application does not exist correctly, I just tried it and didn't work, connect it manually, and also, I recommend to move the gtk_main loop inside the class, but that's just me.
    Thank you.
    However, I should have mentionned this earlier, gtk.glade.XML is documented, and it's documentation says it does cache the parse tree:
    http://www.pygtk.org/pygtk2reference...-gladexml.html
    (Find "cached")
    Also, I have verified that I had saved correctly, I even opened the XML .glade file in a text editor to do so.
    Last edited by Jadd; March 11th, 2008 at 07:20 PM.

  4. #4
    Join Date
    Apr 2006
    Location
    Slovenia
    Beans
    370
    Distro
    Ubuntu Development Release

    Re: Can I delete python's cache?

    Quote Originally Posted by Jadd View Post
    Thank you.
    However, I should have mentionned this earlier, gtk.glade.XML is documented, and it's documentation says it does cache the parse tree:
    http://www.pygtk.org/pygtk2reference...-gladexml.html
    (Find "cached")
    Also, I have verified that I had saved correctly, I even opened the XML .glade file in a text editor to do so.
    Of course it caches the tree... for the life time of the application. It doesn't make sense to cache it longer than that.

  5. #5
    Join Date
    Dec 2006
    Beans
    160
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: Can I delete python's cache?

    Perhaps my IDE has got something to do with it. I'm using SPE.

  6. #6
    Join Date
    Aug 2007
    Location
    127.0.0.1
    Beans
    1,800
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Can I delete python's cache?

    Quote Originally Posted by Jadd View Post
    Thank you.
    However, I should have mentionned this earlier, gtk.glade.XML is documented, and it's documentation says it does cache the parse tree:
    http://www.pygtk.org/pygtk2reference...-gladexml.html
    (Find "cached")
    Also, I have verified that I had saved correctly, I even opened the XML .glade file in a text editor to do so.
    I don't think that cache means a long term cache.

    Could you post the glade file (it's plain XML).

    Also, try to run from the commandline python myfile.py

    I made an example based on your file, this one exits properly, and has the gtk.main inside the class:

    PHP Code:
    #!/usr/bin/env python
     
    #import sys
    import gtk
    import gtk
    .glade
     
    class TutorialApp:
        
    def destroy_event(selfwidgetdata=None):
            
    gtk.main_quit()
            return 
    False
        
        def __init__
    (self):
            
    self.wTree    gtk.glade.XML("filename.glade")
            
    self.win    self.wTree.get_widget("window1")
            
            
            
    #__signals__ = { "on_window_destroy" : gtk.main_quit }
            #self.wTree.signal_autoconnect(__signals__)
            
            
    self.win.connect("destroy"self.destroy_eventNone)
            
            
    self.win.show_all()
            
         
    def gtk_main(self):
             
    gtk.main()
             
    if 
    __name__ == "__main__":
        
    app TutorialApp()
        
    app.gtk_main() 
    Last edited by Can+~; March 11th, 2008 at 07:42 PM.
    "Just in terms of allocation of time resources, religion is not very efficient. There's a lot more I could be doing on a Sunday morning."
    -Bill Gates

  7. #7
    Join Date
    Dec 2006
    Beans
    160
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: Can I delete python's cache?

    I quit SPE and glade and used just gedit, but it still gives me the same problems.

    Here's the code:
    PHP Code:
    #!/usr/bin/env python
     
    import sys
    import gtk
    import gtk
    .glade
     
    class TutorialApp:
     
      
    def __init__(self):
      
        
    self.wTree gtk.glade.XML("desktop_designer.glade")
     
        
    dic = { "on_window_destroy" gtk.main_quit }
        
    self.wTree.signal_autoconnect(dic)
        
    self.wTree.get_widget("window").show()
     
    if 
    __name__ == "__main__":
      
    app TutorialApp()
      
    gtk.main() 

  8. #8
    Join Date
    Dec 2006
    Beans
    160
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: Can I delete python's cache?

    And here's the glade file. I had to archive because these forums don't accept .glade.

    I doubt you'll get the same problems as me though, you haven't got the version with win_ in your cache.
    Attached Files Attached Files
    Last edited by Jadd; March 11th, 2008 at 07:48 PM.

  9. #9
    Join Date
    Dec 2006
    Beans
    160
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: Can I delete python's cache?

    I tried your suggested code. I had to convert the spaces into tabs which was annoying. Using window and window1 gave the same kind of error, but using win_ worked perfectly! (By the way, the .glade file I'm using is called desktop_designer.glade, and I did modify that code to reflect that, sorry for triple posting)

  10. #10
    Join Date
    Aug 2007
    Location
    127.0.0.1
    Beans
    1,800
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Can I delete python's cache?

    It works for me, even if I rename it various times.

    But I came up with a new theory, maybe, just maybe, you opened the wrong file, maybe you're editing a copy instead of the actual file, that would create the false impression of a "omg it's cached". Close glade and make sure you're opening the right file, and the right .py file. How did I get to this conclusion? It just happend to me, I was working on a copy on my desktop rather than the one next to the python script.

    Btw, you have two "WINDOW_TOPLEVEL", make one POPUP.

    *edit* And yes, I use tabs, sorry about that.
    Last edited by Can+~; March 11th, 2008 at 08:10 PM.
    "Just in terms of allocation of time resources, religion is not very efficient. There's a lot more I could be doing on a Sunday morning."
    -Bill Gates

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •