Ich benutze Python und WxPython, um eine Benutzeroberfläche zu erstellen, die den Benutzer eine XML-Datei in der ersten Combobox auswählen und alle Komponenten (d. H. Schaltflächen) in der XML als Auswahl eines anderen Combobox unten angezeigt wird. Es liest eindeutig korrekt, da es das richtige Ding in der Konsole ausgibt, während ich alle XML-Dateien durchführe, aber ich kann es einfach nicht wieder mit der Combobox verknüpfen, nach der ich suche.Bearbeiten von ComboBoxen in wxPython
Hier ist der Code:
import wx
import os
import xml.dom.minidom
from xml.dom.minidom import parse
# get all xmls
path = "C:\Users\William\Desktop\RES\Param"
files = os.listdir(path)
class Panel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.xmlList = files
self.xmlPickerTitle = wx.StaticText(self, label="XML Picker", pos=(20, 30))
self.xmlPicker = wx.ComboBox(self, pos=(100, 30), size=(500, -1), choices=self.xmlList, style=wx.CB_DROPDOWN)
self.elementsTitle = wx.StaticText(self, label="Elements Found", pos=(20, 100))
# labels
self.buttonsPickerTitle = wx.StaticText(self, pos=(20,120), label="Buttons")
self.buttonList = []
self.buttonsPicker = wx.ComboBox(self, pos=(100, 120), size=(250, -1), choices=buttonList, style=wx.CB_DROPDOWN)
self.Bind(wx.EVT_COMBOBOX, self.XMLSelect,)
def XMLSelect(self, event):
xmlPicked = self.xmlList[event.GetSelection()]
DOMTree = xml.dom.minidom.parse(xmlPicked)
collection = DOMTree.documentElement
buttons = DOMTree.getElementsByTagName("Button")
for button in buttons:
if button.hasAttribute("name"):
buttonList.append(button.getAttribute("name"))
print button.getAttribute("name")
app = wx.App(False)
frame = wx.Frame(None, title = "Auto", size = (800, 600))
panel = Panel(frame)
frame.Show()
app.MainLoop()
Irgendwelche Ideen?
Vielen Dank im Voraus!
// 30.06 - Hinzufügen von XML-Beispiel
Hier ist ein Beispiel für meine XML-Datei, die ich zu verarbeiten versucht:
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<Window size="615,600" caption="0,0,0,40">
<Include source="MainFrame_NewStyle.xml" />
<HorizontalLayout>
<VerticalLayout width="1" bkimage="ProcessMgr_boder.png"/>
<VerticalLayout bkimage="Control_bkg1.png">
<VerticalLayout height="1" bkimage="ProcessMgr_boder.png"/>
<HorizontalLayout height="60">
<VerticalLayout>
<Label name="lbl_tip" text="Attribute Edit" height="60" font="4" textpadding="0,0,0,0" align="center" textcolor="#001e1e1f" disabledtextcolor="#FFA7A6AA" />
</VerticalLayout>
<VerticalLayout width="46">
<Button name="btn_close" float="true" pos="0,10,0,0" width="36" height="36" textcolor="#004C5D6E" disabledtextcolor="#FFA0A0A0"
tooltip="Close Notice Window"
normalimage="file='Control_FrameCloseBtn.png' source='0,0,36,36'"
hotimage="file='Control_FrameCloseBtn.png' source='0,36,36,72'"
pushedimage="file='Control_FrameCloseBtn.png' source='0,72,36,108'" />
</VerticalLayout>
</HorizontalLayout>
<VerticalLayout height="1" bkimage="ProcessMgr_boder.png"/>
<HorizontalLayout height="20" bkimage="Control_bkg2.png"/>
<HorizontalLayout height="450" bkimage="Control_bkg2.png">
<HorizontalLayout width="20" />
<HorizontalLayout width="1" bkimage="Control_boder.png" />
<VerticalLayout width="200" bkimage="Control_bkg2.png">
<VerticalLayout height="1" width="200" bkimage="Control_boder.png" />
<VerticalLayout>
<!--List name="pa_cmb_PropertySet" menu="true" header="hidden" style="Common_List_Style"-->
<List name="pa_cmb_PropertySet" menu="true" style="Common_List_Style">
<ListHeader height="30" bkimage="Control_WorklistHeader_Nomal.png" menu="true">
<ListHeaderItem name="title_Collimation Width" text="Collimation Width" minwidth="30" width="200" textcolor="#001e1e1f" sepwidth="1" align="center" hotimage="file='Control_WorklistHeader_HighLight.png'" pushedimage="file='Control_WorklistHeader_Pushed.png'" sepimage="file='Control_boder.png'" />
</ListHeader>
</List>
</VerticalLayout>
<VerticalLayout height="1" width="200" bkimage="Control_boder.png" />
</VerticalLayout>
<HorizontalLayout width="1" bkimage="Control_boder.png" />
<HorizontalLayout width="20" />
<HorizontalLayout >
<HorizontalLayout width="1" bkimage="Control_boder.png" />
<VerticalLayout width="350" bkimage="Control_bkg2.png">
<VerticalLayout height="1" bkimage="Control_boder.png" />
<VerticalLayout >
<List name="list_CollimationWidthSet" menu="true" style="Common_List_Style">
<ListHeader height="30" bkimage="Control_WorklistHeader_Nomal.png" menu="true">
<ListHeaderItem name="title_status" text="Status" minwidth="30" width="60" textcolor="#001e1e1f" sepwidth="1" align="center" hotimage="file='Control_WorklistHeader_HighLight.png'" pushedimage="file='Control_WorklistHeader_Pushed.png'" sepimage="file='Control_boder.png'" />
<ListHeaderItem name="title_name" text="Attribute Name" width="250" textcolor="#001e1e1f" sepwidth="1" align="center" hotimage="file='Control_WorklistHeader_HighLight.png'" pushedimage="file='Control_WorklistHeader_Pushed.png'" sepimage="file='Control_boder.png'" />
</ListHeader>
</List>
</VerticalLayout>
<VerticalLayout height="1" bkimage="Control_boder.png" />
</VerticalLayout>
<HorizontalLayout width="1" bkimage="Control_boder.png" />
</HorizontalLayout>
</HorizontalLayout>
<VerticalLayout bkimage="Control_bkg2.png">
<Button name="btn_ok" text="OK" float="true" pos="480,20,0,0" width="94" height="35" style="Common_Button_222x63_Style" />
</VerticalLayout>
<VerticalLayout height="1" bkimage="ProcessMgr_boder.png"/>
</VerticalLayout>
<VerticalLayout width="1" bkimage="ProcessMgr_boder.png"/>
</HorizontalLayout>
</Window>
Es erzählt eine Benutzeroberfläche mit verschiedenen Komponenten wie Label, Schaltfläche, Liste usw. innerhalb von Layoutstrukturen.
Post eine Probe eines Ihrer XML-Dateien –
einfach haben, bitte überprüfen und sehen, ob Sie :) – AtomicPotato