Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Win32::Clipboard from within a wxPerl

by Chady (Priest)
on May 11, 2003 at 18:53 UTC ( [id://257258]=perlquestion: print w/replies, xml ) Need Help??

Chady has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks,

I'm facing a bit of a mindblock, and not sure about which decision to go for.

I'm writing some app for Windows and there's a lot of Events that need blocking event monitors;

The first event is via Win32::Clipboard which waits for the clipboard to change and needs to capture the data and do something with it.

I'm coding a GUI for the app with wxPerl and not sure how to handle the clipboard thing since I get stuck within MainLoop.

So I decided to split it into two piece, one script handles capturing the clipboard data, and another for the GUI, so came the passing of data; fork+pipes are blocking. I tried to store the data in a temp file, but there was a need to notify the GUI that the temp file has changed, Win32::ChangeNotify can do that, but it's blocking.

I'm just starting with Wx, and probably missing much, is there a way to implement Win32::Clipboard from with a Wx app?

My idea was to try something like:

while (1) { # 100 as to try and make room for other things to happen # as if it is non-blocking if ($CLIP->WaitForChange(100) == 1) { $clipboard = $CLIP->Get(); } }

somewhere, but even that found no place to go...

Any pointers are appreciated.


He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

Chady | http://chady.net/

Replies are listed 'Best First'.
Re: Win32::Clipboard from within a wxPerl
by BrowserUk (Patriarch) on May 11, 2003 at 20:51 UTC

    If you are running a threaded perl, then this is one way. (I know nothing of wxPerl so my apologies if it doesn't work there). This uses the 5.8 flavour of threads, but it wouldn't take much work to get it going with a 5.6 threaded perl I think.

    #! perl -slw use strict; require 5.008; use threads; use threads::shared; use Thread::Queue; use Win32::Clipboard; $|++; # Disable buffering so we see the changes immediatly my $flag : shared = 0; # A flag to tell the thread when to die my $q = new Thread::Queue; # Create a thread sub watchClipboard{ my $clip = Win32::Clipboard(); # Get a handle to the CB while ( !$flag ) { # Repeat until we're told to die $clip->WaitForChange(); # Block waiting for an event # Once something happens, queue it back to the main program $q->enqueue( $clip->Get() ); } }; my $watcher = threads->create( 'watchClipboard' ); my $i =0; # A count to allow the demo to self terminate while( $i < 600 ) { # Wait for 1 minute of inactivity before calling i +t quits. while( $q->pending ) { # If the watcher put anything in the queue, display it. $i = 0; print( $/, 'From the clipboard: ', $q->dequeue ); } # Show we can be doing other things printf "\rMeanwhile, just killing time: %2.1f", $i++/10; # Stop the demo from chewing cpu. select undef,undef,undef, .1; } $flag = 1; # Set the flag asking the thread to +die Win32::Clipboard()->Set(''); # Put something on the CB to break th +e wait $watcher->join; # Wait for it to die. exit;

    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
Re: Win32::Clipboard from within a wxPerl
by PodMaster (Abbot) on May 12, 2003 at 05:38 UTC
    Check out the demo, and read up on wxClipboard. You don't need Win32::Clipboard. If you wanna do IPC, check out Wx::Socket.

    Also, make yourself familiar with http://wxperl.sf.net/ and more importantly wxperl-users@lists.sourceforge.net. If you wanna do some wxperl, you gotta have a copy of the docs (absolutely essential).


    MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
    I run a Win32 PPM repository for perl 5.6x+5.8x. I take requests.
    ** The Third rule of perl club is a statement of fact: pod is sexy.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://257258]
Approved by valdez
Front-paged by Aristotle
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-26 02:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found