Trouble with wxpython when using sizer with checklistbox - python

When I try to use a sizer with the checklist box everything overlaps terribly. My goal is to have the checklistbox on the left and the input fields on the right of the window. I do not know whether the sizer is the solution but I thought it should offer a way to keep the checklistbox on the left and the input fields on the right. Ideally I would also have the ok button and cancel button centered underneath everything else.
import wx
import wx.lib.scrolledpanel
class MyForm(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, title='My Form')
# Add a panel so it looks correct on all platforms
self.panel = wx.Panel(self, wx.ID_ANY)
# panel2 = wx.lib.scrolledpanel.ScrolledPanel(self,-1, size=(200,400), pos=(0,28), style=wx.SIMPLE_BORDER)
# panel2.SetupScrolling()
# bmp = wx.ArtProvider.GetBitmap(wx.ART_INFORMATION, wx.ART_OTHER, (16, 16))
# titleIco = wx.StaticBitmap(self.panel, wx.ID_ANY, bmp)
title = wx.StaticText(self.panel, wx.ID_ANY, 'My Title')
# bmp = wx.ArtProvider.GetBitmap(wx.ART_TIP, wx.ART_OTHER, (16, 16))
# inputOneIco = wx.StaticBitmap(self.panel, wx.ID_ANY, bmp)
labelOne = wx.StaticText(self.panel, wx.ID_ANY, 'Input 1')
inputTxtOne = wx.TextCtrl(self.panel, wx.ID_ANY, '')
# inputTwoIco = wx.StaticBitmap(self.panel, wx.ID_ANY, bmp)
labelTwo = wx.StaticText(self.panel, wx.ID_ANY, 'Input 2')
inputTxtTwo = wx.TextCtrl(self.panel, wx.ID_ANY,'')
# inputThreeIco = wx.StaticBitmap(self.panel, wx.ID_ANY, bmp)
# labelThree = wx.StaticText(self.panel, wx.ID_ANY, 'Input 3')
# inputTxtThree = wx.TextCtrl(self.panel, wx.ID_ANY, '')
# inputFourIco = wx.StaticBitmap(self.panel, wx.ID_ANY, bmp)
# labelFour = wx.StaticText(self.panel, wx.ID_ANY, 'Input 4')
# inputTxtFour = wx.TextCtrl(self.panel, wx.ID_ANY, '')
okBtn = wx.Button(self.panel, wx.ID_ANY, 'OK')
cancelBtn = wx.Button(self.panel, wx.ID_ANY, 'Cancel')
self.Bind(wx.EVT_BUTTON, self.onOK, okBtn)
self.Bind(wx.EVT_BUTTON, self.onCancel, cancelBtn)
finalSizer = wx.BoxSizer(wx.HORIZONTAL)
topSizer = wx.BoxSizer(wx.VERTICAL)
titleSizer = wx.BoxSizer(wx.HORIZONTAL)
inputOneSizer = wx.BoxSizer(wx.HORIZONTAL)
inputTwoSizer = wx.BoxSizer(wx.HORIZONTAL)
checkSizer = wx.BoxSizer(wx.HORIZONTAL)
# inputThreeSizer = wx.BoxSizer(wx.HORIZONTAL)
# inputFourSizer = wx.BoxSizer(wx.HORIZONTAL)
btnSizer = wx.BoxSizer(wx.HORIZONTAL)
# titleSizer.Add(titleIco, 0, wx.ALL, 5)
titleSizer.Add(title, 0, wx.ALL, 5)
# inputOneSizer.Add(inputOneIco, 0, wx.ALL, 5)
inputOneSizer.Add(labelOne, 0, wx.ALL, 5)
inputOneSizer.Add(inputTxtOne, 1, wx.ALL|wx.EXPAND, 5)
# inputTwoSizer.Add(inputTwoIco, 0, wx.ALL, 5)
inputTwoSizer.Add(labelTwo, 0, wx.ALL, 5)
inputTwoSizer.Add(inputTxtTwo, 1, wx.ALL|wx.EXPAND, 5)
# inputThreeSizer.Add(inputThreeIco, 0, wx.ALL, 5)
# inputThreeSizer.Add(labelThree, 0, wx.ALL, 5)
# inputThreeSizer.Add(inputTxtThree, 1, wx.ALL|wx.EXPAND, 5)
# inputFourSizer.Add(inputFourIco, 0, wx.ALL, 5)
# inputFourSizer.Add(labelFour, 0, wx.ALL, 5)
# inputFourSizer.Add(inputTxtFour, 1, wx.ALL|wx.EXPAND, 5)
sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
'six', 'seven', 'eight', 'nine', 'ten', 'eleven',
'twelve', 'thirteen', 'fourteen']
lb = wx.CheckListBox(self, -1, (10, 10), (200,400), sampleList)
self.Bind(wx.EVT_LISTBOX, self.EvtListBox, lb)
self.Bind(wx.EVT_CHECKLISTBOX, self.EvtCheckListBox, lb)
lb.SetSelection(0)
self.lb = lb
checkSizer.Add(lb, 0, wx.ALL |wx.EXPAND | wx.LEFT, 5)
checkSizer.Add(wx.StaticLine(self.panel), 0, wx.ALL|wx.EXPAND, 5)
btnSizer.Add(okBtn, 0, wx.ALL, 5)
btnSizer.Add(cancelBtn, 0, wx.ALL, 5)
topSizer.Add(titleSizer, 0, wx.CENTER)
# topSizer.Add(wx.StaticLine(self.panel,), 0, wx.ALL|wx.EXPAND, 5)
topSizer.Add(inputOneSizer, 0, wx.ALL|wx.EXPAND | wx.RIGHT, 5)
topSizer.Add(inputTwoSizer, 0, wx.ALL|wx.EXPAND | wx.RIGHT, 5)
# topSizer.Add(inputThreeSizer, 0, wx.ALL|wx.EXPAND, 5)
# topSizer.Add(inputFourSizer, 0, wx.ALL|wx.EXPAND, 5)
# topSizer.Add(wx.StaticLine(self.panel), 0, wx.ALL|wx.EXPAND, 5)
topSizer.Add(btnSizer, 0, wx.ALL|wx.CENTER, 5)
# finalSizer.Add(lb, proportion=1, flag=wx.TOP | wx.EXPAND | wx.LEFT, border=5)
finalSizer.Add(checkSizer, 1, wx.EXPAND | wx.LEFT, 5)
# finalSizer.Add(inputTwoSizer, 1, wx.EXPAND | wx.LEFT, 5)
finalSizer.Add(topSizer, 1, wx.EXPAND | wx.RIGHT, 5)
self.panel.SetSizer(finalSizer)
finalSizer.Fit(self)
def EvtListBox(self, event):
self.log.WriteText('EvtListBox: %s\n' % event.GetString())
def EvtCheckListBox(self, event):
index = event.GetSelection()
label = self.lb.GetString(index)
status = 'un'
if self.lb.IsChecked(index):
status = ''
self.log.WriteText('Box %s is %schecked \n' % (label, status))
self.lb.SetSelection(index) # so that (un)checking also selects (moves the highlight)
def onOK(self, event):
# Do something
print 'onOK handler'
def onCancel(self, event):
self.closeProgram()
def closeProgram(self):
self.Close()
# Run the program
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = MyForm().Show()
# import wx.lib.inspection
# wx.lib.inspection.InspectionTool().Show()
app.MainLoop()

I have found its easier to seperate out concerns
import wx
import wx.lib.scrolledpanel
class SizerMixin:
def _hz(self,*widgets):
sz = wx.BoxSizer(wx.HORIZONTAL)
sz.AddMany(widgets)
return sz
def _label(self,label_text,*widgets,**kwargs):
label_size = kwargs.pop("label_size",100)
return self._hz(
(wx.StaticText(self,-1,label_text,size=(label_size,-1)),0,wx.ALIGN_CENTER_VERTICAL),
*widgets)
class MainPanel(wx.Panel,SizerMixin):
def __init__(self,parent):
wx.Panel.__init__(self,parent,-1)
self.CreateWidgets()
self.SetSizer(self.DoLayout())
self.Fit()
def DoLayout(self):
sb = wx.StaticBox(self,-1,"Main Title")
sz = wx.StaticBoxSizer(sb,wx.VERTICAL)
title = wx.StaticText(self,-1,"A Title Goes Here")
sz.Add(title,0,wx.ALIGN_CENTER|wx.EXPAND)
sz.Add(wx.StaticLine(self,-1),0,wx.EXPAND,5) #seperator
body_sizer = wx.BoxSizer(wx.HORIZONTAL)
rightSideInputs = wx.BoxSizer(wx.VERTICAL)
rightSideInputs.Add(self._label("Input 1:",self._widgets["input1"]),0,wx.EXPAND|wx.ALL,5)
rightSideInputs.Add(self._label("Input 2:",self._widgets["input2"]),0,wx.EXPAND|wx.ALL,5)
body_sizer.Add(self._widgets["checklist"],1,wx.EXPAND)
body_sizer.Add(rightSideInputs,1,wx.EXPAND)
sz.Add(body_sizer)
button_sizer = wx.StdDialogButtonSizer()
ok_btn = wx.Button(self,wx.ID_OK)
cancel_btn = wx.Button(self,wx.ID_CANCEL)
button_sizer.AddButton(ok_btn)
button_sizer.AddButton(cancel_btn)
button_sizer.Realize()
sz.Add(button_sizer)
return sz
def CreateWidgets(self):
sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
'six', 'seven', 'eight', 'nine', 'ten', 'eleven',
'twelve', 'thirteen', 'fourteen']
self._widgets = {
"input1":wx.TextCtrl(self,-1),
"input2":wx.TextCtrl(self,-1),
"checklist":wx.CheckListBox(self,-1,choices=sampleList)
}
class MyForm(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, title='My Form')
self.panel = MainPanel(self)
self.Layout()
self.Fit()
def EvtListBox(self, event):
self.log.WriteText('EvtListBox: %s\n' % event.GetString())
def EvtCheckListBox(self, event):
index = event.GetSelection()
label = self.lb.GetString(index)
status = 'un'
if self.lb.IsChecked(index):
status = ''
self.log.WriteText('Box %s is %schecked \n' % (label, status))
self.lb.SetSelection(index) # so that (un)checking also selects (moves the highlight)
def onOK(self, event):
# Do something
print 'onOK handler'
def onCancel(self, event):
self.closeProgram()
def closeProgram(self):
self.Close()
# Run the program
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = MyForm().Show()
# import wx.lib.inspection
# wx.lib.inspection.InspectionTool().Show()
app.MainLoop()

Related

Show matplotlib plot in a wxpython panel and update on button push

I am trying to plot 1D txt files in a part of the window created using wxpython. For this purpose, a directory selection tool was included which lists all txt files. Now, I would like to select a txt file and plot it in a panel on the right side.
Further, I am thinking to implement a button that does some operations on the data and replot again.
What I have tried is this :
import os
import wx
import numpy as np
import matplotlib
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.figure import Figure
class mainFrame (wx.Frame):
def __init__(self):
super().__init__(None, id=wx.ID_ANY, title=u" test ",
size=wx.Size(854, 698),
style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)
self.SetSizeHints(wx.Size(600, -1), wx.DefaultSize)
sizer = wx.BoxSizer(wx.VERTICAL)
self.panel = MainPanel(self, style=wx.TAB_TRAVERSAL)
self.Layout()
sizer.Add(self.panel, 1, wx.EXPAND, 0)
self.SetSizer(sizer)
self.Layout()
self.Centre()
# Connect Events
self.panel.dirPicker.Bind(wx.EVT_DIRPICKER_CHANGED, self.dirPickerOnDirChanged)
self.panel.listBox.Bind(wx.EVT_LISTBOX, self.listBoxOnListBox)
# ------------ Add widget program settings
# ------------ Call Populates
self.Show()
# Virtual event handlers, override them in your derived class
def dirPickerOnDirChanged(self, event):
self.FilePath = event.GetPath()
self.populateFileList()
def populateFileList(self):
self.panel.listBox.Clear()
allFiles = os.listdir(self.FilePath)
for file in allFiles:
if file.endswith('.txt'):
self.panel.listBox.Append(file)
def listBoxOnListBox(self, event):
try:
selected_file = event.GetString()
file_address = os.path.join(self.FilePath, selected_file)
# load file
data = np.loadtxt(file_address)
# select the first column
if isinstance(data, np.ndarray):
print("\tdata is np.array")
dim = data.ndim
if dim == 2:
input1D = data[:, 0]
else:
input1D = data
print(input1D.shape)
# plot here
else:
print("\tdata is not np.array")
except: # Do not use bare except
print("Some error.")
class MainPanel(wx.Panel):
def __init__(self, parent, *args, **kwargs):
super().__init__(parent, *args, **kwargs)
self.FONT_11 = wx.Font(11, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL,
wx.FONTWEIGHT_NORMAL, False, "Consolas")
self.FONT_12 = wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL,
wx.FONTWEIGHT_NORMAL, False, wx.EmptyString)
self.FONT_13 = wx.Font(13, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL,
wx.FONTWEIGHT_NORMAL, False, wx.EmptyString)
self.FONT_14 = wx.Font(14, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL,
wx.FONTWEIGHT_BOLD, False, "Consolas")
self.FONT_16 = wx.Font(16, wx.FONTFAMILY_SCRIPT, wx.FONTSTYLE_NORMAL,
wx.FONTWEIGHT_BOLD, False, wx.EmptyString)
sizer = wx.BoxSizer(wx.VERTICAL)
quick_display = self._quick_display()
directory_sizer = self._directory_sizer()
list_box_sizer = self._list_box_sizer()
self.text_details = self._detail_input()
details_sizer = self._details_sizer()
status_sizer = self._status_sizer()
message_sizer = wx.BoxSizer(wx.VERTICAL)
message_sizer.Add(details_sizer, 1, wx.EXPAND, 5)
message_sizer.Add(status_sizer, 1, wx.EXPAND, 5)
sizer.Add(quick_display, 0, wx.EXPAND, 0)
sizer.Add(directory_sizer, 0, wx.EXPAND, 0)
sizer.Add(list_box_sizer, 1, wx.EXPAND, 0)
sizer.Add(message_sizer, 1, wx.EXPAND, 5)
self.SetSizer(sizer)
def _quick_display(self):
quick_display = wx.StaticText(self, label=u"quick display")
quick_display.Wrap(-1)
quick_display.SetFont(self.FONT_16)
return quick_display
def _directory_sizer(self):
sbSizerDir = wx.StaticBoxSizer(wx.StaticBox(self, label=u" working directory"))
self.dirPicker = wx.DirPickerCtrl(sbSizerDir.GetStaticBox(), message=u"Select a folder")
sbSizerDir.Add(self.dirPicker, 0, wx.ALL | wx.EXPAND, 5)
return sbSizerDir
def _list_box(self):
listBoxChoices = []
self.listBox = wx.ListBox(self, size=wx.Size(300, -1), choices=listBoxChoices)
self.listBox.SetMinSize(wx.Size(250, -1))
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.listBox, 1, wx.ALL, 10)
return sizer
def _plot_sizer(self):
self.panelPlot = PlotPanel(self)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.panelPlot, 1, wx.EXPAND | wx.ALL, 5)
return sizer
def _list_box_sizer(self):
file_list_sizer = self._list_box()
bSizer_plot = self._plot_sizer()
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(file_list_sizer, 1, wx.EXPAND, 0)
sizer.Add(bSizer_plot, 1, wx.EXPAND, 5)
bSizerSplitHor = wx.BoxSizer(wx.HORIZONTAL)
bSizerSplitHor.Add(sizer, 1, wx.EXPAND, 2)
bSizerSplit = wx.BoxSizer(wx.VERTICAL)
bSizerSplit.Add(bSizerSplitHor, 1, wx.EXPAND, 0)
return bSizerSplit
def _detail_label(self):
detail_label = wx.StaticText(self, label="Details")
detail_label.Wrap(-1)
detail_label.SetFont(self.FONT_14)
return detail_label
def _detail_input(self):
text_details = wx.TextCtrl(self, size=wx.Size(250, -1))
text_details.SetFont(self.FONT_11)
return text_details
def _button_sizer(self):
self.button = wx.Button(self, label=u"do some operation")
self.button.SetFont(self.FONT_13)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.button, 0, wx.ALL, 5)
return sizer
def _details_sizer(self):
detail_label = self._detail_label()
button_sizer = self._button_sizer()
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(detail_label, 0, wx.ALL, 5)
sizer.Add(self.text_details, 1, wx.EXPAND, 5)
sizer.Add(button_sizer, 1, wx.EXPAND, 5)
return sizer
def _status_sizer(self):
self.staticline3 = wx.StaticLine(self)
self.status_label = wx.StaticText(self, label=u"Status bar")
self.status_label.Wrap(-1)
self.status_label.SetFont(self.FONT_12)
self.staticline4 = wx.StaticLine(self)
self.textCtrl_status = wx.TextCtrl(self)
self.textCtrl_status.SetFont(self.FONT_11)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.staticline3, 0, wx.EXPAND | wx.ALL, 5)
sizer.Add(self.status_label, 0, wx.ALL, 5)
sizer.Add(self.staticline4, 0, wx.EXPAND | wx.ALL, 5)
sizer.Add(self.textCtrl_status, 0, wx.ALL | wx.EXPAND, 5)
status_sizer = wx.BoxSizer(wx.VERTICAL)
status_sizer.Add(sizer, 1, wx.EXPAND, 5)
return status_sizer
class PlotPanel(wx.Panel):
def __init__(self, parent, *args, **kwargs):
super().__init__(parent, *args, **kwargs)
self.SetMinSize(wx.Size(100, -1))
if __name__ == "__main__":
app = wx.App(False)
frame = mainFrame()
app.MainLoop()
This creates a window as follows :
The right portion is assigned as a panel, and I not sure how to place the matplotlib plot in it. Thank you.
There are several good questions on SE probing this topic, such as Q1 and Q2; however, most are limited to the plot being shown on the main window.
wxGlade includes some wxPython / matplotlib examples. Use these as starting point.
https://github.com/wxGlade/wxGlade/tree/master/examples

Why does this StaticLine appear behind the sizer?

I'm trying to draw a static line between the "Label"+TextCtrl and the radio buttons.
It keeps appearing only when the window is dragged, and then it appears behind everything and I can't figure out why.
The goal is to have the static line draw horizontally between the upper and the lower section.
import wx
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame.__init__
wx.Frame.__init__(self, *args, **kwds)
self.SetSize((237, 237))
self.__initUI()
self.__do_layout()
def __initUI(self):
panel = wx.Panel(self)
self.SetSize((350, 150))
self.qtyField = wx.TextCtrl(panel, wx.ID_ANY, "", style=wx.TE_CENTER)
self.qtyField.SetFocus()
self.longRb = wx.RadioButton(panel, wx.ID_ANY, "This", style=wx.RB_GROUP)
self.shortRb = wx.RadioButton(panel, wx.ID_ANY, "That")
def __do_layout(self):
# begin wxGlade: MyFrame.__do_layout
vertSizer = wx.BoxSizer(wx.VERTICAL)
horSizer1 = wx.GridSizer(1, 2, 0, 0)
rbSizer = wx.GridSizer(1, 2, 0, 36)
qtyLabel = wx.StaticText(self, wx.ID_ANY, "Label")
horSizer1.Add(qtyLabel, 0, wx.ALIGN_CENTER, 0)
horSizer1.Add(self.qtyField, 0, wx.ALIGN_CENTER_VERTICAL, 0)
vertSizer.Add(horSizer1, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM | wx.TOP, 6)
static_line_1 = wx.StaticLine(self, wx.ID_ANY)
vertSizer.Add(static_line_1, 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 6)
rbSizer.Add(self.longRb, 0, wx.ALIGN_CENTER, 0)
rbSizer.Add(self.shortRb, 0, wx.ALIGN_CENTER, 0)
vertSizer.Add(rbSizer, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM | wx.TOP, 6)
self.SetSizer(vertSizer)
class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame(None, wx.ID_ANY, "")
self.SetTopWindow(self.frame)
self.frame.Show()
return True
# end of class MyApp
if __name__ == "__main__":
app = MyApp(0)
app.MainLoop()
Your are assigning some widgets to the Frame (self) and others to the panel, so they present themselves where instructed to do so.
This is what you are after:
import wx
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame.__init__
wx.Frame.__init__(self, *args, **kwds)
self.SetSize((237, 237))
self.__initUI()
self.__do_layout()
def __initUI(self):
self.panel = wx.Panel(self)
self.panel.SetBackgroundColour("green")
self.SetSize((350, 150))
self.qtyField = wx.TextCtrl(self.panel, wx.ID_ANY, "", style=wx.TE_CENTER)
self.qtyField.SetFocus()
self.longRb = wx.RadioButton(self.panel, wx.ID_ANY, "This", style=wx.RB_GROUP)
self.shortRb = wx.RadioButton(self.panel, wx.ID_ANY, "That")
def __do_layout(self):
# begin wxGlade: MyFrame.__do_layout
vertSizer = wx.BoxSizer(wx.VERTICAL)
horSizer1 = wx.GridSizer(1, 2, 0, 0)
rbSizer = wx.GridSizer(1, 2, 0, 36)
qtyLabel = wx.StaticText(self.panel, wx.ID_ANY, "Label")
horSizer1.Add(qtyLabel, 0, wx.ALIGN_CENTER, 0)
horSizer1.Add(self.qtyField, 0, wx.ALIGN_CENTER_VERTICAL, 0)
vertSizer.Add(horSizer1, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM | wx.TOP, 6)
static_line_1 = wx.StaticLine(self.panel, wx.ID_ANY)
vertSizer.Add(static_line_1, 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 6)
rbSizer.Add(self.longRb, 0, wx.ALIGN_CENTER, 0)
rbSizer.Add(self.shortRb, 0, wx.ALIGN_CENTER, 0)
vertSizer.Add(rbSizer, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM | wx.TOP, 6)
self.SetSizer(vertSizer)
class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame(None, wx.ID_ANY, "")
self.SetTopWindow(self.frame)
self.frame.Show()
return True
# end of class MyApp
if __name__ == "__main__":
app = MyApp(0)
app.MainLoop()

Delete item from listBox wxpython

I have this class which deals with listBox:
I tried to make a delete button for listBox items but it didn't work. The "deleteItem" function does now work.Without the marked parts it works good, but there is no delete option. Help someone?
class SettingProcess(wx.Frame):
itemsArr= []
# ----------------------------------------------------------------------
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Black list Proceses",size=(500, 600))
self.Centre()
# Add a panel so it looks the correct on all platforms
panel = wx.Panel(self, wx.ID_ANY,size=(500, 600))
self.index = 0
sizer = wx.FlexGridSizer(cols=2, hgap=6, vgap=6)
lbl_process = wx.StaticText(panel, -1, "Process name")
lbl_process.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
self.txt_processname = wx.TextCtrl(panel, size=(140, -1))
self.txt_processname.SetValue("chrome.exe")
sizer.AddMany([lbl_process, self.txt_processname])
#------------- Files ListBox -------------------------------------
global ProcessListMain
self.files_listBox = wx.ListBox(panel, -1, (12, 130), (200, 240), ProcessListMain,
wx.LB_SINGLE | wx.LB_HSCROLL | wx.LB_ALWAYS_SB | wx.LB_SORT)
self.files_listBox.SetBackgroundColour(wx.Colour(255, 255, 128))
#------------- Set event handlers ---------------------------------
m_start = wx.Button(panel, wx.ID_CLOSE, "Add")
m_start.Bind(wx.EVT_BUTTON, self.OnAddButton)
sizer.Add(m_start, 0, wx.ALL, 10)
m_close = wx.Button(panel, wx.ID_CLOSE, "Close")
m_close.Bind(wx.EVT_BUTTON, self.onExit)
sizer.Add(m_close, 0, wx.ALL, 10)
**m_delete = wx.Button(panel, wx.ID_CLOSE, "Delete")
m_delete.Bind(wx.EVT_BUTTON, self.deleteItem)
sizer.Add(m_delete, 0, wx.ALL, 10)**
panel.SetSizer(sizer)
# ----------------------------------------------------------------------
def OnAddButton(self,str):
global ProcessListMain
#print "value is "+ str(self.txt_processname.GetValue())
ProcessListMain.append(self.txt_processname.GetValue())
self.files_listBox.Set(ProcessListMain)
def onExit(self, event):
self.Destroy()
***def deleteItem(self,event):
numOfItems=self.files_listBox.GetCount()
for i in range(numOfItems):
self.itemsArr[i]=self.files_listBox.GetString()
selectedItems=self.files_listBox.GetStringSelection()
self.files_listBox.clear()
for i in numOfItems :
if self.itemsArr[i]!=selectedItems:
self.files_listBox.append( self.itemsArr[i])***
Here is the version, courtesy of Robin Dunn's comment:
Note that I have also bound the textctrl so that just filling in a process name and pressing Enter, also acts like the Add button.
import wx
class SettingProcess(wx.Frame):
# ----------------------------------------------------------------------
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Black list Processes",size=(500, 600))
self.Centre()
# Add a panel so it looks the correct on all platforms
panel = wx.Panel(self, wx.ID_ANY,size=(500, 600))
self.index = 0
sizer = wx.FlexGridSizer(cols=2, hgap=6, vgap=6)
lbl_process = wx.StaticText(panel, -1, "Process name")
lbl_process.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
self.txt_processname = wx.TextCtrl(panel, size=(140, -1), style=wx.TE_PROCESS_ENTER)
self.txt_processname.SetValue("chrome.exe")
self.txt_processname.Bind(wx.EVT_TEXT_ENTER, self.OnAddButton)
sizer.AddMany([lbl_process, self.txt_processname])
#------------- Files ListBox -------------------------------------
ProcessListMain = ['Process A','Process B','Process C','Process D','Process E']
self.files_listBox = wx.ListBox(panel, -1, (12, 130), (200, 240), ProcessListMain,
wx.LB_SINGLE | wx.LB_HSCROLL | wx.LB_ALWAYS_SB | wx.LB_SORT)
self.files_listBox.SetBackgroundColour(wx.Colour(255, 255, 128))
#------------- Set event handlers ---------------------------------
m_start = wx.Button(panel, -1, "Add")
m_start.Bind(wx.EVT_BUTTON, self.OnAddButton)
sizer.Add(m_start, 0, wx.ALL, 10)
m_close = wx.Button(panel, -1, "Close")
m_close.Bind(wx.EVT_BUTTON, self.onExit)
sizer.Add(m_close, 0, wx.ALL, 10)
m_delete = wx.Button(panel, -1, "Delete")
m_delete.Bind(wx.EVT_BUTTON, self.deleteItem)
sizer.Add(m_delete, 0, wx.ALL, 10)
panel.SetSizer(sizer)
# ----------------------------------------------------------------------
def OnAddButton(self,event):
Addproc = self.txt_processname.GetValue()
if Addproc:
self.files_listBox.Append(Addproc)
def onExit(self, event):
self.Destroy()
def deleteItem(self,event):
deleted_item = self.files_listBox.GetSelection()
self.files_listBox.Delete(deleted_item)
if __name__=='__main__':
app = wx.App()
frame = SettingProcess()
frame.Show()
app.MainLoop()
It's a bit more complicated than having duplicate Id's for your buttons, as I suggested earlier.
Try the following: (I have stuck with your global ProcessListMain but had to mock it up, as it isn't declared in your questions code)
import wx
class SettingProcess(wx.Frame):
itemsArr= []
# ----------------------------------------------------------------------
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Black list Processes",size=(500, 600))
self.Centre()
# Add a panel so it looks the correct on all platforms
panel = wx.Panel(self, wx.ID_ANY,size=(500, 600))
self.index = 0
sizer = wx.FlexGridSizer(cols=2, hgap=6, vgap=6)
lbl_process = wx.StaticText(panel, -1, "Process name")
lbl_process.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
self.txt_processname = wx.TextCtrl(panel, size=(140, -1))
self.txt_processname.SetValue("chrome.exe")
sizer.AddMany([lbl_process, self.txt_processname])
#------------- Files ListBox -------------------------------------
global ProcessListMain
ProcessListMain = ['123','456','789','1123','2123']
self.files_listBox = wx.ListBox(panel, -1, (12, 130), (200, 240), ProcessListMain,
wx.LB_SINGLE | wx.LB_HSCROLL | wx.LB_ALWAYS_SB | wx.LB_SORT)
self.files_listBox.SetBackgroundColour(wx.Colour(255, 255, 128))
#------------- Set event handlers ---------------------------------
m_start = wx.Button(panel, -1, "Add")
m_start.Bind(wx.EVT_BUTTON, self.OnAddButton)
sizer.Add(m_start, 0, wx.ALL, 10)
m_close = wx.Button(panel, -1, "Close")
m_close.Bind(wx.EVT_BUTTON, self.onExit)
sizer.Add(m_close, 0, wx.ALL, 10)
m_delete = wx.Button(panel, -1, "Delete")
m_delete.Bind(wx.EVT_BUTTON, self.deleteItem)
sizer.Add(m_delete, 0, wx.ALL, 10)
panel.SetSizer(sizer)
# ----------------------------------------------------------------------
def OnAddButton(self,event):
global ProcessListMain
Addproc = self.txt_processname.GetValue()
ProcessListMain.append(Addproc)
self.files_listBox.Set(ProcessListMain)
def onExit(self, event):
self.Destroy()
def deleteItem(self,event):
global ProcessListMain
deleted_item = self.files_listBox.GetStringSelection()
numOfItems=self.files_listBox.GetCount()
itemsArr = []
for i in range(numOfItems):
x = self.files_listBox.GetString(i)
if x != deleted_item:
itemsArr.append(x)
ProcessListMain = itemsArr
self.files_listBox.Clear()
self.files_listBox.Set(ProcessListMain)
self.files_listBox.Update()
if __name__=='__main__':
app = wx.App()
frame = SettingProcess()
frame.Show()
app.MainLoop()

wxPython layout using boxsizers

I've recently started using wxPython to build a GUI and I'm trying to create the following layout:
Button1 Button2 Button3
----------------------------------------
listbox | textctrl
The buttons should have a flexible width, expanding to fill the full width of the frame with a border between them (each buttons has a width (incl. border) of 1/3 frame). Their height should be set to a height in pixels.
The listbox should fill the frame vertically and have a set width of x pixels
The textctrol should be a textbox which expands to fill the width of the frame vertically as well as horizontally.
This is the code I have:
mainPanel = wx.Panel(self, -1)
parentBox = wx.BoxSizer(wx.VERTICAL)
menubar = wx.MenuBar()
filem = wx.Menu()
menubar.Append(filem, '&File')
self.SetMenuBar(menubar)
navPanel = wx.Panel(mainPanel, -1, size=(1000, 80))
navBox = wx.BoxSizer(wx.HORIZONTAL)
newSection = wx.Button(navPanel, self.ID_NEW, 'New')
renSection = wx.Button(navPanel, self.ID_RENAME, 'Rename')
dltSection = wx.Button(navPanel, self.ID_DELETE, 'Delete')
navBox.Add(newSection, 1, wx.EXPAND | wx.ALL, 5)
navBox.Add(renSection, 1, wx.EXPAND | wx.ALL, 5)
navBox.Add(dltSection, 1, wx.EXPAND | wx.ALL, 5)
navPanel.SetSizer(navBox)
contentPanel = wx.Panel(mainPanel, -1, size=(1000, 600))
contentBox = wx.BoxSizer(wx.HORIZONTAL)
self.listbox = wx.ListBox(contentPanel, -1, size=(300, 700))
self.settings = wx.TextCtrl(contentPanel, -1)
contentBox.Add(self.listbox, 0)
contentBox.Add(self.settings, 1, wx.EXPAND | wx.ALL, 5)
contentPanel.SetSizer(contentBox)
parentBox.Add(navPanel, 0, wx.EXPAND | wx.ALL, 5)
parentBox.Add(contentPanel, 1, wx.EXPAND | wx.ALL, 5)
mainPanel.SetSizer(parentBox)
Something is going wrong since what I see is not what I expect to see, anybody who can help me out?
It is working for me, I'm on win64, python 32bit 2.7.3.3, wx '2.8.12.1 (msw-unicode)'. The full working test example is:
import wx
class testframe(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'some title')
mainPanel = wx.Panel(self, -1)
parentBox = wx.BoxSizer(wx.VERTICAL)
menubar = wx.MenuBar()
filem = wx.Menu()
menubar.Append(filem, '&File')
self.SetMenuBar(menubar)
navPanel = wx.Panel(mainPanel, -1, size=(1000, 80))
navBox = wx.BoxSizer(wx.HORIZONTAL)
newSection = wx.Button(navPanel, -1, 'New')
renSection = wx.Button(navPanel, -1, 'Rename')
dltSection = wx.Button(navPanel, -1, 'Delete')
navBox.Add(newSection, 1, wx.EXPAND | wx.ALL, 5)
navBox.Add(renSection, 1, wx.EXPAND | wx.ALL, 5)
navBox.Add(dltSection, 1, wx.EXPAND | wx.ALL, 5)
navPanel.SetSizer(navBox)
contentPanel = wx.Panel(mainPanel, -1, size=(1000, 600))
contentBox = wx.BoxSizer(wx.HORIZONTAL)
self.listbox = wx.ListBox(contentPanel, -1, size=(300, 700))
self.settings = wx.TextCtrl(contentPanel, -1)
contentBox.Add(self.listbox, 0, wx.ALL, 5)
contentBox.Add(self.settings, 1, wx.EXPAND | wx.ALL, 5)
contentPanel.SetSizer(contentBox)
parentBox.Add(navPanel, 0, wx.EXPAND | wx.ALL, 5)
parentBox.Add(contentPanel, 1, wx.EXPAND | wx.ALL, 5)
mainPanel.SetSizer(parentBox)
parentBox.Fit(self)
app = wx.PySimpleApp()
app.frame = testframe()
app.frame.Show()
app.MainLoop()
Notice the addition of Fit() of the main sizer, and also 5px border added to the listbox.

Get variables from the GUI in program

first, sorry for my english - im still learning. I´m a student from Germany and i learn Python.
I have a program which needs a lot of paramters for running so i build a gui by wxGlade. Now i want to get this paramters in my application. I saw some things. They used the GUI for editing a INI- File. And the application gets the paramters from these INI. But this is not what i want. I want to controll my application with the GUI.
And it is very Important that i can save my Values in the GUI (so that the User should not do everything again).
Hope you understand what i mean.
Here is my Code for the Gui (not ready but it is enough for doing the first steps)
Here is my GUI Code:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# generated by wxGlade 0.6.8 (standalone edition) on Thu Apr 24 12:36:34 2014
#
import wx
# begin wxGlade: dependencies
import gettext
# end wxGlade
# begin wxGlade: extracode
# end wxGlade
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
# Menu Bar
self.frame_3_menubar = wx.MenuBar()
wxglade_tmp_menu = wx.Menu()
wxglade_tmp_menu.Append(wx.ID_ANY, _("Beenden"), "", wx.ITEM_NORMAL)
self.frame_3_menubar.Append(wxglade_tmp_menu, _("Datei"))
wxglade_tmp_menu = wx.Menu()
self.frame_3_menubar.Append(wxglade_tmp_menu, _("Bearbeiten"))
wxglade_tmp_menu = wx.Menu()
wxglade_tmp_menu.Append(wx.ID_ANY, _("Dokumenationen"), "", wx.ITEM_NORMAL)
self.frame_3_menubar.Append(wxglade_tmp_menu, _("Hilfe"))
self.SetMenuBar(self.frame_3_menubar)
# Menu Bar end
self.frame_3_statusbarr = self.CreateStatusBar(1, 0)
self.kartei = wx.Notebook(self, wx.ID_ANY, style=0)
self.pane_all_settings = wx.Panel(self.kartei, wx.ID_ANY)
self.label_5 = wx.StaticText(self.pane_all_settings, wx.ID_ANY, _("Laufzeiteinstellungen"))
self.label_6 = wx.StaticText(self.pane_all_settings, wx.ID_ANY, _("Abrechnungsjahr"))
self.abr_jahr = wx.SpinCtrl(self.pane_all_settings, wx.ID_ANY, "", min=2000, max=2099, style=wx.SP_ARROW_KEYS | wx.TE_AUTO_URL)
self.label_7 = wx.StaticText(self.pane_all_settings, wx.ID_ANY, _("Abrechnungmonat"))
self.abr_monat = wx.SpinCtrl(self.pane_all_settings, wx.ID_ANY, "", min=1, max=12)
self.label_8 = wx.StaticText(self.pane_all_settings, wx.ID_ANY, _("Payroll"))
self.payroll = wx.ComboBox(self.pane_all_settings, wx.ID_ANY, choices=[_("Loga"), _("Sage"), _("SAP"), _("KidiCap"), _("fidelis Personal")], style=wx.CB_DROPDOWN)
self.label_1 = wx.StaticText(self.pane_all_settings, wx.ID_ANY, _("Mandant"))
self.mandant = wx.SpinCtrl(self.pane_all_settings, wx.ID_ANY, "1", min=0, max=999, style=wx.SP_ARROW_KEYS | wx.TE_AUTO_URL)
self.zuschlag = wx.CheckBox(self.pane_all_settings, wx.ID_ANY, _(u"Zuschl\xe4ge"))
self.fehlzeit = wx.CheckBox(self.pane_all_settings, wx.ID_ANY, _("Fehlzeiten"))
self.urlaub = wx.CheckBox(self.pane_all_settings, wx.ID_ANY, _(u"Urlaubsanspr\xfcche"))
self.soll = wx.CheckBox(self.pane_all_settings, wx.ID_ANY, _("Sollstunden"))
self.label_8_copy_1 = wx.StaticText(self.pane_all_settings, wx.ID_ANY, _("ImpVar"))
self.dir_impvar = wx.TextCtrl(self.pane_all_settings, wx.ID_ANY, "")
self.label_8_copy_2 = wx.StaticText(self.pane_all_settings, wx.ID_ANY, _("ImpUbr"))
self.dir_impubr = wx.TextCtrl(self.pane_all_settings, wx.ID_ANY, "")
self.label_8_copy_1_copy = wx.StaticText(self.pane_all_settings, wx.ID_ANY, _("Pfad zur ImpVar"))
self.dir_impvar_copy = wx.TextCtrl(self.pane_all_settings, wx.ID_ANY, "")
self.label_8_copy_1_copy_copy = wx.StaticText(self.pane_all_settings, wx.ID_ANY, _("Pfad zur ImpUbr"))
self.dir_impvar_copy_1 = wx.TextCtrl(self.pane_all_settings, wx.ID_ANY, "")
self.label_8_copy_1_copy_copy_copy = wx.StaticText(self.pane_all_settings, wx.ID_ANY, _("Ausgabeverzeichnis"))
self.dir_impvar_copy_2 = wx.TextCtrl(self.pane_all_settings, wx.ID_ANY, "")
self.button_1 = wx.Button(self.pane_all_settings, wx.ID_ANY, _("Exportieren"))
self.button_1_copy = wx.Button(self.pane_all_settings, wx.ID_ANY, _("Abbrechen"))
self.pan_loga = wx.Panel(self.kartei, wx.ID_ANY)
self.label_5_copy = wx.StaticText(self.pan_loga, wx.ID_ANY, _("Exportieren nach Loga"))
self.label_6_copy = wx.StaticText(self.pan_loga, wx.ID_ANY, _("Loga-Mandant"))
self.loga_mandant = wx.SpinCtrl(self.pan_loga, wx.ID_ANY, "1", min=0, max=1000000, style=wx.SP_ARROW_KEYS | wx.TE_AUTO_URL)
self.label_7_copy = wx.StaticText(self.pan_loga, wx.ID_ANY, _("Loga-Abrechnungskreis"))
self.loga_al = wx.SpinCtrl(self.pan_loga, wx.ID_ANY, "", min=0, max=100)
self.label_8_copy = wx.StaticText(self.pan_loga, wx.ID_ANY, _("Empty"))
self.combo_box_1_copy = wx.ComboBox(self.pan_loga, wx.ID_ANY, choices=[], style=wx.CB_DROPDOWN)
self.label_1_copy = wx.StaticText(self.pan_loga, wx.ID_ANY, _(u"Personalnummer f\xfcllen"))
self.loga_fill_pnr = wx.SpinCtrl(self.pan_loga, wx.ID_ANY, "1", min=0, max=999, style=wx.SP_ARROW_KEYS | wx.TE_AUTO_URL)
self.konv_loa = wx.CheckBox(self.pan_loga, wx.ID_ANY, _("Konvertierungslohnart"))
self.konv_fehl = wx.CheckBox(self.pan_loga, wx.ID_ANY, _("Konvertierungsfehlzeiten"))
self.zeitraum_fehl = wx.CheckBox(self.pan_loga, wx.ID_ANY, _("Zeitraum Fehlzeit"))
self.vertragsnummer = wx.CheckBox(self.pan_loga, wx.ID_ANY, _(u"Vertragsnummer ber\xfccksichtigen"))
self.notebook_2_pane_3 = wx.Panel(self.kartei, wx.ID_ANY)
self.notebook_2_pane_4 = wx.Panel(self.kartei, wx.ID_ANY)
self.notebook_2_pane_5 = wx.Panel(self.kartei, wx.ID_ANY)
self.notebook_2_pane_6 = wx.Panel(self.kartei, wx.ID_ANY)
self.notebook_2_pane_7 = wx.Panel(self.kartei, wx.ID_ANY)
self.__set_properties()
self.__do_layout()
self.Bind(wx.EVT_MENU, self.stopExport, id=wx.ID_ANY)
self.Bind(wx.EVT_BUTTON, self.startExport, self.button_1)
self.Bind(wx.EVT_BUTTON, self.stopExport, self.button_1_copy)
# end wxGlade
def __set_properties(self):
# begin wxGlade: MyFrame.__set_properties
self.SetTitle(_("TDA Export Manager 0.12"))
self.frame_3_statusbarr.SetStatusWidths([-1])
# statusbar fields
frame_3_statusbarr_fields = [_("(C) TDA-HR-Software Entwicklungs GmbH")]
for i in range(len(frame_3_statusbarr_fields)):
self.frame_3_statusbarr.SetStatusText(frame_3_statusbarr_fields[i], i)
self.payroll.SetSelection(-1)
# end wxGlade
def __do_layout(self):
# begin wxGlade: MyFrame.__do_layout
sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
grid_sizer_2_copy = wx.FlexGridSizer(10, 4, 0, 0)
grid_sizer_2 = wx.FlexGridSizer(10, 4, 0, 0)
grid_sizer_2.Add(self.label_5, 0, wx.ALL, 10)
grid_sizer_2.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2.Add(self.label_6, 0, wx.ALL, 10)
grid_sizer_2.Add(self.abr_jahr, 0, wx.ALL, 10)
grid_sizer_2.Add(self.label_7, 0, wx.ALL, 10)
grid_sizer_2.Add(self.abr_monat, 0, wx.ALL, 10)
grid_sizer_2.Add(self.label_8, 0, wx.ALL, 10)
grid_sizer_2.Add(self.payroll, 0, wx.ALL, 10)
grid_sizer_2.Add(self.label_1, 0, wx.ALL, 10)
grid_sizer_2.Add(self.mandant, 0, wx.ALL, 10)
grid_sizer_2.Add(self.zuschlag, 0, wx.ALL, 10)
grid_sizer_2.Add(self.fehlzeit, 0, wx.ALL, 10)
grid_sizer_2.Add(self.urlaub, 0, wx.ALL, 10)
grid_sizer_2.Add(self.soll, 0, wx.ALL, 10)
grid_sizer_2.Add(self.label_8_copy_1, 0, wx.ALL, 10)
grid_sizer_2.Add(self.dir_impvar, 0, wx.ALL, 10)
grid_sizer_2.Add(self.label_8_copy_2, 0, wx.ALL, 10)
grid_sizer_2.Add(self.dir_impubr, 0, wx.ALL, 10)
grid_sizer_2.Add(self.label_8_copy_1_copy, 0, wx.ALL, 10)
grid_sizer_2.Add(self.dir_impvar_copy, 0, wx.ALL, 10)
grid_sizer_2.Add(self.label_8_copy_1_copy_copy, 0, wx.ALL, 10)
grid_sizer_2.Add(self.dir_impvar_copy_1, 0, wx.ALL, 10)
grid_sizer_2.Add(self.label_8_copy_1_copy_copy_copy, 0, wx.ALL, 10)
grid_sizer_2.Add(self.dir_impvar_copy_2, 0, wx.ALL, 10)
grid_sizer_2.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2.Add(self.button_1, 0, wx.ALL, 10)
grid_sizer_2.Add(self.button_1_copy, 0, wx.ALL, 10)
self.pane_all_settings.SetSizer(grid_sizer_2)
grid_sizer_2_copy.Add(self.label_5_copy, 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add(self.label_6_copy, 0, wx.ALL, 10)
grid_sizer_2_copy.Add(self.loga_mandant, 0, wx.ALL, 10)
grid_sizer_2_copy.Add(self.label_7_copy, 0, wx.ALL, 10)
grid_sizer_2_copy.Add(self.loga_al, 0, wx.ALL, 10)
grid_sizer_2_copy.Add(self.label_8_copy, 0, wx.ALL, 10)
grid_sizer_2_copy.Add(self.combo_box_1_copy, 0, wx.ALL, 10)
grid_sizer_2_copy.Add(self.label_1_copy, 0, wx.ALL, 10)
grid_sizer_2_copy.Add(self.loga_fill_pnr, 0, wx.ALL, 10)
grid_sizer_2_copy.Add(self.konv_loa, 0, wx.ALL, 10)
grid_sizer_2_copy.Add(self.konv_fehl, 0, wx.ALL, 10)
grid_sizer_2_copy.Add(self.zeitraum_fehl, 0, wx.ALL, 10)
grid_sizer_2_copy.Add(self.vertragsnummer, 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
self.pan_loga.SetSizer(grid_sizer_2_copy)
self.kartei.AddPage(self.pane_all_settings, _("Allgemeine Einstellungen"))
self.kartei.AddPage(self.pan_loga, _("Loga"))
self.kartei.AddPage(self.notebook_2_pane_3, _("Sage"))
self.kartei.AddPage(self.notebook_2_pane_4, _("SAP"))
self.kartei.AddPage(self.notebook_2_pane_5, _("KidiCap"))
self.kartei.AddPage(self.notebook_2_pane_6, _("fidelis Personal"))
self.kartei.AddPage(self.notebook_2_pane_7, _("Konvertierungsfehlzeiten"))
sizer_2.Add(self.kartei, 1, wx.EXPAND, 0)
self.SetSizer(sizer_2)
sizer_2.Fit(self)
self.Layout()
# end wxGlade
def startExport(self, event): # wxGlade: MyFrame.<event_handler>
abrjahr = self.abr_jahr.GetValue()
print abrjahr
def stopExport(self, event): # wxGlade: MyFrame.<event_handler>
self.Close()
# end of class MyFrame
if __name__ == "__main__":
gettext.install("app") # replace with the appropriate catalog name
app = wx.PySimpleApp(0)
wx.InitAllImageHandlers()
frame_3 = MyFrame(None, wx.ID_ANY, "")
app.SetTopWindow(frame_3)
frame_3.Show()
app.MainLoop()
There are ways to get the class objects and iterate over them.
But i'd suggest a restructure of the code and consider a container for your graphical elements instead, like this:
self.frames = {}
self.frames['_3_menubar'] = wx.MenuBar()
self.frames['frame_3_statusbarr'] = self.CreateStatusBar(1, 0)
self.frames['kartei'] = wx.Notebook(self, wx.ID_ANY, style=0)
self.frames['pane_all_settings'] = wx.Panel(self.kartei, wx.ID_ANY)
self.frames['label_5'] = wx.StaticText(self.pane_all_settings, wx.ID_ANY, _("Laufzeiteinstellungen"))
#... Etc etc, the rest of the objects
# And do something like this not only for your own sake
# But for getting rid huge amounts of code that can be compressed into stuff like this.
for item in ('Beenden', 'Datei', 'Bearbeiten', 'Dokumentationen', 'Hilfe'):
self.frames['_3_menubar'].Append(wxglade_tmp_menu, _(item))
With this you can simply do:
def getAllValues(self):
for frame in self.frames:
value = self.getValue(self.frames[frame])
yield (frame, value)
Or something similar, not sure what you want to do with the values but you could do:
def saveAllValues(self):
with open('settings.ini', 'w') as fh:
for frame, value in self.getAllValues():
fh.write(frame + ':' + str(value) + '\n')
I would suggest you do the following:
Use a dictionary to receive all the initial values. Let the names in the dictionary map to the names of your variables.
Allow other modules to subscribe to this GUI using the Observer Pattern.
When anything changes, or when the buttons are pressed, create a dictionary with the changes and notify all subscribers of the change.
This keeps the GUI cleanly separated from the rest of the program.

Categories

Resources