Interesting problem - wxTextCtrl

fowlertrainer at anonym.hu fowlertrainer at anonym.hu
Mon Mar 29 05:25:34 EST 2004


Hello !

I want to create a tool for mp3 files in wx.

Some sections of the code (see below) is copied from wx demo.

Problems:
1.) the wxStaticText is not centered vertically
2.) the wxTextCtrl is not editable, it is cannot get the focus.
Why ?

My machine OS: winxp.
Python: 2.3,
Wx: for python 2.3

The demo is working, but only my code is not working !
Why ?

Thanx for every help !

FT

PS:
 Please send the answers to my private mail address too, because I'm
 in digest mode.


#!/usr/bin/python
from wxPython.wx import *
from wxPython.grid import *
from freedb import *


class MainFrame(wxFrame):
    def __init__(self, *args, **kwds):
        kwds["style"] = wxDEFAULT_FRAME_STYLE
        wxFrame.__init__(self, *args, **kwds)
        self.AlbumGrid=None
        self.Albums=None
        self.MainSizer=wxBoxSizer(wxVERTICAL)
        self.toppanel = wxPanel(self, -1)
        self.bottompanel = wxPanel(self, -1)
        self.centpanel = wxPanel(self, -1)
        self.toppanel.SetSize((592, 23))
        self.bottompanel.SetSize((592, 24))
        self.MainSizer.Add(self.toppanel,0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL, 0)
        self.MainSizer.Add(self.centpanel,1,wxALL|wxEXPAND,0)
        self.MainSizer.Add(self.bottompanel,1, wxEXPAND|wxALIGN_CENTER_HORIZONTAL, 0)
        self.SetAutoLayout(1)
        self.SetSizer(self.MainSizer)

        self.btnExit = wxButton(self.toppanel, 1220, "Exit")
        EVT_BUTTON(self, 1220, self.Exit)
        self.btnSearch = wxButton(self.toppanel, 1221, "Search")
        EVT_BUTTON(self, 1221, self.OnClickBtn)
        self.Text=wxTextCtrl(self, -1, "Search Text", size=(125, -1))
        self.Text.SetInsertionPoint(0)
        EVT_CHAR(self.Text,self.EvtChar)
        self.Label=wxStaticText(self, -1, "Search:")
        self.Label.SetBackgroundColour(self.toppanel.GetBackgroundColour())
        topsizer = wxBoxSizer(wxHORIZONTAL)
        topsizer.Add(self.Label, 0,wxLEFT|wxHORIZONTAL|wxVERTICAL|wxALIGN_CENTER_VERTICAL,2)
        topsizer.Add(self.Text, 1,wxLEFT|wxHORIZONTAL,2)
        topsizer.Add(self.btnSearch, 1,wxLEFT|wxHORIZONTAL,2)
        topsizer.Add(self.btnExit, 1, wxLEFT|wxHORIZONTAL,2)
        self.toppanel.SetAutoLayout(1)
        self.toppanel.SetSizer(topsizer)
        topsizer.SetSizeHints(self.toppanel)

        self.centersizer=wxBoxSizer(wxHORIZONTAL)
        self.centpanel.SetAutoLayout(1)
        self.centpanel.SetSizer(self.centersizer)
        self.centersizer.SetSizeHints(self.centpanel)

        self.bottomsizer=wxBoxSizer(wxHORIZONTAL)
        self.bottompanel.SetAutoLayout(1)
        self.bottompanel.SetSizer(self.bottomsizer)
        self.bottomsizer.SetSizeHints(self.bottompanel)

        self.Layout()
        self.Centre()
        self.SetTitle("FreeDB Search Dialog")
        _icon = wxEmptyIcon()
        #_icon.CopyFromBitmap(wxBitmap("EXITEML.ico", wxBITMAP_TYPE_ANY))
        #self.SetIcon(_icon)
        self.SetSize((640, 480))
        self.SetBackgroundColour(wxColour(94, 138, 244))
        self.Centre()
        # end wxGlade

    def EvtChar(self, event):
        cc=event.GetKeyCode()
        if (cc==13):
           self.OnClick(None)
           event.Skip()
        #self.log.WriteText('EvtChar: %d\n' % event.GetKeyCode())



    def OnClickBtn(self,event):
        s=self.Text.GetValue()
        import freedb
        albums=freedb.freedb_search('Last Night Another Soldier',criteria="all")
        def sf(a1,a2):
            l1=[a1.artist,a1.title,a1.checksum,a1.versions]
            l2=[a2.artist,a2.title,a2.checksum,a2.versions]
            for i in range(len(l1)):
                s1=str(l1[i]).strip();s2=str(l2[i]).strip()
                if s1<>s1:
                  if s1>s2: return 1
                  else: return -1
            return 0
        albums.sort(sf)
        self.Albums=albums
        self.ShowAlbums()

    def ShowAlbums(self):
        if self.AlbumGrid<>None:
           self.AlbumGrid.Destroy()
           self.AlbumGrid=None
        self.AlbumGrid=grid=wxGrid(self.centpanel,-1)
        albs=self.Albums
        self.AlbumGrid.CreateGrid(len(albs),4)
        EVT_GRID_CELL_LEFT_DCLICK(grid,self.OnSub)
        grid.SetColLabelValue(0,"ID")
        grid.SetColLabelValue(1,"Artist")
        grid.SetColLabelValue(2,"Title")
        grid.SetColLabelValue(3,"Versions")
        grid.SetColSize(0,80)
        grid.SetColSize(1,192)
        grid.SetColSize(2,160)
        grid.SetColSize(3,80)
        for idx in range(len(albs)):
            alb=albs[idx]
            grid.SetCellValue(idx,0,alb.checksum)
            grid.SetCellValue(idx,1,alb.artist)
            grid.SetCellValue(idx,2,alb.title)
            grid.SetCellValue(idx,3,str(alb.versions))
        self.centersizer.Add(self.AlbumGrid,1,wxALL|wxEXPAND,4)
        self.SubGrid=None
        self.SubGrid2=None
        self.centpanel.Layout()

    def OnSub(self,e):
        albs=self.Albums
        r=e.GetRow()
        alb=albs[r]
        self.XAlbum=xalb=alb.load()
        if self.SubGrid<>None: self.SubGrid.Destroy()
        if self.SubGrid2<>None: self.SubGrid2.Destroy()
        self.SubGrid=grid=wxGrid(self.bottompanel,-1)
        self.SubGrid2=grid2=wxGrid(self.bottompanel,-1)
        grid.CreateGrid(len(xalb.tracks),1)
        grid2.CreateGrid(6,1)
        grid.SetColSize(0,128)
        grid.SetColLabelValue(0,"Title")
        grid2.SetRowLabelValue(0,"DiscID")
        grid2.SetRowLabelValue(1,"Artist")
        grid2.SetRowLabelValue(2,"Title")
        grid2.SetRowLabelValue(3,"Versions")
        grid2.SetRowLabelValue(4,"Genre")
        grid2.SetRowLabelValue(5,"Year")
        grid2.SetColLabelValue(0,"Value")
        grid2.SetColSize(0,128)
        #grid.SetColSize(1,192)
        for i in range(len(xalb.tracks)):
            data=str(xalb.tracks[i][0]).strip()
            grid.SetCellValue(i,0,data)
        grid2.SetCellValue(2,0,str(xalb.dtitle))
        grid2.SetCellValue(0,0,str(xalb.discid))
        grid2.SetCellValue(1,0,str(alb.artist))
        grid2.SetCellValue(2,0,str(alb.versions))
        grid2.SetCellValue(5,0,str(xalb.dyear))
        grid2.SetCellValue(4,0,str(xalb.dgenre))
        self.bottomsizer.Add(grid2,1,wxALL|wxEXPAND,4)
        self.bottomsizer.Add(grid,1,wxALL|wxEXPAND,4)
        self.bottompanel.Layout()
        e.Skip()

    def Exit(self,e):
        self.Destroy()


# end of class MyFrame


class FDApplication(wxApp):
    def __init__(self,Param,MainFrameClass):
        self.MainFrameClass=MainFrameClass
        wxApp.__init__(self,Param)
        self.MainFrameClass.Application=self
    def OnInit(self):
        wxInitAllImageHandlers()
        MainFrame=self.MainFrameClass(None, -1, "")
        #MainFrame=self.MainFrame
        #print MainFrame
        self.SetTopWindow(MainFrame)
        MainFrame.ID=-1
        MainFrame.Show(1)
        return 1


if __name__ == "__main__":
   app=FDApplication(0,MainFrame)
   app.MainLoop()


  

-- 
Best regards,
 fowlertrainer                          mailto:fowlertrainer at anonym.hu





More information about the Python-list mailing list