473,325 Members | 2,308 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

wxPython DnD stops working after SetSizeHints

This has been driving me crazy for a couple of days and I have finally
narrowed it down to the following code. If the commented section is
uncommented the drag and drop handler is never called. I have included
the .xrc file for reference.

Any help is greatly appreciated. An explanation would be great, but at
the moment I would be eternally grateful for a workaround!

Thanks in advance for those of you that spend some time helping out.

Here is the blasted code,

from wxPython.wx import *
from wxPython.xrc import *

class TestFrame(wxFrame):
def __init__(self,parent,ID):
wxFrame.__init__(self,parent,ID,"test
frame",(100,30),(70,60),wxDEFAULT_FRAME_STYLE)
self.panel=wxPanel(self,-1)

class FileDropTarget(wxFileDropTarget):
def __init__(self, window):
wxFileDropTarget.__init__(self)

def OnDropFiles(self, x, y, filenames):
print filenames

class App(wxApp):
def OnInit(self):

self.res=wxXmlResource("test.xrc")
self.frame=self.res.LoadFrame(None,"FRAME1")
self.frame.panel=XRCCTRL(self.frame,"test_list")

dt=FileDropTarget(self.frame)
self.frame.panel.SetDropTarget(dt)

# The following lines break the drag and drop
# self.panel=XRCCTRL(self.frame,"panel")
# sizer=self.panel.GetSizer()
# sizer.SetSizeHints(self.frame)

self.frame.Show()
self.SetTopWindow(self.frame)

return True
def main():
app=App(0)
app.MainLoop()
if __name__=="__main__":
main()
and here the XRC

<?xml version="1.0" ?>
<resource>
<object class="wxFrame" name="FRAME1">
<title></title>
<object class="wxPanel" name="panel">
<size>100,100</size>
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
<object class="sizeritem">
<object class="wxStaticBoxSizer">
<label>test_list</label>
<orient>wxVERTICAL</orient>
<object class="sizeritem">
<object class="wxListBox" name="test_list">
<content/>
</object>
</object>
</object>
</object>
</object>
</object>
<size>100,100</size>
</object>
</resource>
Jul 18 '05 #1
2 2290


"Emiliano Molina" wrote
<snip>
from wxPython.wx import *
from wxPython.xrc import *

class TestFrame(wxFrame):
def __init__(self,parent,ID):
wxFrame.__init__(self,parent,ID,"test frame",(100,30),(70,60),wxDEFAULT_FRAME_STYLE) self.panel=wxPanel(self,-1) This gets overwritten -^

class FileDropTarget(wxFileDropTarget):
def __init__(self, window): unused --------------------^
wxFileDropTarget.__init__(self)

def OnDropFiles(self, x, y, filenames):
print filenames

class App(wxApp):
def OnInit(self):

self.res=wxXmlResource("test.xrc")
self.frame=self.res.LoadFrame(None,"FRAME1")
self.frame.panel=XRCCTRL(self.frame,"test_list")

dt=FileDropTarget(self.frame)
self.frame.panel.SetDropTarget(dt)

# The following lines break the drag and drop
# self.panel=XRCCTRL(self.frame,"panel")
# sizer=self.panel.GetSizer()
# sizer.SetSizeHints(self.frame)
What is self.panel, as opposed to self.frame.panel?

self.frame.Show()
self.SetTopWindow(self.frame)

return True

Hi Emiliano, it isn't clear what you are trying to do here, you seem to
have a panel being created in 3 different places -- which one do you
want? I suspect that the self.panel, is hiding the other panel
that you created (self.frame.panel) which is the drop target (just a
guess)

I've never used xrc, but this works for me (is it what you want?)

class App(wxApp):
def OnInit(self):

self.res=wxXmlResource("test.xrc")
self.frame=self.res.LoadFrame(None,"FRAME1")
self.frame.panel=XRCCTRL(self.frame,"panel")

dt=FileDropTarget()
self.frame.panel.SetDropTarget(dt)

# The following lines break the drag and drop
sizer=self.frame.panel.GetSizer()
sizer.SetSizeHints(self.frame)

self.frame.Show()
self.SetTopWindow(self.frame)

return True


Jul 18 '05 #2
>> self.panel=wxPanel(self,-1)

This gets overwritten -^
def __init__(self, window):


unused --------------------^


Yes, you are 100% right, its there because I have been cutting
down the original program bit by bit to find the problem! It
should no longer be there.
# The following lines break the drag and drop
# self.panel=XRCCTRL(self.frame,"panel")
# sizer=self.panel.GetSizer()
# sizer.SetSizeHints(self.frame)

What is self.panel, as opposed to self.frame.panel?


self.panel is where I am temporarily storing the window that
I am adding the DnD to. One of the steps that I took when
trying to work out where the problem was was to start with
nothing but a frame and a panel and see if I could drop files
into the panel. That worked fine, it was only when I added a
sizer and then had to fit and set hints that DnD broke.

I'm sorryt that the naming is a bit confusing, I posted this
last night as a last desperate attempt before going to bed!
Hi Emiliano, it isn't clear what you are trying to do here, you seem to
have a panel being created in 3 different places -- which one do you
want? I suspect that the self.panel, is hiding the other panel
that you created (self.frame.panel) which is the drop target (just a
guess)
The confusion is understandable, I should have spent more time
tidying up the code before posting.

self.frame.panel is used to store the retrieved control to which
the DnD handler is attached. Its called panel because originally
it WAS a panel, its now a wxListBox.

self.panel is used to store the retrieved panel (this one IS a panel,
sorry for the confusion) from which we can then obtain the main sizer
for the frame. If we don't have the sizer we can't call SetSizeHints
to arrange the controls in the window. Its the calling of SetSizeHints
that seems to break the DnD handling. If I don't call SetSizeHints
then DnD works fine and I can drop a file onto the list in the frame
and its name is printed. The frame looks terrible of course, the
controls are only arranged properly when I call SetSizeHints.
I've never used xrc, but this works for me (is it what you want?)

some helpful code

return True


I tried the code you sent on the iBook and no luck, but you mentioned
that it worked so I sent it over to the PC and tried it again. It worked!

I had a close look at it and you have changed the drop target from the
list to the main panel. I did the same with my code on the PC and it
also worked. So the conclusion is that neither your or my code works on
the Mac. Both sets of code work on the PC as long as the drop target is
the panel and not the list.

Thanks for your help and time. Now I have to figure out what is
happening on the Mac.
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Curzio Basso | last post by:
Hi all, I have a problem for which I wasn't able to find an answer anywhere else, maybe someone can give me a hint... I designed with XRCed a small GUI (the code is at the bottom of the...
1
by: Piet | last post by:
Hello, I am still struggling with a dynamic dialog box. I have created a dialog box that will show a variable number of controls depending on a selection made in a ComboBox also present in the...
0
by: Dave Williams | last post by:
Hi, I'm having problems getting IpAddrCtrl working with a frame containing nested sizers generated from an xrc file. Firstly I tried adding it using AttachUnknownControl as per the example code...
1
by: flupke | last post by:
Hi, i'm trying to convert my java console app to a python gui. Now, the only problem i seem to have at the moment are the resizers for the layout. It seems that for the purpose of what i'm...
0
by: flupke | last post by:
Hi, i need to develop a gui which will load several "windows" depending on what the users selects in the menu and i thought i could accomplish this with panels. What i'm trying to do to test...
10
by: abcd | last post by:
I have a TextCtrl which is set to be multi-line. I have a function say, updateText(msg), which takes some string and appends it to the text control... txtControl.AppendText(msg) ...
10
by: markwalker84 | last post by:
Hello everyone! Got a bit of a problem... Two of the panels on my program contain a number of check boxes. The exact number of which is determined by a pair of variables. I have recently...
6
by: shuf | last post by:
Hello, I am running python 2.4.4 with wxpython 2.6 on Fedora 6. I am trying to set the font color of individual elements in a listbox, but I am not able to with SetItemForegroundColour()...
9
by: Tyler | last post by:
Hello All: I am currently working on a project to create an FEM model for school. I was thinking about using wxPython to gather the 12 input variables from the user, then, after pressing the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.