Tk::DropSite question

G

~greg

I have reduced the following script,
but it's runnable. It's a way
to make a Tk listbox that accepts
a selection of files or folders
from Windows Explorer.

The drop handler (my "OnSourceDrop")
is apparently called individually
on each file or folder in a multiple selection.

And my question is,

is there any way to know when to call
a group-drop-handler,
to be called after all the individual
calls to OnSourceDrop() are finished
after a group drop?

thank you,

~greg

~~~~~~~~~~~~~~~~~~~~~~


use strict;
use warnings;
$|=1;

use Tk;
use Tk::DropSite qw(Win32);

my $Main = MainWindow->new
(
-title=>'DND'
);

my %SourceList;

my $SourceListBox = $Main->Scrolled
(
"Listbox",
-scrollbars => "osoe",
)->pack
(
-fill => 'x',
);

$SourceListBox->DropSite
(
-dropcommand => [\&OnSourceDrop,$SourceListBox],
-droptypes => 'Win32',
);

sub SourceAdd
{
my $f = shift; # file or folder
return if exists $SourceList{$f};
return if ! -e $f;
$SourceList{$f} = 1;
my $slash = -d $f ? '\\' : '';
$SourceListBox->insert('end', "$f$slash" );
$SourceListBox->yviewMoveto(1);
}

sub OnSourceDrop
{
my($widget, $selection) = @_;
my $f = $widget->SelectionGet('-selection'=>$selection,'STRING');
return if ! defined $f; # is this really necessary?
SourceAdd($f);
}

MainLoop;
 
Z

zentara

I have reduced the following script,
but it's runnable. It's a way
to make a Tk listbox that accepts
a selection of files or folders
from Windows Explorer.

The drop handler (my "OnSourceDrop")
is apparently called individually
on each file or folder in a multiple selection.

And my question is,

is there any way to know when to call
a group-drop-handler,
to be called after all the individual
calls to OnSourceDrop() are finished
after a group drop?

thank you,

~greg

Hi, I waited to see if anyone answered first; but since no one has,
I suggest you post this to comp.lang.perl.tk or perlmonks.org.

Tk Drop is not seen much, and in conjunction with Windows makes
it pretty esoteric.

zentara
 
G

~greg

"zentara" > ...
~greg >

Hi, I waited to see if anyone answered first; but since no one has,
I suggest you post this to comp.lang.perl.tk or perlmonks.org.


Thank you for your patience about that, zentara.
And for your suggested alternatives.

When I asked the question in this newsgroup, I asked it also
in exactly one other group - comp.lang.perl.modules.
And I got a answer there pretty quick, from a Mr Christoph (Ch) Lamprecht.

He suggested at first a general idea, which might be useful in other situations:
-- namely, setting up a delayed call to the general-handler
from within the particular-handler, delayed by say 50 milliseconds,
but canceling it first, in the particular-handler, so that the general handler
won't be called as long as the particular-handler is being repeatedly
called within 50 msec of itself. And that worked.

But after I told Mr Lamprecht that I had been hoping for something
that didn't depend on timing, he very kindly went through the source
code of Tk::DropSite for me and discovered that the module itself
does in fact provide for exactly what I was asking for.
And he showed me two ways to do it.

His solutions can still be read very near the top of that newsgroup,
(which is very slow, but very sure moving.)

The real problem is that Tk::DropSite has in effect no pod
documentation at all. What it has instead is simply a mention
of the names of 3 attributes (one of them oddly repeated)
and 4 methods. But it says nothing at all about what they're for
or how to use them. And of course no examples.

It'd be a contender for the contest for the worst documented module,
except that I guess that Tk is understood to be documented in TCL references?

As for reading the source, I know that it can always be a useful
adjunct to understanding the official interface to a module.
But I am not very good at it, and in particular
I am not very good at seeing the difference, in source code,
between what's for the interface, and what's just for the
internal implimentaion, unless it's explicitly commented.
And I am afraid of accidentally making anything dependant
on internal implimentation, which could change with
every minor version upgrade of modules.
Tk Drop is not seen much, and in conjunction with Windows makes
it pretty esoteric.
zentara
http://zentara.net/japh.html


well, ok, but ...
when i clicked on your link, I got an ActiveX warning...

so I know at least you don't mean your comment
as a blanket indictment of Windows. :)

~greg
 
Z

zentara

When I asked the question in this newsgroup, I asked it also
in exactly one other group - comp.lang.perl.modules.
And I got a answer there pretty quick, from a Mr Christoph (Ch) Lamprecht.

He knows more than me, I'm glad he answered you.

The real problem is that Tk::DropSite has in effect no pod
documentation at all. What it has instead is simply a mention
It'd be a contender for the contest for the worst documented module,
except that I guess that Tk is understood to be documented in TCL references?

Yeah, that is why I said it is hardly used.

There is one good example on the net, at
A Drag-and-Drop Primer for Perl/Tk
http://www.perl.com/pub/a/2001/12/11/perltk.html
As for reading the source, I know that it can always be a useful
adjunct to understanding the official interface to a module.
But I am not very good at it, and in particular
I am not very good at seeing the difference, in source code,
between what's for the interface, and what's just for the
internal implimentaion, unless it's explicitly commented.
And I am afraid of accidentally making anything dependant
on internal implimentation, which could change with
every minor version upgrade of modules.

Well you are wise enough to realize that the Drag'n'Drop
code for Tk, us pretty weak, and you might not want to
depend on it, for anything other than your own scripts.
In other words, what works for you may fail for others.
well, ok, but ...
when i clicked on your link, I got an ActiveX warning...

It's just a short flash animation, that says Just Another Perl Hacker.
The ActiveX warning is beyond me, I hear that one of the biggest
complaints about Windows is stupid warnings like that. If you
google for "flash ActiveX warning" you may find solutions.
so I know at least you don't mean your comment
as a blanket indictment of Windows. :)
~greg

I'll issue a blanket indictment of Windows any time you want,
just as Judge Jackson did in his Anti-Trust findings against
Microsoft a few years ago.
http://usvms.gpo.gov/ms-findings2.html

:)
But what I meant was that Tk's Drag'n'Drop is hard enough
to get going with it's own Tk widgets, and that trying to do
a drop from an non-Tk app is pushing the limits, especially
on Windows.
( most Perl was written with linux/unix type systems in mind)


zentara
 
G

~greg

"zentara" > ...
It's just a short flash animation, that says Just Another Perl Hacker.
The ActiveX warning is beyond me, I hear that one of the biggest
complaints about Windows is stupid warnings like that. If you
google for "flash ActiveX warning" you may find solutions.

I was trying to be funny, but it went flat because
it was based on my ignorance.

I was mistakenly thinking that since ActiveX is a Windows' thing,
then you must have put the extra effort into using Windows-specific
HTML code to call the ActiveX component.
( ..something like <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ... > )

So the 'joke' would have been
that anybody who honestly hated Windows
would have never bothered doing that.

However, I can see in the source to your page
that you use "object"-"embed" syntax
-- which I guess is cross-platform.

(so the joke now is that that I am obviously not very clear
about the different ways of embeding objects in HTML.)
~~

Flash is an ActiveX component on Windows.
And the warning told me that my security
settings are set up the way that they ought to be set up.

Which is quite different from having a decent set
of security settings to set up in the first place!

For example, if it could be done, then I would probably want
to let your Flash-applet run, automatically, without me having
to click a bunch of things first, -- while at the same time
blocking all other ActiveX activity.

But Windows (at least before Vista) doesn't do things
in that very sensible a way.

Instead I have got to decide if I trust your whole site in toto
or not, -- it's an all or none thing - I can't cherry pick which
things I trust it with and which I might not trust it with.

The problem with this approach to security is that it is absolutely insane.
Beause no site can be trusted.
Any site can potentially be hacked.

If, say, I see from the source code of your page
that it's only trying to run a short flash animation,
then I could let it run.
But then there is nothing to stop your site from opening
a different page that will run a different AciveX
component on my computer, - perhaps a
malevolent one.

And that isn't the only problem with Windows security.
But as far as I'm concerned it's the most annoying one,
--because it's what makes it totally impossible
to at the same time both freely, and safely, surf the internet.

And since Vista will, finally, be doing the sand-box thing,
(like java) - then I can't believe it couldn't have been done sooner.

So I have got to think that "planned obsolescence"
was probably always a part of Microsoft's business strategy.

And if it was, then that's a real good reason to hate Bill Gates.
(--vs the many not so good reasons.)
But what I meant was that Tk's Drag'n'Drop is hard enough
to get going with it's own Tk widgets, and that trying to do
a drop from an non-Tk app is pushing the limits, especially
on Windows.
( most Perl was written with linux/unix type systems in mind)


I think I recall once trying to use it to drag and drop
between two Tk-widgets, and gave up. But I don't
remember why.

Oddly, though, it's working beautifully for me now,
DND between Windows Explorer and a Tk-widget.
And it seems to be very robust. I can drag and drop
a thousand files for example - which is way past
the limit that can be "Send to" (-without a lot of extra
work) for example. (--it's a windows thing.)


~greg
 
Z

zentara

And that isn't the only problem with Windows security.
But as far as I'm concerned it's the most annoying one,
--because it's what makes it totally impossible
to at the same time both freely, and safely, surf the internet.

And since Vista will, finally, be doing the sand-box thing,
(like java) - then I can't believe it couldn't have been done sooner.

I've heard that the biggest complaint new Vista users have
is that they get bombarded with so many "do you trust" questions,
that they are forced to turn it off, rendering it useless.

Why not use linux for the internet? :)
I think I recall once trying to use it to drag and drop
between two Tk-widgets, and gave up. But I don't
remember why.

Probably because the example didn't work. :)
Oddly, though, it's working beautifully for me now,
DND between Windows Explorer and a Tk-widget.
And it seems to be very robust. I can drag and drop
a thousand files for example - which is way past
the limit that can be "Send to" (-without a lot of extra
work) for example. (--it's a windows thing.)
~greg

It would be nice if you would post it, anonymously if
desired, in the Snippets section at http://perlmonks.org

so others can try it out, and see your technique.
I would be interested, if you can drag in the other direction,
from Tk to Explorer?

For what it's worth, the only example of inter-tk dnd
that I could get working is at
http://zentara.net/perlplay/tkdnd/tkdnd.tgz

It is based on Lidie's tutorial, but slightly modified to work. :)

If you run the ztest, you can drag from one window to the other,
but only in one direction. The logic needed to switch from
drag source to drop site, still eludes me.

Just to shoot the breeze, Perl/Gtk2 has DND too, and
I believe it to be better. But Perl/Gtk2 can be a bear
to install on windows.
See:
http://live.gnome.org/GnomeLove/DragNDropTutorial


zentara
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top