Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 19th, 2012, 01:47 AM
gokulkumargopal gokulkumargopal is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 5 gokulkumargopal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 32 m 54 sec
Reputation Power: 0
List assignment in ComboBox not working

Hello,

I am trying to create a combobox and set values using output of a query executed in Oracle database.

On assigning the list in combobox.SetItems(list), I get the following error..

TypeError: String or Unicode type required

However, if I cast the input as str ie., combobox.SetItems(str(list)), the output I see in the combobox is wierd.

If the output of the query is
5
4

The combobox displays
[
5
,
4
]

How to assign a list to the combobox ?

Code:
import wx
import cx_Oracle

class PerfFrame(wx.Frame):
    def __init__(self,parent,title):
        frame = wx.Frame.__init__(self,parent,title=title, size=(500, 500))  
        self.panel = wx.Panel(frame) 
        lbl_InstanceID  = wx.StaticText(self, -1, "Values List")
        self.combobox1 = wx.ComboBox(self, 1,  style=wx.CB_DROPDOWN,  pos=wx.Point(100, 30),  choices=[])
        self.combobox1.SetSelection(0)
        lst=[]
        new_list=[]
        lst=self.populate_instanceid()
        for i in lst:
            new_list.append(i)
        self.combobox1.SetItems(new_list)
        self.Show()

    def populate_instanceid(self):
        con=cx_Oracle.connect ("Connection String")
        curs=con.cursor()
        curs.execute("select to_number(inst_id) from gv$instance")
        inst_list=[]
        for row in curs.fetchall()[0]:
            inst_list.append(row)
        return inst_list

app=wx.App(False)
frame=PerfFrame(None,"Perf")
app.SetTopWindow(frame)
app.MainLoop()


Rgds,
Gokul

Reply With Quote
  #2  
Old October 19th, 2012, 06:11 AM
SuperOscar SuperOscar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Location: Joensuu, Finland
Posts: 412 SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 7 h 25 m 55 sec
Reputation Power: 65
Quote:
Originally Posted by gokulkumargopal
How to assign a list to the combobox ?


SetItems() method is the way, so I think you need to check what the populate_instance() method is returning. Simply insert debugging lines like “print(inst_list)”, “print(type(inst_list))”, “print([item for item in inst_list])” as necessary and see what you got in the console.
__________________
My armada: openSUSE 12.3 (home desktop, laptop, work desktop), Ubuntu 12.04 LTS (mini laptop), Debian GNU/Linux 7.0 (server), Mythbuntu 12.04 LTS (HTPC), Bodhi Linux 2.0 & Windows 7 Ultimate (test desktop), FreeBSD 9.1 (test server)

Reply With Quote
  #3  
Old October 19th, 2012, 12:56 PM
gokulkumargopal gokulkumargopal is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 5 gokulkumargopal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 32 m 54 sec
Reputation Power: 0
Solved

Hello,

Thanks for your response.

It appears the values in the choices list must be a set of strings and not integers.

The following code errors..

Code:
self.combobox1 = wx.ComboBox(self, 1,  style=wx.CB_DROPDOWN,  pos=wx.Point(100, 30),  choices=[1,2,3,4,5])


This succeeds..

Code:
self.combobox1 = wx.ComboBox(self, 1,  style=wx.CB_DROPDOWN,  pos=wx.Point(100, 30),  choices=['1','2','3','4','5'])


Rgds,
Gokul

Reply With Quote
  #4  
Old October 19th, 2012, 01:50 PM
SuperOscar SuperOscar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Location: Joensuu, Finland
Posts: 412 SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 7 h 25 m 55 sec
Reputation Power: 65
Quote:
Originally Posted by gokulkumargopal
It appears the values in the choices list must be a set of strings and not integers.


Yes, of course. It’s easy enough to fix, just use list comprehension like:

Code:
choices = [str(choice) for choice in choices]


(using the name you gave in your last example.)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > List assignment in ComboBox not working

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap