Results 1 to 3 of 3

Thread: STOCK_CLOSE not defined?

  1. #1
    Join Date
    Sep 2007
    Location
    Oklahoma, USA
    Beans
    2,271
    Distro
    Xubuntu 14.04 Trusty Tahr

    STOCK_CLOSE not defined?

    I'm creating a small weather applet based on the "textview-basic" example from the pygtk manual, and attempting to create its "Close" button using the STOCK_CLOSE definition as shown in several of the other examples. In every case, I get an error message that STOCK_CLOSE is not defined. What am I missing?

    Here's the entire applet script, in its working condition. If I replace ("Close") with (stock=STOCK_CLOSE), as copied and pasted from other examples, I get the fatal error when running in the interpreter.
    Code:
    #!/usr/bin/env python
    
    # example textview-basic.py
    
    import pygtk
    pygtk.require('2.0')
    import gtk
    import weather
    
    class wxokc:
        def close_application(self, widget):
            gtk.main_quit()
    
        def __init__(self):
            window = gtk.Window(gtk.WINDOW_TOPLEVEL)
    	window.set_default_size(585, 275)
            window.set_resizable(True)  
            window.connect("destroy", self.close_application)
            window.set_title("Weather at Will Rogers")
            window.set_border_width(2)
    
            box1 = gtk.VBox(False, 0)
            window.add(box1)
            box1.show()
    
            box2 = gtk.VBox(False, 10)
            box2.set_border_width(5)
            box1.pack_start(box2, True, True, 0)
            box2.show()
    
            sw = gtk.ScrolledWindow()
            sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
            textview = gtk.TextView()
            textbuffer = textview.get_buffer()
    	textview.set_editable(False)
    	textview.set_cursor_visible(False)
            sw.add(textview)
            sw.show()
            textview.show()
            box2.pack_start(sw)
    
            string = weather.get_metar(id="KOKC")
            textbuffer.set_text(string)
    
            button = gtk.Button("Close")
            button.connect("clicked", self.close_application)
            button.set_flags(gtk.CAN_DEFAULT)
    
            # Create an alignment object
            align = gtk.Alignment(1.0, 1.0, 0, 0)
            box2.pack_end(align, False, False, 2)
    	align.add(button)
    
            button.show()
            align.show()
            window.show()
    
    def main():
        gtk.main()
        return 0       
    
    if __name__ == "__main__":
        wxokc()
        main()
    EDIT: You may have to install the "weather-util" package to have the "weather" module in place! I just ran the applet in another system, without the weather package, and got such an error message.
    Last edited by JKyleOKC; September 13th, 2013 at 09:01 PM. Reason: additional detail.
    --
    Jim Kyle in Oklahoma, USA
    Linux Counter #259718
    Howto mark thread: https://wiki.ubuntu.com/UnansweredPo.../SolvedThreads

  2. #2
    Join Date
    Nov 2005
    Location
    Bordeaux, France
    Beans
    11,297
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: STOCK_CLOSE not defined?

    Try gtk.STOCK_CLOSE.
    「明後日の夕方には帰ってるからね。」


  3. #3
    Join Date
    Sep 2007
    Location
    Oklahoma, USA
    Beans
    2,271
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: STOCK_CLOSE not defined?

    I thought I had tried that when copying and pasting from another example in the manual, but perhaps it was cached -- because making the change just now fixed it! Many thanks for prompting me to try again!
    --
    Jim Kyle in Oklahoma, USA
    Linux Counter #259718
    Howto mark thread: https://wiki.ubuntu.com/UnansweredPo.../SolvedThreads

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
  •