drop problem with grid -- on Mac only?

39 views
Skip to first unread message

Brian H. Toby

unread,
Sep 25, 2010, 10:40:14 AM9/25/10
to wxpytho...@googlegroups.com
I have been having problems getting drag & drop to work, where I drag into a grid on a Mac. I have constructed a <60 line demo program that works on Windows and Linux, but where dragging to the grid on my Mac (10.6.4, EPD 6.2-2) fails. Is this operator error or is there a wx bug here?

As a second question, since I am still struggling to learn proper use of sizers, can anyone explain to me why the commented out BoxSizer Add fails to cause the TextCtrl to expand to its proper size, if it is used in place of the previous Add?

Brian

testdrop.py

Robin Dunn

unread,
Sep 27, 2010, 12:22:16 PM9/27/10
to wxpytho...@googlegroups.com
On 9/25/10 7:40 AM, Brian H. Toby wrote:
> I have been having problems getting drag& drop to work, where I drag

> into a grid on a Mac. I have constructed a<60 line demo program that
> works on Windows and Linux, but where dragging to the grid on my Mac
> (10.6.4, EPD 6.2-2) fails. Is this operator error or is there a wx
> bug here?

The Grid widget is composed of several sub widgets (for the grid area
and the col/row labels), which occupy all the visible area of the grid.
If you want to be able to drop into the grid you should set the drop
target on one of the visible windows, not its parent.

grid.GetGridWindow().SetDropTarget(drptgt)


>
> As a second question, since I am still struggling to learn proper use
> of sizers, can anyone explain to me why the commented out BoxSizer
> Add fails to cause the TextCtrl to expand to its proper size, if it
> is used in place of the previous Add?

Depends on what you mean by "proper size." I'm guessing that you think
it means to be large enough to show all the text. But since the
wx.TextCtrl can have variable size needs that change at runtime as the
user types then it just uses a fixed width for its best size and that is
what the sizer will use for layout unless you tell it different. You
can override the best size by setting the min size.

lbl1.SetMinSize((200,-1))

--
Robin Dunn
Software Craftsman
http://wxPython.org

bht

unread,
Sep 27, 2010, 5:50:51 PM9/27/10
to wxPython-users
Ah ha! Thanks this is indeed the solution:

> If you want to be able to drop into the grid you should set the drop
> target on one of the visible windows, not its parent.
>
> grid.GetGridWindow().SetDropTarget(drptgt)

So I take it that the GridDragAndDrop.py example:

class SimpleGrid(gridlib.Grid):
def __init__(self, parent, log):
gridlib.Grid.__init__(self, parent, -1)
...
# set the drag and drop target
dropTarget = GridFileDropTarget(self)
self.SetDropTarget(dropTarget)

is wrong. (How to get that changed?) To help others avoid this
pitfall, I have made appropriate (I hope) updates to http://wiki.wxpython.org/wxGrid
and http://wiki.wxpython.org/AppointmentsSchedulingWidget where the
similar problematic usage is present.

Brian

Robin Dunn

unread,
Sep 27, 2010, 6:12:59 PM9/27/10
to wxpytho...@googlegroups.com
On 9/27/10 2:50 PM, bht wrote:
> Ah ha! Thanks this is indeed the solution:
>
>> If you want to be able to drop into the grid you should set the drop
>> target on one of the visible windows, not its parent.
>>
>> grid.GetGridWindow().SetDropTarget(drptgt)
>
> So I take it that the GridDragAndDrop.py example:
>
> class SimpleGrid(gridlib.Grid):
> def __init__(self, parent, log):
> gridlib.Grid.__init__(self, parent, -1)
> ...
> # set the drag and drop target
> dropTarget = GridFileDropTarget(self)
> self.SetDropTarget(dropTarget)
>
> is wrong.

Apparently not as that sample works fine on Mac for me, I guess I was
misremembering something. Try to figure out what the difference is
between your sample and the one in the demo, so we can narrow down where
the problem is at.

Robin Dunn

unread,
Sep 27, 2010, 6:18:13 PM9/27/10
to wxpytho...@googlegroups.com

Oops, what I was missing is that I ran one sample with wx 2.8 and the
other with 2.9. In 2.9 this issue has been solved, and setting the Grid
as the drop target on Mac will also work for drops done on the GridWindow.

Reply all
Reply to author
Forward
0 new messages