Here's the solution I figured out, but a self.destroy() on the assistant at the
last step gives me a Segmentation Fault.
Anybody ?
<code>
#-*-encoding:utf-8-*-
# From #pida
# <aa_> ok, first direction, never use import pygtk
# <aa_> pygtk.require("2.0")
import gtk
from coriolis.models import Media
from pygtkhelpers.proxy import proxy_for
from mytable import MyTable
class SelectModelAttrForm(gtk.VBox):
def __init__(self,model):
"""
"""
gtk.VBox.__init__(self)
self.orm_model = model
self.fields = {}
self.create_ui()
self.show()
def create_ui(self):
self.pack_start(self.create_table())
def create_table(self):
attributes = self.orm_model.get_attr_names()
rows = 5
cols = len(attributes) / rows
table = MyTable(rows,cols)
for attr_name in attributes :
label =
self.orm_model.translation_dict.get(attr_name,"No translation found")
check_box = gtk.CheckButton(label)
proxy = proxy_for(check_box)
self.fields[attr_name] = proxy
table.fill_verticaly(check_box)
return table
def get_selected_fields(self):
"""
"""
return dict([(field_name,field.read()) for (field_name, field) in
self.fields.iteritems()])
class AssistantPage(gtk.VBox):
"""
To be appended to an assistant. These pages hold a reference to the
assistant to :
1. Configure themselves (title, complete, type)
2. Share a state b/w pages (user input)
"""
def __init__(self,assistant):
"""
"""
gtk.VBox.__init__(self)
self.assistant = assistant
def prepare(self):
"""
"""
pass
class IntroductionPage(AssistantPage):
"""
"""
def __init__(self,assistant):
"""
"""
AssistantPage.__init__(self,assistant)
label = gtk.Label("Cet assistant va vous aider à tirer un état de la
situtation.\nVeuillez suivre les étapes en cliquant sur le bouton suivant.")
self.pack_start(label,padding=20)
def configure(self):
"""
"""
self.assistant.set_page_title(self,"Bienvenu dans l'assistant d'export")
self.assistant.set_page_complete(self,True)
self.assistant.set_page_type(self,gtk.ASSISTANT_PAGE_INTRO)
class SelectModelAttrPage(AssistantPage):
"""
"""
def __init__(self,assistant):
"""
"""
AssistantPage.__init__(self,assistant)
self.form = SelectModelAttrForm(Media)
label = gtk.Label("Veuillez selectionner les colonnes à exporter")
self.pack_start(label,padding=20)
self.pack_start(self.form,padding=20)
def configure(self):
self.assistant.set_page_title(self,"Champs à exporter")
self.assistant.set_page_type(self,gtk.ASSISTANT_PAGE_CONTENT)
self.assistant.set_page_complete(self,True)
class LastStep(AssistantPage):
"""
"""
def __init__(self,assistant):
"""
"""
AssistantPage.__init__(self,assistant)
text = """La configuration de l'export est terminée.\nCliquer sur le
bouton fermer pour exporter les données."""
label = gtk.Label(text)
self.pack_start(label,padding=20)
def configure(self):
"""
"""
self.assistant.set_page_title(self,"Configuration terminée")
self.assistant.set_page_type(self,gtk.ASSISTANT_PAGE_CONFIRM)
self.assistant.set_page_complete(self,True)
def prepare(self):
"""
"""
myindex = self.assistant.get_current_page()
form_page = self.assistant.get_children()[myindex-1]
self.assistant._state["selected_fields"] =
form_page.form.get_selected_fields()
class Main(gtk.Assistant):
def __init__(self):
"""
"""
gtk.Assistant.__init__(self)
# self.state is already taken by gtk.Widget. It's a readonly property
and this is sick.
# See API documentation on gtk.Widget
self._state = {}
self.create_pages()
self.connect_signals()
def prepare(self,widget,page):
"""
"""
page.prepare()
def create_pages(self):
for Page in [IntroductionPage,SelectModelAttrPage,LastStep]:
page = Page(self)
self.append_page(page)
page.configure()
def connect_signals(self):
self.connect("apply",self.export)
self.connect("prepare",self.prepare)
def export(self,widget):
print "export : state is ",self._state
self.destroy()
mw = Main()
mw.show_all()
gtk.main()
# This line is not printed
print "seg fault ?"
gtk.main_quit()
</code>
--- On Wed, 8/18/10, chaouche yacine <[email protected]> wrote:
> From: chaouche yacine <[email protected]>
> Subject: [pygtk] Best way to collect data from an Assistant page
> To: [email protected]
> Date: Wednesday, August 18, 2010, 4:27 AM
> Hello,
>
> <pseudo-code>
>
> welcome = FirstPage()
> form = SecondPage()
> thankx = LastPage()
>
> wizard = Assistant()
> wizard.add(welcom,form,thanks)
>
> </pseudo-code>
>
> When the user is at the SecondPage, which is a form, and
> then clicks on the next button, I wish to retrieve the forms
> data.
>
> the prepare signal that is triggered will give me a
> reference to the LastPage, where the data is lost. I wish to
> have a reference to the SecondPage (form), to do something
> like : page.save_date().
>
>
> Here's my real code :
>
> <code>
> #-*-encoding:utf-8-*-
> # From #pida
> # <aa_> ok, first direction, never use import pygtk
> # <aa_> pygtk.require("2.0")
>
> import gtk
>
> from coriolis.models import Media
> from pygtkhelpers.proxy import proxy_for
>
> class MyTable(gtk.Table):
> def __init__(self,*args,**kw):
> """
> """
>
> gtk.Table.__init__(self,*args,**kw)
> self.actual_col = 0
> self.actual_row = 0
> self.set_col_spacings(5)
> self.set_row_spacings(5)
>
> def fill_verticaly(self,widget):
> """
> Fill the table column by
> column
> """
> if self.actual_row >=
> self.get_property("n-rows"):
> self.actual_col
> += 1
>
> self.actual_row = 0
>
>
> self.attach(widget,self.actual_col,self.actual_col+1,self.actual_row,self.actual_row+1)
> self.actual_row += 1
>
> class SelectModelAttrForm(gtk.VBox):
> def __init__(self,model):
> """
> """
> gtk.VBox.__init__(self)
> self.orm_model = model
>
> self.fields = {}
> self.create_ui()
> self.show()
>
> def create_ui(self):
>
> self.pack_start(self.create_table())
>
>
> def create_table(self):
> attributes =
> self.orm_model.get_attr_names()
> rows
> = 5
> cols
> = len(attributes) / rows
> table
> = MyTable(rows,cols)
> for attr_name in attributes :
> label
> =
> self.orm_model.translation_dict.get(attr_name,"No
> translation found")
> check_box
> =
> gtk.CheckButton(label)
> proxy
> =
> proxy_for(check_box)
>
> self.fields[attr_name] = proxy
>
> table.fill_verticaly(check_box)
>
> return table
>
> def get_selected_fields(self):
> """
> """
> return
> dict([(field_name,field.read()) for field_name, field in
> field.iteritems()])
>
> class AssistantPage(gtk.VBox):
> """
> To be appended to an assistant. These pages
> hold a reference to the assistant to :
> 1. Configure themselves (title, complete,
> type)
> 2. Share a state b/w pages (user input)
> """
> def __init__(self,assistant):
> """
> """
> gtk.VBox.__init__(self)
> self.assistant = assistant
>
> def prepare(self):
> """
> """
> pass
>
> class IntroductionPage(AssistantPage):
> """
> """
> def __init__(self,assistant):
> """
> """
>
> AssistantPage.__init__(self,assistant)
> label = gtk.Label("Cet
> assistant va vous aider à tirer un état de la
> situtation.\nVeuillez suivre les étapes en cliquant sur le
> bouton suivant.")
>
> self.pack_start(label,padding=20)
>
> def configure(self):
> """
> """
>
> self.assistant.set_page_title(self,"Bienvenu dans
> l'assistant d'export")
>
> self.assistant.set_page_complete(self,True)
>
> self.assistant.set_page_type(self,gtk.ASSISTANT_PAGE_INTRO)
>
>
> class SelectModelAttrPage(AssistantPage):
> """
> """
> def __init__(self,assistant):
> """
> """
>
> AssistantPage.__init__(self,assistant)
>
> self.form =
> SelectModelAttrForm(Media)
> label = gtk.Label("Veuillez
> selectionner les colonnes à exporter")
>
> self.pack_start(label,padding=20)
>
> self.pack_start(self.form,padding=20)
>
> def configure(self):
>
> self.assistant.set_page_title(self,"Champs à exporter")
>
> self.assistant.set_page_type(self,gtk.ASSISTANT_PAGE_CONTENT)
>
> self.assistant.set_page_complete(self,True)
>
> def prepare(self):
> """
> """
>
> self.assistant._state["selected_fields"] =
> self.form.get_selected_fields()
>
> class LastStep(AssistantPage):
> """
> """
> def __init__(self,assistant):
> """
> """
>
> AssistantPage.__init__(self,assistant)
> text = """La configuration de
> l'export est terminée.\nCliquer sur le bouton fermer pour
> exporter les données."""
> label = gtk.Label(text)
>
> self.pack_start(label,padding=20)
>
> def configure(self):
> """
> """
>
> self.assistant.set_page_title(self,"Configuration
> terminée")
>
> self.assistant.set_page_type(self,gtk.ASSISTANT_PAGE_CONFIRM)
>
> self.assistant.set_page_complete(self,True)
>
>
> class Main(gtk.Assistant):
> def __init__(self):
> """
> """
> gtk.Assistant.__init__(self)
> # self.state is already taken
> by gtk.Widget. It's a readonly property.
> # See API documentation on
> gtk.Widget
> self._state = {}
> self.create_pages()
> self.connect_signals()
>
> def create_pages(self):
> for Page in
> [IntroductionPage,SelectModelAttrPage,LastStep]:
> page =
> Page(self)
>
> self.append_page(page)
> page.configure()
>
> def connect_signals(self):
>
> self.connect("apply",self.export)
> # WRONG. This will call
> self.next_page with the next page, not the actual page.
> # I need something like a
> "next" signal wich gives me a reference to the actual page.
>
> self.connect("prepare",self.next_page)
>
> def next_page(self,widget,page):
> """
> """
> page.prepare()
>
> def export(self,widget):
> print "export : state is
> ",self._state
>
> mw = Main()
>
> mw.show_all()
> gtk.main()
> </code>
>
>
>
> _______________________________________________
> pygtk mailing list [email protected]
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
>
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/