Seite 1 von 1

Sizer höhe einstellen

Verfasst: Donnerstag 7. Juni 2012, 12:55
von Zwiebel
Hallo Python Gemeinde!

Folgende Situation:
Ich habe ein Panel mit 2 Sizer und einem ListCtrl Feld.
Der Aufbau ist Vertikal gestaltet. Zuerst ein GridSizer dann das ListCtrl und zum Schluss das zweite GridSizer.
Funktioniert auch soweit ganz gut. Lediglich stört mich das Verhältnis der Größen.
Ist es möglich das untere GridSizer(das zweite) ein wenig einzustauchen damit das ListCtrl mehr Platz nach unten hat?
Gäbe es als ansonsten vielleicht eine andere Methode das ganze darzustellen?

Und natürlich kommt noch der (schlecht kommentierte) Quellcode hinterher.

Grüße
Daniel

Edit: Ok habs durch "wildes herumprobieren" gefunden ^^
der zweite parameter entscheidet über den Platz der eingenommen wird.

Code: Alles auswählen

sizer.Add(grid, 1, wx.EXPAND, 0)
sizer.Add(self.lc, 2, wx.EXPAND, 0)
sizer.Add(command, 0, wx.ALL, 0)

Code: Alles auswählen

#!/usr/bin/python
# coding: utf-8
import wx, wx.html
import wx.lib.mixins.listctrl as listmix
import sys

class EditableListCtrl(wx.ListCtrl, listmix.TextEditMixin):
    def __init__(self, parent, ID=wx.ID_ANY, pos=wx.DefaultPosition,
                 size=wx.DefaultSize, style=0):
        wx.ListCtrl.__init__(self, parent, ID, pos, size, style)
        listmix.TextEditMixin.__init__(self)

class Neu(wx.Frame, listmix.TextEditMixin):
    def __init__(self, title, typ):
        wx.Frame.__init__(self,None, -1, title=title, pos=(175,175), size=(300,400))
        panel = wx.Panel(self)
        ##Gemeinsame Felder
        static1 = wx.StaticText(panel, -1, "Firma: ")
        input1 = wx.TextCtrl(panel, -1)
        button1 = wx.Button(panel, -1, label="v")
        static2 = wx.StaticText(panel, -1, "Person: ")
        input2 = wx.TextCtrl(panel, -1)
        button2 = wx.Button(panel, -1, label="v")
        leer1 = wx.StaticText(panel, -1, "")
        leer2 = wx.StaticText(panel, -1, "")
        leer3 = wx.StaticText(panel, -1, "")
        save = wx.Button(panel, -1, label="Speichern")
        self.Bind(wx.EVT_BUTTON, self.OnSave, save)
        command = wx.GridSizer(1, 3, 0, 0)
        grid = wx.GridSizer(2, 3, 0, 0)
        grid.AddMany([  (static1, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL),
                        (input1, 0, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL),
                        (button1, 0, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL),
                        (static2, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL),
                        (input2, 0, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL),
                        (button2, 0, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL)
                    ])
        sizer = wx.BoxSizer(wx.VERTICAL)
        if typ == 1:
            ## Programm
            self.lc = EditableListCtrl(panel, style=wx.LC_REPORT)
            self.lc.InsertColumn(0, 'Datei')
            self.lc.InsertColumn(1, 'MD5-Summe')
            self.lc.SetColumnWidth(0, 75)
            self.lc.SetColumnWidth(1, 210)
            self.lc.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick)
            self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.lc)
            grid.SetRows(6)
            static3 = wx.StaticText(panel, -1, "Datum: ")
            input3 = wx.TextCtrl(panel, -1)
            button3 = wx.Button(panel, -1, label="v")
            static4 = wx.StaticText(panel, -1, "Ablageort: ")
            input4 = wx.TextCtrl(panel, -1)
            button4 = wx.Button(panel, -1, label="v")
            grid.AddMany([  (static3, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL),
                            (input3, 0, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL),
                            (button3, 0, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL),
                            (static4, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL),
                            (input4, 0, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL),
                            (button4, 0, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL)
                        ])
            command.AddMany([   (leer1, 0, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL),
                                (leer2, 0, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL),
                                (save, 0, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL)
                            ])
            
            sizer.Add(grid, 0, wx.EXPAND, 0)
            sizer.Add(self.lc, 1, wx.EXPAND, 0)
            sizer.Add(command, 2, wx.ALL, 0)
            
        elif typ == 2:
            ## Kunde
            sizer.Add(grid, 0, wx.EXPAND, 0)
            sizer.Add(command, 1, wx.EXPAND, 0)
        panel.SetSizer(sizer)
    
    def OnSave(self,event):
        print "save"
    def OnRightClick(self,event):
        if not hasattr(self, "popupID1"):
            self.popupID1 = wx.NewId()
            self.popupID2 = wx.NewId()
            
            self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)
            self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)
            
        Rmenu = wx.Menu()
        Rmenu.Append(self.popupID1, "Add")
        Rmenu.Append(self.popupID2, "Del")

        self.PopupMenu(Rmenu)
        Rmenu.Destroy()
    
    def OnPopupOne(self, event):
        index = self.lc.GetItemCount()
        self.lc.InsertStringItem(index, "Datei")
        self.lc.SetStringItem(index, 1, "MD5")
    def OnPopupTwo(self, event):
        self.lc.DeleteItem(self.currentItem)
    def OnItemSelected(self, event):
        self.currentItem = event.m_itemIndex
        event.Skip()
        
app = wx.App(redirect=True)
top = Neu("neues Programm",1)
top.Show()
app.MainLoop()