propgrid.FileProperty with wildcards
Carlos Gimenez <[email protected]>
| Newsgroups | gmane.comp.python.wxpython.devel |
|---|---|
| Message-ID | <[email protected]> |
Hello guys, I'm kinda new to Python and got my hands on wxPython. I'm still
impressed with it and it was a refreshing change after so much Visual C#
hehe.
While making my litle test app I got stuck in a minor problem that bothers
me. I created a small propgrid with some object properties. Two of them
must be FileProperty type, but each of them needs a diferent wildcard.
So I followed the docs and inherited a class from
propgrid.PGEditorDialogAdapter with a DoShowDialog method and SetValue() on
it (
https://wxpython.org/Phoenix/docs/html/wx.propgrid.PGEditorDialogAdapter.html#wx.propgrid.PGEditorDialogAdapter.SetValue
), but the only way I could thing to implement it was to create it from
another class inherited from propgrid.FileProperty, wich I already had
because I needed to enable some outsider buttons on value change.
The only method I found to do the work was the GetEditorDialog() method and
indeed it launched my custom dialog, but when you choose a file and press
the button, or even canceling it, It hangs out for some time, then crashes
without exceptions (this program has become irresponsive),
Is there a better way to avoid all of this and get a shortcut ? Lol ! I
only want to accept .txt in one property and .mp3 on the other. Here's my
code:
...
self.txtFile = self.pgrid.Append(CFileProperty("TxtFile ",
"txtFile", self.data.txtFile, subpanel=self ))
...
class CFileProperty(propgrid.FileProperty):
def __init__(self, *args, subpanel=None, **kwargs):
propgrid.FileProperty.__init__(self, *args, **kwargs)
self.SetDefaultValue(self.GetValue())
#self.EditorDialog = CLyricFileDialog()
#dialogAdapter = CLyricFileDialog(parent=self)
#self.SetEditor(dialogAdapter)
if subpanel:
self.subpanel = subpanel
def OnSetValue(self, *args, **kwargs):
#six.print_("Se Edito: %s - %s" % (self.GetLabel(),
self.GetValue()))
if self.subpanel:
self.subpanel.OnEnableButtons(self)
return propgrid.FileProperty.OnSetValue(self, *args, **kwargs)
def GetEditorDialog(self, *args, **kwargs):
return CLyricFileDialog(parent=self)
class CLyricFileDialog(propgrid.PGEditorDialogAdapter):
def __init__(self, *args, parent=None, **kwargs):
propgrid.PGEditorDialogAdapter.__init__(self, *args, **kwargs)
self.parent = parent
self.DoShowDialog()
def DoShowDialog(self):
dlg = wx.FileDialog(None, "Open lyric file", "", "", "Lyric Files
(*.rap)|*.rap|Plain Text (*.txt)|*.txt", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
try:
if dlg.ShowModal() == wx.ID_OK:
value = dlg.GetFilename()
self.SetValue(value)
return True
self.SetValue(value)
return False
except :
print("Exception")
return False
Im sure the problem is something silly Im missing... but I can't find it.
Sorry about my english! Thank you for your time.
--
You received this message because you are subscribed to the Google Groups "wxPython-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.