473,320 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to quit a dialog within a function ?

56
Dear Friends,
I am working in a python based application. I need an option to go
a page with Dialog >> combobox option. But I could not close the dialog box on the onchange event of combobox. My current function is:

Expand|Select|Wrap|Line Numbers
  1.   def mostrar_combobox(self, titulo, texto_etiqueta, lista):
  2.     """
  3.     Mà© All to show a combobox on screen and get the option chosen
  4.     """
  5.     #print texto_etiqueta
  6.     #dialogo = gtk.Dialog(titulo, None, 0, (gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
  7.     dialogo = gtk.Dialog(titulo, None, 0, None)
  8.     etiqueta = gtk.Label(texto_etiqueta)
  9.     etiqueta.show()
  10.     dialogo.vbox.pack_start(etiqueta)
  11.     combobox = gtk.combo_box_new_text()
  12.     for x in lista:
  13.       combobox.append_text(x)
  14.     combobox.connect('changed', self.changed_cb)
  15.     #combobox.set_active(0)
  16.     combobox.show()
  17.     dialogo.vbox.pack_start(combobox, False)
  18.     dialogo.run()
  19.     elemento_activo = combobox.get_active()
  20.     dialogo.destroy()
  21.  
  22.     return elemento_activo
  23.  
  24.  
Please advise

Thanks
Anes
Mar 1 '16 #1
4 1572
dwblas
626 Expert 512MB
dialogo.destroy() should be in the callback function self.changed_cb (which we don't have so can't comment further).
Mar 1 '16 #2
amskape
56
dear dwlabs,
When I give that option in 'changed_cb' as below:
Expand|Select|Wrap|Line Numbers
  1.   def mostrar_combobox(self, titulo, texto_etiqueta, lista):
  2.     """
  3.     Mà© All to show a combobox on screen and get the option chosen
  4.     """
  5.     #print texto_etiqueta
  6.     #dialogo = gtk.Dialog(titulo, None, 0, (gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
  7.     dialogo = gtk.Dialog(titulo, None, 0, None)
  8.     etiqueta = gtk.Label(texto_etiqueta)
  9.     etiqueta.show()
  10.     dialogo.vbox.pack_start(etiqueta)
  11.     combobox = gtk.combo_box_new_text()
  12.     for x in lista:
  13.       combobox.append_text(x)
  14.     combobox.connect('changed', self.changed_cb)
  15.     #combobox.set_active(0)
  16.     combobox.show()
  17.     dialogo.vbox.pack_start(combobox, False)
  18.     dialogo.run()
  19.     #print response
  20.     #combobox.connect('changed', self.changed_cb)
  21.     elemento_activo = combobox.get_active()
  22.  
  23.     #dialogo.destroy()
  24.     dialogo.hide()
  25.     return elemento_activo
  26.  
  27.   def changed_cb(self, combobox):
  28.     model = combobox.get_model()
  29.     index = combobox.get_active()
  30.     #self.dialogo.destroy()
  31.     if index:
  32.       self.dialogo.destroy()
  33.       print index
  34.       return index
  35.  
  36.  
got error as

self.dialogo.destroy()
AttributeError: Controlador instance has no attribute 'dialogo'

So need an intelligent solution , waiting for it. In my opinion if I remove that 'changed_cb' def no problem in current working of program . That function is really useless ...

Thanks
Anes
Mar 2 '16 #3
dwblas
626 Expert 512MB
The only thing I can do is point you to a tutorial on classes as there are too many things that you don't understand http://www.freenetpages.co.uk/hp/ala...d/tutclass.htm
Mar 2 '16 #4
amskape
56
Dear dwlabs and friends,
I try your code , but still have no solution :(
my code is:

Expand|Select|Wrap|Line Numbers
  1.  def mostrar_combobox(self, titulo, texto_etiqueta, lista):
  2.     """
  3.     Mà© All to show a combobox on screen and get the option chosen
  4.     """
  5.     #print texto_etiqueta
  6.     #dialogo = gtk.Dialog(titulo, None, 0, (gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
  7.     dialogo = gtk.Dialog(titulo, None,  gtk.DIALOG_MODAL, None)
  8.     dialogo.connect('response', lambda *x: self.destroy())
  9.     etiqueta = gtk.Label(texto_etiqueta)
  10.     etiqueta.show()
  11.     dialogo.vbox.pack_start(etiqueta)
  12.     combobox = gtk.combo_box_new_text()
  13.     for x in lista:
  14.       combobox.append_text(x)
  15.     combobox.connect('changed', self.changed_cb)
  16.     combobox.show()
  17.     dialogo.vbox.pack_start(combobox, False)
  18.     response = dialogo.run()
  19.     combobox.connect('changed', self.changed_cb)
  20.     dialogo.emit("delete-event", gtk.gdk.Event(gtk.gdk.DELETE))
  21.     elemento_activo = combobox.get_active()
  22.     return elemento_activo
  23.  
  24.  
  25.   def changed_cb(self, combobox):
  26.     #model = combobox.get_model()
  27.     index = combobox.get_active()
  28.     #self.dialogo.destroy()
  29.     #response = self.dialogo.run()
  30.     if index > -1:
  31.       print index
  32.  
  33.       #return index
  34.  
  35.  
  36.  
Do i have use GtkWindow for this purpose ? if so please provide a sample code..



Thanks
Anes
Mar 3 '16 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Michael | last post by:
Hello Currently I'm migrating an applet from Java 1.1 to 1.3. Targetplattform: Microsoft Internet Explorer 5.x with Sun's Java VM 1.3.1 Problem: The attached applet works fine with the...
12
by: Christopher J. Bottaro | last post by:
I want to get the name of the function from within the function. Something like: def myFunc(): print __myname__ >>> myFunc() 'myFunc' Really what I want to do is to easily strip off the...
5
by: Nils Petter Vaskinn | last post by:
I'm using an enum that's declared within a function (since I only need it within that function.) I can't find anything about this in "The C++ Programming Language" by Stroustroup and I don't...
1
by: Yasutaka Ito | last post by:
Hi, Is there a way to programmatically find out the caller of your function? For example, let's say I have a function called MyFunction(), and I want to debug print the caller of this function...
12
by: AMT2K5 | last post by:
Hello. I have the following function titled cleanSpace that recieves a string and cleans it up. My program passes a string to the function via "cleanSpace(c)". The function works the first time...
2
by: mj | last post by:
Hi, I recently have found it necessary to move from fortran to c++ for scientific programming... I'm working on a program that needs to resize a 2d vector of vectors within a function... This...
4
by: cupa | last post by:
Hi, is it posible to execute script from file within function (sql or pl/sql or ...)
6
by: SanPy | last post by:
The subject of this message might be a little cryptic, so here's an example of what I mean: def foo(): """doc string of foo""" print foo.__doc__ doc string of foo What I want to know is...
2
kaushalparik
by: kaushalparik | last post by:
hi all, i am working with Desktop application, and trying to create a setup project. i finalized my application and now creating the setup for that application. what i need to do is, with in...
1
by: =?Utf-8?B?amZz?= | last post by:
In the last few weeks my arrow keys have quit working in Excel 2003 only. I have changed batteries in both my mouse and keyboard with no results. Has anyone else experienced this problem? The...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.