[gelöst] Darstellung im wx.SplitterWindow

Plattformunabhängige GUIs mit wxWidgets.
Antworten
Benutzeravatar
Mawilo
User
Beiträge: 452
Registriert: Sonntag 22. Februar 2004, 10:58
Wohnort: Sachsen
Kontaktdaten:

Hallo,

ich habe eine Oberfläche mit wx.SplitterWindow erstellt. Im oberen Fenster kann ich Elemente anordnen. Im unteren Fenster gelingt mir das nicht. Dort habe ich noch zusätzlich ein Scrollfenster draufgelegt.

Warum wird im unteren Fenster der Testeintrag nicht richtig dargestellt?

Code: Alles auswählen

#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-

import wx

wx.SetDefaultPyEncoding("iso-8859-15")

class MainFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, 'Eingabe', size=(800, 700))
        self.menuBar()
        self.spWindow = wx.SplitterWindow(self)
        scr = wx.ScrolledWindow(self.spWindow, -1)
        scr.SetScrollbars(1, 1, 700, 1000)
        self.top_w = wx.Panel(self.spWindow, style=wx.SUNKEN_BORDER)
        self.bottom_w = wx.Panel(scr, style=wx.SUNKEN_BORDER)
        self.spWindow.Initialize(self.top_w)
        self.spWindow.Initialize(self.bottom_w)
        self.spWindow.SetMinimumPaneSize(10)
        self.spWindow.SplitHorizontally(self.top_w, scr, 180)
        self.selectMask()
        self.enterMask()

    def menuBar(self):
        menubar = wx.MenuBar()
        mFile = wx.Menu()
        menubar.Append(mFile, 'Datei')
        mWork = wx.Menu()
        totake = mWork.Append(wx.NewId(), u'Übernehmen')
        self.Bind(wx.EVT_MENU, None, totake)
        menubar.Append(mWork, 'Bearbeiten')
        self.SetMenuBar(menubar)

    def selectMask(self):
        bordersizer = wx.BoxSizer(wx.HORIZONTAL)
        self.top_w.SetSizer(bordersizer)
        gsizer = wx.GridBagSizer(hgap=10, vgap=10)
        bordersizer.Add(gsizer, 1, wx.EXPAND | wx.ALL, 8)
        size = (200, 25)

        lb_project = wx.StaticText(self.top_w, -1, 'Projekt:')
        gsizer.Add(lb_project, pos=(0, 0), flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        projects = ['', 'Alpha', 'Beta', 'Gamma']
        selectProject = wx.Choice(self.top_w, -1, size=size, choices=projects)
        gsizer.Add(selectProject, pos=(0, 1), flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)

        lb_period = wx.StaticText(self.top_w, -1, 'Periode:')
        gsizer.Add(lb_period, pos=(1, 0), flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        periods = ['', '1a W', '1a S', '1a SF', '2 W']
        selectPeriod = wx.Choice(self.top_w, -1, size=size, choices=periods)
        gsizer.Add(selectPeriod, pos=(1, 1), flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)

        lb_base = wx.StaticText(self.top_w, -1, 'Orte:')
        gsizer.Add(lb_base, pos=(2, 0), flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        bases = ['', 'Ort1', 'Ort2']
        selectBase = wx.Choice(self.top_w, -1, size=size, choices=bases)
        gsizer.Add(selectBase, pos=(2, 1), flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)

        lb_function = wx.StaticText(self.top_w, -1, 'Funktion:')
        gsizer.Add(lb_function, pos=(0, 2), flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        functions = ['', 'F1', 'F2']
        selectFunction = wx.Choice(self.top_w, -1, size=size, choices=functions)
        gsizer.Add(selectFunction, pos=(0, 3), flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)

        lb_valid = wx.StaticText(self.top_w, -1, 'Gültigkeit:')
        gsizer.Add(lb_valid, pos=(1, 2), flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        chkboxsizer = wx.GridSizer(rows=2, cols=7)
        lb_mo = wx.StaticText(self.top_w, -1, 'Mo')
        chkboxsizer.Add(lb_mo, 0, wx.ALIGN_BOTTOM | wx.ALIGN_CENTER_HORIZONTAL)
        lb_tu = wx.StaticText(self.top_w, -1, 'Di')
        chkboxsizer.Add(lb_tu, 0, wx.ALIGN_BOTTOM | wx.ALIGN_CENTER_HORIZONTAL)
        lb_we = wx.StaticText(self.top_w, -1, 'Mi')
        chkboxsizer.Add(lb_we, 0, wx.ALIGN_BOTTOM | wx.ALIGN_CENTER_HORIZONTAL)
        lb_th = wx.StaticText(self.top_w, -1, 'Do')
        chkboxsizer.Add(lb_th, 0, wx.ALIGN_BOTTOM | wx.ALIGN_CENTER_HORIZONTAL)
        lb_fr = wx.StaticText(self.top_w, -1, 'Fr')
        chkboxsizer.Add(lb_fr, 0, wx.ALIGN_BOTTOM | wx.ALIGN_CENTER_HORIZONTAL)
        lb_sa = wx.StaticText(self.top_w, -1, 'Sa')
        chkboxsizer.Add(lb_sa, 0, wx.ALIGN_BOTTOM | wx.ALIGN_CENTER_HORIZONTAL)
        lb_su = wx.StaticText(self.top_w, -1, 'So')
        chkboxsizer.Add(lb_su, 0, wx.ALIGN_BOTTOM | wx.ALIGN_CENTER_HORIZONTAL)
        mo = wx.CheckBox(self.top_w, -1)
        chkboxsizer.Add(mo, 0, wx.ALIGN_CENTER)
        tu = wx.CheckBox(self.top_w, -1)
        chkboxsizer.Add(tu, 0, wx.ALIGN_CENTER)
        we = wx.CheckBox(self.top_w, -1)
        chkboxsizer.Add(we, 0, wx.ALIGN_CENTER)
        th = wx.CheckBox(self.top_w, -1)
        chkboxsizer.Add(th, 0, wx.ALIGN_CENTER)
        fr = wx.CheckBox(self.top_w, -1)
        chkboxsizer.Add(fr, 0, wx.ALIGN_CENTER)
        sa = wx.CheckBox(self.top_w, -1)
        chkboxsizer.Add(sa, 0, wx.ALIGN_CENTER)
        su = wx.CheckBox(self.top_w, -1)
        chkboxsizer.Add(su, 0, wx.ALIGN_CENTER)
        gsizer.Add(chkboxsizer, pos=(1, 3), flag=wx.ALIGN_LEFT)

        lb_tripnr = wx.StaticText(self.top_w, -1, 'Nummer:')
        gsizer.Add(lb_tripnr, pos=(2, 2), flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        tripnumbers = ['0001', '0002', '0003', '0004']
        selectTrip = wx.ComboBox(self.top_w, -1, '', size=size, choices=tripnumbers)
        gsizer.Add(selectTrip, pos=(2, 3), flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)

        lb_comment = wx.StaticText(self.top_w, -1, 'Kommentar:')
        gsizer.Add(lb_comment, pos=(3, 0), flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        selectComment = wx.TextCtrl(self.top_w, -1, '', size=(400, 25))
        gsizer.Add(selectComment, pos=(3, 1), span=(1, 3), flag=wx.EXPAND)

        return gsizer
    
    def enterMask(self):
        bordersizer = wx.BoxSizer(wx.HORIZONTAL)
        self.bottom_w.SetSizer(bordersizer)
        esizer = wx.FlexGridSizer(rows=10, cols=13, hgap=20, vgap=10)
        bordersizer.Add(esizer, 1, wx.EXPAND | wx.ALL, 8)
        
        t = wx.StaticText(self.bottom_w, -1, 'Das ist ein Testeintrag')
        esizer.Add(t, 0, wx.ALIGN_LEFT)

        return esizer
        
def main():
    app = wx.PySimpleApp()
    frame = MainFrame()
    frame.Show()
    app.MainLoop()

if __name__ == '__main__':
    main()
Mawilo
Zuletzt geändert von Mawilo am Donnerstag 20. Dezember 2007, 14:03, insgesamt 1-mal geändert.
Benutzeravatar
Mawilo
User
Beiträge: 452
Registriert: Sonntag 22. Februar 2004, 10:58
Wohnort: Sachsen
Kontaktdaten:

Ich glaube, ich habe selbst eine Lösung gefunden:

Code: Alles auswählen

class MainFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, 'Eingabe', size=(800, 800))
        self.menuBar()
        self.spWindow = wx.SplitterWindow(self)
        self.top_w = wx.Panel(self.spWindow, -1, style=wx.SUNKEN_BORDER)
        self.bottom_w = wx.ScrolledWindow(self.spWindow, -1, style=wx.SUNKEN_BORDER)
        self.bottom_w.SetScrollbars(1, 1, 700, 1200)
        self.spWindow.Initialize(self.top_w)
        self.spWindow.Initialize(self.bottom_w)
        self.spWindow.SetMinimumPaneSize(10)
        self.spWindow.SplitHorizontally(self.top_w, self.bottom_w, 180)
Ich hatte auf das ScrolledWindow ein Panel gelegt. Das ist nicht nötig, da man ein ScrolledWindow für alle Fälle nehmen kann, für die man sonst ein Panel nimmt. So steht es jedenfalls im Buch. :oops:
Jedenfalls scheint es jetzt zu funktionieren.

Mawilo
Antworten