J'utilise Python et wxPython pour créer une interface utilisateur qui permet à l'utilisateur de sélectionner un fichier XML dans la première liste déroulante et tous les composants (boutons) du XML apparaissent comme choix d'une autre liste déroulante ci-dessous. C'est clairement lire correctement car il imprime la bonne chose dans la console que je passe par tous les XML, mais je ne peux pas sembler relier à la combobox que je recherche.Manipulation de ComboBox dans wxPython
Voici le 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()
Toutes les idées?
Merci d'avance!
// 06/30 - ajouter par exemple XML
Voici un exemple de mon fichier XML que je suis en train de traiter:
<?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>
Il raconte une interface utilisateur avec différents composants tels que l'étiquette, bouton, liste, etc dans les structures de mises en page.
après un échantillon d'un de vos fichiers xml –
Tout a fait, s'il vous plaît vérifier et voir si vous pouvez aider – AtomicPotato