combobox problem

Hi,

Can somebody help me with the combobox problem.When I start the my GUI application, it should upload all the directories from the path into the combo box.

I created 2 directories in my path. When I run this program, it Sets up one directory and when I click it, it just disappears.

Thanks in advance for the help.

mkdir.py (1.67 KB)

Your program was adding each entry to the combobox as the displayed value
in the textbox but not creating a list for the combobox to hold all the items. So

you only saw the last one added.

You can just append each new entry to a growing list and then use
comboBox.SetItems(list) as below…

import wx
import os, sys
import string
import re
import wx.lib.dialogs

class MyFrame1(wx.Frame):
def init(self, parent, id, title):
wx.Frame.init(self, parent,-1,title,wx.DefaultPosition,wx.Size(450,200))

        self.mainpa = wx.Panel(self,-1,wx.DefaultPosition, wx.DefaultSize)
        self.samplelist = []

        self.combo1= wx.ComboBox(self.mainpa,-1,"",(120,70),(105,-1),self.samplelist,
           wx.CB_DROPDOWN)
        path=os.getcwd()
        for entry in os.listdir(path):
                if os.path.isdir(entry):
                        print 'entry %s' % entry
                        self.samplelist.append(entry)
                        self.combo1.SetItems(self.samplelist)

        ok = wx.Button(self.mainpa, -1, 'Ok',wx.Point(300,100))

class MyApp(wx.App):
def OnInit(self):

    frame = MyFrame1(None, -1, 'Make Directory Structure')
    frame.Show(True)
    self.SetTopWindow(frame)
    return True

app = MyApp(0)
app.MainLoop()

···

On Nov 19, 2007 4:23 PM, Thippana, Prasoonadevi pthippan@mc.com wrote:

Hi,

Can somebody help me with the combobox problem.When I start the my GUI application, it should upload all the directories from the path into the combo box.

I created 2 directories in my path. When I run this program, it Sets up one directory and when I click it, it just disappears.

Thanks in advance for the help.


To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Sorry, not sure. This is something about the os module, which I haven’t used much.

Can someone else on the list help out here?

···

On Nov 20, 2007 4:00 PM, Thippana, Prasoonadevi pthippan@mc.com wrote:

This code is working fine when I created new directories and run this program. But when I change the path instead of path = os.getcwd(), I gave path="C:\Python25", it is not loading all the directories under that path. But when I create new directory like “test” in the path C:\Python25, it just loads only “test” directory into the combobox and ignores the other directories. Can you tell me what the problem will be?

Thanks

Kaufman, Duane ha scritto:

>> path="C:\Python25\"

SyntaxError: EOL while scanning single-quoted string
Please send a runnable example of what you are trying to do....who knows, perhaps in making the example, you'll find the bug!

Backslash ("\") is the escape character in python. That means that the character after the '\' is intended with the value of the character itself (for example, '\P' means 'P' or '\"' means '"'). If you want to pass the backslash character in a string you have to write it twice ("\\") or defining the string as raw putting an 'r' before the apex.

In your example:

path = "C:\\Python25\\"

or

path = r"C:\Python25\"

···

--
Simone
Chiacchiera con i tuoi amici in tempo reale! Yahoo fa parte della famiglia di brand Yahoo.

Simone wrote:

In your example:

path = "C:\\Python25\\"

or

path = r"C:\Python25\"

or use the other slash:

path = "C:/Python25/"

Windows will understand that too.

Even better, use the os.path.join to build your path, and have something more cross-platform.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

I tried os.path.join also. It didn't work.

-Prasoona

···

-----Original Message-----
From: Christopher Barker [mailto:Chris.Barker@noaa.gov]
Sent: Wednesday, November 21, 2007 11:47 AM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] combobox problem

Simone wrote:

In your example:

path = "C:\\Python25\\"

or

path = r"C:\Python25\"

or use the other slash:

path = "C:/Python25/"

Windows will understand that too.

Even better, use the os.path.join to build your path, and have something
more cross-platform.

-Chris

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org