#!/usr/bin/python


import wx

class Frame1(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)

        self.panel1 = wx.Panel(id=1, name='panel1', parent=self,
              pos=wx.Point(16, 8), size=wx.Size(344, 192),
              style=wx.TAB_TRAVERSAL)
        
        self.button1 = wx.Button(id=3, label='open frame',
              name='button1', parent=self.panel1, pos=wx.Point(304, 16),
              size=wx.Size(75, 23), style=0)
        self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
              id=3)

        self.listCtrl1 = wx.ListCtrl(id=4, name='listCtrl1',
              parent=self.panel1, pos=wx.Point(56, 40), size=wx.Size(248, 152),
              style=wx.LC_REPORT)
        self.listCtrl1.Bind(wx.EVT_LIST_ITEM_SELECTED,
              self.OnListCtrl1ListItemSelected, id=4)
        self.listCtrl1.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK,
              self.OnListCtrl1ListItemRightClick, id=4)
        self.listCtrl1.Bind(wx.EVT_LEFT_DOWN, self.OnListCtrl1LeftDown)
        self.listCtrl1.Bind(wx.EVT_LEFT_UP, self.OnListCtrl1LeftUp)

        self.initialization()
        
       
    def initialization(self):
        
        self.listCtrl1.ClearAll() 

        self.listCtrl1.InsertColumn(0, 'id', format = 
        wx.LIST_FORMAT_LEFT, width = 20) 
        self.listCtrl1.InsertColumn(1, 'Vorname', format = 
        wx.LIST_FORMAT_LEFT, width = 90)
        self.listCtrl1.InsertColumn(2, 'Nachname', format = 
        wx.LIST_FORMAT_LEFT, width = 90)
        
        self.listCtrl1.InsertStringItem(0, 'asdf')
        self.listCtrl1.SetStringItem(0, 0, '2')
        self.listCtrl1.SetStringItem(0, 1, 'hello')
        self.listCtrl1.SetStringItem(0, 2, 'world')
        

    def OnButton1Button(self, event):
        myFrame2 = Frame2(self)
        myFrame2.Show()


    def OnListCtrl1ListItemSelected(self, event):
        itemSelected = event.m_itemIndex
        itemSelected_products_id = self.listCtrl1.GetItem(itemSelected,0)
        products_id = itemSelected_products_id.GetText()
        print products_id 
        
        myFrame2 = Frame2(self)
        myFrame2.Show()
        event.Skip()
        

    def OnListCtrl1ListItemRightClick(self, event):
        myFrame2 = Frame2(self)
        myFrame2.Show()


    def OnListCtrl1LeftDown(self, event):
        print 'down'
        event.Skip()

    def OnListCtrl1LeftUp(self, event):
        print 'up'
        myFrame2.SetFocus()
        myFrame2.Raise()
        event.Skip()


class Frame2(wx.Frame):
    def __init__(self, parent, id=wx.ID_ANY, title=wx.EmptyString,
                 pos=wx.DefaultPosition, size=wx.DefaultSize,
                 style=wx.DEFAULT_FRAME_STYLE, name='frame2'):
        wx.Frame.__init__(self, parent, id, title, pos, size, style, name)
        

        self.panel1 = wx.Panel(id=1, name='panel1', parent=self,
              pos=wx.Point(16, 8), size=wx.Size(344, 192),
              style=wx.TAB_TRAVERSAL)
        
        self.staticText1 = wx.StaticText(id=2,
              label='me is frame 2', name='staticText1', parent=self.panel1,
              pos=wx.Point(120, 88), size=wx.Size(65, 13), style=0)
              
                    
        
if __name__ == '__main__':
    app = wx.App()
    main = Frame1(None)
    main.Show()
    app.MainLoop()

