HiI am trying to embed a Python script (creates a PyGtk window) in C. I can get it to work, except when I try to import a module I created. I have attached a simple example which shows what the problem is
simulator.sh is the script I run to compile and execute the C program. simulator.c the main C program which calls the Python interpreter.test_dialogue.py is a simple python script which launches a window, and two dialogs.
global_variables.py contains some global variablesIn test_dialog.py, line 16 ('import global_variables') is commented out. If I uncomment it, I get an exception: " 'No module named global_variables' in 'garbage collection' "
Can anyone shed some light as to what this means. Also, to make the C program work you have to update the full file paths. Cheers Peter
#!/usr/bin/env python
#global widget dictionary
widgets={}
#dictionary entries for topology, neuron and synapse items
topologyItems={}
neuronItems={}
synapseItems={}
#dictionary entry for the single simulator item
simulatorItem={}
#dictionary entry for the single navigation item
navigationItem={}
#dictionary entry for the single environment item
environmentItem={}
#dictionary entries for topology, neuron and synapse objects
topologyObjects={}
neuronObjects={}
synapseObjects={}
#dictionary entries for topology, neuron and synapse visual objects
topologyVisualObjects={}
neuronVisualObjects={}
synapseVisualObjects={}
#dictionary entries for environment,navigator and simulator objects
environmentObject=[None]
navigationObject=[None]
simulatorObject=[None]
#for blocking signal callbacks
topologyBlocked=[False]
neuronBlocked=[False]
synapseBlocked=[False]
#main directory
path='/home/peyman/simulator/'
#user defined models directory
userDefinedPath=path+'save_files/user_defined/'
#specific model directories
simulatorModelPath=userDefinedPath+'simulator_models/'
neuronModelPath=userDefinedPath+'neuron_models/'
synapseModelPath=userDefinedPath+'synapse_models/'
neuronFunctionPath=userDefinedPath+'neuron_functions/'
plasticityModelPath=userDefinedPath+'plasticity_models/'
connectionFunctionPath=userDefinedPath+'connection_functions/'
environmentTypePath=userDefinedPath+'environment_types/'
navigationFunctionPath=userDefinedPath+'navigation_functions/'
#save file directory
saveFilePath=path+'save_files/simulations/'
simulator.c
Description: Binary data
simulator.sh
Description: Binary data
#!/usr/bin/env python
import sys
try:
import pygtk
pygtk.require("2.0")
except:
pass
try:
import gtk
import gtk.glade
except:
sys.exit(1)
#Uncommenting the below import statement raises an exception
#import global_variables
#Uncommenting the above import statement raises an exception
def make_effective_dialog(window):
"""Create all the widgets in here
"""
dialog=gtk.Dialog(title='Hello',parent=window,flags=gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT)
#disable the separator
#get the vbox
vBox=dialog.vbox
#create and entry
label=gtk.Label("I'm afraid I can't do that, Dave")
#add entry to vertical box
vBox.pack_start(label,expand=True,fill=True,padding=10)
window.show_all()
label.show()
if dialog.run():
print True
else:
print False
dialog.destroy()
def make_deffective_dialog(window):
"""Create all the widgets in here
"""
dialog=gtk.Dialog(title='Hello',parent=window,flags=gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT, buttons=(gtk.STOCK_OK,True,gtk.STOCK_OK,True,gtk.STOCK_CANCEL,False))
#make some dummy buttons
button1=gtk.Button(gtk.STOCK_CANCEL)
#get the action area (it is a horizontal box)
hBox=dialog.action_area
hBox.pack_start(button1,expand=True,fill=True,padding=10)
button1.show()
#get the vbox
vBox=dialog.vbox
#create and entry
label=gtk.Label("I'm afraid I can't do that, Dave")
#add entry to vertical box
vBox.pack_start(label,expand=True,fill=True,padding=10)
window.show_all()
label.show()
if dialog.run():
print True
else:
print False
dialog.destroy()
def on_main_window_delete_event(widget,data=None):
"""Return false so the window gets destroyed
"""
return False
def on_main_window_destroy(widget,data=None):
"""Return false so the window gets destroyed
"""
gtk.main_quit()
if __name__ == '__main__':
try:
window=gtk.Window()
window.set_title("main")
window.show()
window.connect('destroy',on_main_window_destroy)
window.connect('delete_event',on_main_window_delete_event)
make_effective_dialog(window)
make_deffective_dialog(window)
gtk.main()
except KeyboardInterrupt:
sys.exit(1)
_______________________________________________ pygtk mailing list [email protected] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
