Flame has asked for the wisdom of the Perl Monks concerning the following question:
I have a GUI program done with Win32::GUI with a slight problem... almost everything the program does involves connecting to a website and sending/rescieving data. Now I know how to connect to the site and all... but whenever I do that the GUI freezes. Is there a way to keep the GUI alive while dealing with the sending and rescieving of the data from the website? I considered threading or forking, but I really don't understand it well enough. (For some reason... ActivePerl doesn't want to use the Threads package that CAME WITH the install... heh, so I can't even exeperement with those) If any of the responses involve forking or threads, please explain each step in detail... I hope to gain an understanding of both methods.
If I didn't explain my question enough, please say so. Thanks
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GIT d- s:++ a--- C++++ UL P+++>++++ L+ E- W++>+++ N !o K- w+ O---- M-- V--
PS PE Y- PGP t++(+++) 5(+++)++++ X R+@ tv+ b+++ DI+ D- G e->+++ h! r-- y-
------END GEEK CODE BLOCK------
Translate
"Weird things happen, get used to it."
Flame ~ Lead Programmer: GMS
Re: Win32::Gui + Threading?
by deadkarma (Monk) on Nov 12, 2001 at 06:40 UTC
|
I had the same dillema a while ago. I compiled perl with 'threading enabled' (which you can download here: http://www.imagemap.org/perl), and using both Win32::GUI and Tk, so get it to work the way I wanted it to.
Although it was a while ago, and I totally can't find the script, I think I ended up using Win32::GUI::Timer to do it.
I'm sorry I can't be of more help. This has gotten my interest though, and I'm going to try and find that script I wrote. . .
| [reply] |
|
I think the script is lost, but here is an example that might help:
use Win32::GUI;
$Win = new Win32::GUI::Window(
-left => 341,
-top => 218,
-width => 300,
-height => 191,
-name => "Win",
-text => "Window Title"
);
$Win->Show();
$Win->AddLabel(
-text => "Test",
-name => "Test",
-left => 121,
-top => 72,
-width => 49,
-height => 16,
-foreground => 0,
);
$Win->AddButton(
-text => "Do it",
-name => "doit",
-left => 100,
-top => 90,
-width => 65,
-height => 24,
);
Win32::GUI::Dialog();
sub doit_Click {
$t1 = $Win->AddTimer('T1', 10);
}
sub T1_Timer { # This gets called over and over again
$i++;
$Win->Test->Change(-text => "$i");
# You can put code here to read
# from a line from a socket or file
# and the GUI won't freeze up.
}
| [reply] [d/l] |
|
Hmm, it looks promising... but I really can't tie up the users internet connection like that (constant polling)...
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GIT d- s:++ a--- C++++ UL P+++>++++ L+ E- W++>+++ N !o K- W+ O---- M-- V--
PS PE Y- PGP t++(+++) 5(+++)++++ X R+@ tv+ b+++ DI+ D- G e->+++ h! r-- y-
------END GEEK CODE BLOCK------
Translate
"Weird things happen, get used to it."
Flame ~ Lead Programmer: GMS
| [reply] |
|
|
Well, this looks like it's suppost to support threads... and the thread module came with the thing...
I'll look into the other version of perl you pointed to.
C:\windows>perl -V
Summary of my perl5 (revision 5 version 6 subversion 0) configuration:
Platform:
osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
uname=''
config_args='undef'
hint=recommended, useposix=true, d_sigaction=undef
usethreads=undef use5005threads=undef useithreads=define usemultip
+licity=def
ine
useperlio=undef d_sfio=undef uselargefiles=undef
use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=u
+ndef
Compiler:
cc='cl', optimize='-O1 -MD -DNDEBUG', gccversion=
cppflags='-DWIN32'
ccflags ='-O1 -MD -DNDEBUG -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_D
+ES_FCRYPT
-DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DPERL_MSVCRT_READFIX'
stdchar='char', d_stdstdio=define, usevfork=false
intsize=4, longsize=4, ptrsize=4, doublesize=8
d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
+ lseeksize
=4
alignbytes=8, usemymalloc=n, prototype=define
Linker and Libraries:
ld='link', ldflags ='-nologo -nodefaultlib -release -libpath:"E:\
+Perl\lib\C
ORE" -machine:x86'
libpth="E:\Perl\lib\CORE"
libs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
+ comdlg32
.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uui
+d.lib wsoc
k32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib msvcrt.
+lib
libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl56.lib
Dynamic Linking:
dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -release -l
+ibpath:"E:
\Perl\lib\CORE" -machine:x86'
Characteristics of this binary (from libperl):
Compile-time options: MULTIPLICITY USE_ITHREADS PERL_IMPLICIT_CONTEX
+T PERL_IMP
LICIT_SYS
Locally applied patches:
ActivePerl Build 623
Built under MSWin32
Compiled at Dec 15 2000 16:27:07
@INC:
E:/Perl/lib
E:/Perl/site/lib
.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GIT d- s:++ a--- C++++ UL P+++>++++ L+ E- W++>+++ N !o K- W+ O---- M-- V--
PS PE Y- PGP t++(+++) 5(+++)++++ X R+@ tv+ b+++ DI+ D- G e->+++ h! r-- y-
------END GEEK CODE BLOCK------
Translate
"Weird things happen, get used to it."
Flame ~ Lead Programmer: GMS
| [reply] [d/l] |
|
It's compiled to support "ithreads" (interperator threads),
which are currently under development.
The "Thread" module is for 5.005-style threads, which are
not ithreads. 5.005-style threads are being abondoned, apparently
because they create race conditions that cannot be resolved
efficiently. I would advise against their use.
If you are interested,
there is an experimental "threads" module for ithreads
access from perl code.
The primary reason that it has threading support is to support forking emulation, because Windows does not
have a OS-level fork call. (See perlfork.)
You should be able to access threads this way, but beware
that Win32::GUI might have some problems
if you spawn threads while it's objects are in scope
because
it's (XS-based) destructors could be called prematurely, or twice.
update: (These problems may occur if
you merely have such objects in exsitence at time
of forking, even.)
| [reply] |
|
|
|
Re (tilly) 1: Win32::Gui + Threading?
by tilly (Archbishop) on Nov 12, 2001 at 19:23 UTC
|
| [reply] |
Re: Win32::Gui + Threading?
by Flame (Deacon) on Nov 13, 2001 at 08:04 UTC
|
Oh no...
You guys aren't gonna be happy about this. I think I've found the solution...
In lwpcook it says that you can specify a sub to run for each line that LWP downloads... All I need to do, apparantly, is stick a DoEvents() into the loop and everything SHOULD work... I think... It has another advantage in that it allows me to use a progress bar and abort in the middle of a download if someone wants to exit.
Regardless of whether or not I use any of these suggestions you all made, thanks. I always enjoy watching what happens when TMTOWTDI breaks out.
Thanks again.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GIT d- s:++ a--- C++++ UL P+++>++++ L+ E- W++>+++ N !o K- w+ O---- M-- V--
PS PE Y- PGP t++(+++) 5(+++)++++ X R+@ tv+ b+++ DI+ D- G e->+++ h! r-- y-
------END GEEK CODE BLOCK------
Translate
"Weird things happen, get used to it."
Flame ~ Lead Programmer: GMS
| [reply] |
|
I'm glad to have been able to amuse you.
=)
| [reply] |
|
|