hi...can somebody give me a little help here.
i get error message : 'file' object is not callable

its a program that call shell script (shell script run "fusion.deb").
here`s the code: test.py

#!/usr/bin/env python

import sys
import os
try:
        import pygtk
        pygtk.require("2.0")
except:
        pass
try:
        import gtk
        import gtk.glade
except:
        sys.exit(1)

class HelloWorldGTK:
        def __init__(self):
                #set the glade
                self.gladefile="hello.glade"
                self.wTree=gtk.glade.XML(self.gladefile)

                #create dictionary and connect it
                dic = { "on_button1_clicked" : self.button1_clicked,
                        "on_button2_clicked" : gtk.main_quit,
                        "on_checkbutton1_toggled": os.popen2("./nau")}
                self.wTree.signal_autoconnect(dic)

        def button1_clicked(self,widget):
                os.popen2("gedit")




if __name__ == "__main__":
        wine = HelloWorldGTK()
        gtk.main()

the glade file : hello.glade

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.2 on Fri Feb 13 01:37:08 2009 -->
<glade-interface>
  <widget class="GtkWindow" id="window1">
    <property name="visible">True</property>
    <property name="title" translatable="yes">Hello World</property>
    <signal name="destroy" handler="on_window1_destroy"/>
    <child>
      <widget class="GtkVBox" id="vbox1">
        <property name="visible">True</property>
        <child>
          <widget class="GtkButton" id="button1">
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="receives_default">True</property>
            <property name="label" translatable="yes">Hello!</property>
            <property name="response_id">0</property>
            <signal name="clicked" handler="on_button1_clicked"/>
          </widget>
        </child>
        <child>
          <widget class="GtkCheckButton" id="checkbutton1">
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="label" translatable="yes">checkbutton</property>
            <property name="response_id">0</property>
            <property name="draw_indicator">True</property>
            <signal name="toggled" handler="on_checkbutton1_toggled"/>
          </widget>
          <packing>
            <property name="position">1</property>
          </packing>
        </child>
        <child>
          <widget class="GtkButton" id="button2">
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="receives_default">True</property>
            <property name="label" translatable="yes">Exit</property>
            <property name="response_id">0</property>
            <signal name="clicked" handler="on_button2_clicked"/>
          </widget>
          <packing>
            <property name="position">2</property>
          </packing>
        </child>
      </widget>
    </child>
  </widget>
</glade-interface>

shell script file:nau

#!/bin/sh
sudo dpkg -i fusion-icon_0.0.0+git20071028-2ubuntu2_all.deb

this message appear when i hit the checkbutton1 (run shell script)

Well can you post the whole error because that usually also shows what line it is on, it makes it easy to debug. But ill give you an example of something that would get that error:

f = open("infile.txt")
f()            #here i would get my error. The file variable is not callable
f.close()

Maybe you need

self.gladefile = open( "hello.glade" )

instead of

self.gladefile="hello.glade"

?

paulthom12345 :
as soon after i hit the checkbutton it get error (first attachment).
i think the error appear because it should print out for password input when i run directly the "nau" shell script in terminal, because the debian package need root access to install. Meanwhile change the os.popen to run directly the "fusion.deb" still appear the same error as in the attachment.Or maybe because i give the checkbutton signal : on_checkbutton1_toggled.

ps: sorry for my bad english :( .

jlm699:
i change but got error:
TypeError: GladeXML.__init__() argument 1 must be string, not file.

you can see the detail in the second attachment.

Okay, i see you are using wing IDE, well in that case go to stack and go to the Call Stack, Click on them one by one and at one of them you will get something do with the actual problem, not just the function that called the problem.

So tht way you will be able to give greater detail as to whats going on.

paulthom12345 :
ok i solve the error (take a look at the code), but how to make the checkbutton run the fusion.deb in the same dir?. looks like os.popen only run os command in /usr/bin/.
i just need the program to prompt a password dialog and
it install the deb package just like we double click the file to install it.

#!/usr/bin/env python

import sys
import os
try:
        import pygtk
        pygtk.require("2.0")
except:
        pass
try:
        import gtk
        import gtk.glade
except:
        sys.exit(1)

class HelloWorldGTK:
        def __init__(self):
                #set the glade
                self.gladefile=("hello.glade")
                self.wTree=gtk.glade.XML(self.gladefile)

                #create dictionary and connect it
                dic = { "on_button1_clicked" : self.button1_clicked,
                        "on_button2_clicked" : gtk.main_quit,
                        "on_checkbutton1_toggled" : self.checkbutton1_toggled}
                self.wTree.signal_autoconnect(dic)

        def button1_clicked(self,widget):
                os.popen2("nautilus")
        def checkbutton1_toggled(self,widget):
                os.popen2("fusion.deb")


if __name__ == "__main__":
        wine = HelloWorldGTK()
        gtk.main()

Glade:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.2 on Fri Feb 13 20:03:10 2009 -->
<glade-interface>
  <widget class="GtkWindow" id="window1">
    <property name="visible">True</property>
    <property name="title" translatable="yes">Hello World</property>
    <signal name="destroy" handler="on_window1_destroy"/>
    <child>
      <widget class="GtkVBox" id="vbox1">
        <property name="visible">True</property>
        <child>
          <widget class="GtkButton" id="button1">
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="receives_default">True</property>
            <property name="label" translatable="yes">Hello!</property>
            <property name="response_id">0</property>
            <signal name="clicked" handler="on_button1_clicked"/>
          </widget>
        </child>
        <child>
          <widget class="GtkCheckButton" id="checkbutton1">
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="events">GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON1_MOTION_MASK | GDK_BUTTON2_MOTION_MASK | GDK_BUTTON3_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_FOCUS_CHANGE_MASK | GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK | GDK_VISIBILITY_NOTIFY_MASK | GDK_PROXIMITY_IN_MASK | GDK_PROXIMITY_OUT_MASK | GDK_SUBSTRUCTURE_MASK | GDK_SCROLL_MASK</property>
            <property name="label" translatable="yes">Fusion</property>
            <property name="response_id">1</property>
            <property name="draw_indicator">True</property>
            <signal name="toggled" handler="on_checkbutton1_toggled"/>
          </widget>
          <packing>
            <property name="position">1</property>
          </packing>
        </child>
        <child>
          <widget class="GtkButton" id="button2">
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="receives_default">True</property>
            <property name="label" translatable="yes">Exit</property>
            <property name="response_id">0</property>
            <signal name="clicked" handler="on_button2_clicked"/>
          </widget>
          <packing>
            <property name="position">2</property>
          </packing>
        </child>
      </widget>
    </child>
  </widget>
</glade-interface>

shell script:

#!/bin/sh
sudo dpkg -i fusion.deb
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.