• Publicidad

Ayuda con Tk

¿Apenas comienzas con Perl? En este foro podrás encontrar y hacer preguntas básicas de Perl con respuestas aptas a tu nivel.

Ayuda con Tk

Notapor BigBear » 2009-10-25 10:15 @468

Hola.

Ando programando un pequeño programa que trabaja con Tk. Éste espía canales IRC e imprime lo sucedido en un ROtext.

El problema es que cuando minimizo la ventana es como si se tildara y está se volviera blanca y aparece "no responde".

¿Alguien me podría explicar por qué pasa eso y cómo lo soluciono?
BigBear
Perlero frecuente
Perlero frecuente
 
Mensajes: 981
Registrado: 2009-03-01 18:39 @818

Publicidad

Re: Ayuda con Tk

Notapor explorer » 2009-10-25 16:12 @717

¿Puedes publicar parte del código que replique el error?
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: Ayuda con Tk

Notapor BigBear » 2009-10-25 18:11 @799

Ok, publico todo el código que es más fácil.

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #usr/perl/bin
  2.  
  3. ##############MÓDULOS A USAR############################3
  4. use Tk;
  5. use LWP::UserAgent;
  6. use HTTP::Request;
  7. use LWP::Simple;
  8. use Tk::ROText;
  9. use IO::Socket;
  10. ######################################################3
  11.  
  12.  
  13. ################DISEÑO TK#################################3
  14. $mw = MainWindow->new( -background => "black", -cursor=>"crosshair");
  15. $mw->geometry("600x325+100+100");
  16. $mw->title("IRC-SPY by Guason");
  17.  
  18.  
  19. $tiempo = "1";
  20.  
  21. $mw->resizable(0,0);
  22.  
  23. $statusbar = "Status <NONE>";
  24. $statusbottom = $mw->Label(-textvariable => \$statusbar, -relief => 'flat', -background => "black", -foreground => "red", -font => "Verdana 7", -width => 120)->place(-x => 50, -y => 307);
  25.  
  26.  
  27. $mw->Label(-background => "black", -foreground => "black")->pack();
  28. $stat = "Log extraido";
  29. $sta = $mw->Label(-textvariable => \$stat, -relief => 'flat', -background => "black", -foreground => "yellow", -font => "Verdana 9")->place(-x => 380, -y => 10);
  30.  
  31.  
  32.    my $espacio = $mw->Scrolled('ROText', -scrollbars => 'oe', -font => "Verdana 8", -background => "black", -foreground => "yellow", -selectbackground => "yellow", -insertbackground => "yellow", -relief => "ridge", -width => 55, -height=> 20)->pack(-side => 'right', -anchor => 'e');
  33. $mw->Label(-background => "black", -foreground => "black")->pack();
  34. $mw->Label(-background => "black", -foreground => "black")->pack();
  35. $mw->Label(-background => "black", -foreground => "black")->pack();
  36.  
  37. ############################ESPACIOS A COMPLETAR#########################################3
  38.  
  39.  
  40. $mw->Label(-background => "black", -foreground => "yellow", -font => "Verdana 9", -text => "Servidor IRC")->pack(-anchor => 'nw');
  41. my $ent_google = $mw->Entry(-background => "black", -foreground => "yellow", -selectbackground => "black", -insertbackground => "yellow", -width => 40, -relief => "ridge", -textvariable=>\$server)->pack(-anchor=> 'nw');
  42.  
  43.  
  44.  
  45. $mw->Label(-background => "black", -foreground => "yellow", -font => "Verdana 9", -text => "Canal")->pack(-anchor => 'nw');
  46. my $ent_string = $mw->Entry(-background => "black", -foreground => "yellow", -selectbackground => "black", -insertbackground => "yellow", -width => 40, -relief => "ridge", -textvariable => \$canal)->pack(-anchor => 'nw');
  47.  
  48. $mw->Label(-background => "black", -foreground => "yellow", -font => "Verdana 9", -text => "Nombre del bot")->pack(-anchor => 'nw');
  49. my $ent_num = $mw->Entry(-background => "black", -foreground => "yellow", -selectbackground => "black", -insertbackground => "yellow", -width => 40, -relief => "ridge", -textvariable => \$nick)->pack(-anchor => 'nw');
  50.  
  51.  
  52.  
  53. $mw->Label(-background => "black", -foreground => "black")->pack();
  54. $mw->Label(-background => "black", -foreground => "black")->pack();
  55. ####################################################################################3
  56. ###############BOTONES###################################################################3
  57. $mw->Button(-activebackground => "yellow",  -activeforeground => "black",  -background => "black", -foreground => "yellow", -font => "Verdana 7", -relief => "groove", -text => "Start", -width => 5, -command => \&ven)->place(-x => 80, -y => 250);
  58.  
  59. $mw->Button(-activebackground => "yellow",  -activeforeground => "black",  -background => "black", -foreground => "yellow", -font => "Verdana 7", -relief => "groove", -text => "Ver Log", -width => 8, -command => \&log)->place(-x => 40, -y => 40);
  60.  
  61.  
  62. $mw->Button(-activebackground => "yellow",  -activeforeground => "black",  -background => "black", -foreground => "yellow", -font => "Verdana 7", -relief => "groove", -text => "Clear",  -width => 5, -command => \&cls)->place(-x => 130, -y => 40);
  63.  
  64. $mw->Button(-activebackground => "yellow",  -activeforeground => "black",  -background => "black", -foreground => "yellow", -font => "Verdana 7", -relief => "groove", -text => "Help/About", -width => 9, -command => \&about)->place(-x => 50, -y => 300);
  65.  
  66. $mw->Button(-activebackground => "yellow",  -activeforeground => "black",  -background => "black", -foreground => "yellow", -font => "Verdana 7", -relief => "groove", -text => "Exit",  -width => 5, -command => sub { exit })->place(-x => 133, -y => 300);
  67.  
  68. #################################################################################################3
  69.  
  70. MainLoop;
  71.  
  72.  
  73. ##########################FIN DEL DISEÑO#################################################33
  74. sub about {
  75. $about = $mw->Toplevel(-background => "black", -cursor=>"crosshair");
  76. $about->geometry("500x422+425+250");
  77. $about->title("Google-search by Guason");
  78. $about->resizable(0,0);
  79. $about->Label(-background => "black", -foreground=>"yellow")->pack();
  80. $about->Label(-background => "black", -foreground=>"yellow", -font=> "Cambria 10", -text => "IRC BOT\n")->pack();
  81. $about->Label(-background => "black", -foreground=>"yellow", -font=> "Cambria 10",  -text => " Este programa fue escrito por Guason\n")->pack();
  82. $about->Label(-background => "black", -foreground=>"yellow", -font=> "Cambria 10",  -text => " Con esta hermosura espiaras al canal que quieras\n\nEspero que te sirva\n\n")->pack();
  83. $about->Label(-background => "black", -foreground=>"yellow", -font=> "Cambria 10",  -text => "Si necesitan contactarme mi email es chairface_darkhat[dot]hotmail.com ")->pack();
  84. $about->Label(-background => "black", -foreground=>"yellow")->pack();
  85.  
  86.  
  87. $about->Label(-background => "black",-foreground => "yellow",-font => "wingdings 22", -text => "7")->pack();
  88. $about->Label(-background => "black", -foreground=>"yellow", -font=> "Cambria 11",  -text => "Written By Guason || 2009")->pack();
  89.  
  90.  
  91.  
  92. $about->Button(-activebackground => "yellow",  -activeforeground => "black",  -background => "black", -foreground => "yellow", -relief => "groove", -font=> "Verdana 7", -text => "Exit", -command => [$about => 'destroy'])->pack(-fill => "both");
  93.  
  94. }
  95.  
  96. ########################################START##################################
  97. sub ven {
  98.  
  99. $port = "6667";
  100. $file = "irc-spy.txt";
  101.  
  102.  
  103. my $server =  $ent_google -> get();
  104. my $canal =  $ent_string -> get();
  105. my $nick =  $ent_num -> get();
  106.  
  107.  
  108.  
  109.  
  110. my $connection = new IO::Socket::INET(   PeerAddr =>$server,
  111.                                                                      PeerPort => $port,
  112.                                                                       Proto => 'tcp' );
  113.  
  114. if (!$connection) {
  115. print "\nNo se puedo conectar en  $server $port\n";
  116. exit 1;
  117. }
  118.  
  119. print $connection "NICK $nick\r\n";
  120. print $connection "USER $nick 1 1 1 1\r\n";
  121.  
  122.  
  123. print "\nDentro!\n\n";
  124.  
  125. print FILE "#####Canal $canal#######\n\n";
  126.  
  127.  
  128. while($response = <$connection>) {
  129.  
  130.  
  131.  
  132.  
  133.  if($response =~ m/^PING (.*?)$/gi){print $connection "PONG ".$1."\r\n";}
  134.  if($response =~ m/:(.*) 00(.*) (.*) :/){print $connection "JOIN $canal\r\n";
  135. }
  136.  
  137.  
  138. if ( $response =~ m/:(.*)!(.*):(.*)/ig) {
  139.  
  140.  
  141.  
  142. my $nicke = $1;
  143. my $texto = $3;
  144.  
  145. if ($texto ne $canal) {
  146.  
  147.  
  148. $statusbottom->update();
  149.  
  150.  
  151.  open (R , ">>$file");
  152.  
  153. $espacio -> insert('end', "$nicke = $texto\n");
  154. print "$nicke = $texto\n";
  155. }
  156.  
  157. }
  158.  
  159. }
  160.  
  161. }
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170. ################################BOTÓN PARA LIMPIAR LA PANTALLA#########################################
  171. sub cls {
  172.  
  173.   $espacio -> delete('0.1', 'end');
  174.  
  175. }
  176.  
  177. ####################VER LOG###################################
  178. sub log {
  179. system ("irc-spy.txt");
  180. }
  181. ###########################################################
Coloreado en 0.009 segundos, usando GeSHi 1.0.8.4
BigBear
Perlero frecuente
Perlero frecuente
 
Mensajes: 981
Registrado: 2009-03-01 18:39 @818

Re: Ayuda con Tk

Notapor explorer » 2009-10-26 17:15 @760

Es que... yo no veo que llames por ninguna parte al método iconify() para que la ventana se esconda...
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: Ayuda con Tk

Notapor BigBear » 2009-10-26 20:49 @909

¡Ah, no!, me expresé mal; no me refiero a que quiero minimizar la ventana con una función Tk, sino que cuando le doy clic al botón "start" el programa se tilda y aparece "no responde". Por eso ni cuando le doy al botón minimizar todavía queda tildado. Ahora que lo pienso bien, necesito una constante actualización de la ventana Tk. Vi que se usa $mw->update pero aún no sé cómo hacerlo porque todavía queda como tildado.

La parte que tendría que arreglar sería esta:

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #
  2. if ( $response =~ m/:(.*)!(.*):(.*)/ig) {
  3.  
  4. $mw->update;  
  5.  
  6. my $nicke = $1;
  7. #
  8. my $texto = $3;
  9. #
  10.  
  11. #
  12. if ($texto ne $canal) {
  13. #
  14. a
  15.  open (R , ">>$file");
  16. #
  17.  
  18. #
  19. $espacio -> insert('end', "$nicke = $texto\n");
  20. #
  21. print "$nicke = $texto\n";
  22. #
  23. }
  24. #
  25.  
  26. #
  27. }
  28. #
  29.  
  30. #
  31.  
  32. }
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4


Lo que tendría que hacer es que cada vez que entre más texto del chat, esta ventana se actualice. ¿Cómo lo haría?
Última edición por explorer el 2009-10-27 03:20 @180, editado 1 vez en total
Razón: Ortografía
BigBear
Perlero frecuente
Perlero frecuente
 
Mensajes: 981
Registrado: 2009-03-01 18:39 @818

Re: Ayuda con Tk

Notapor explorer » 2009-10-27 04:55 @246

Efectivamente, al entrar en la subrutina de vigilancia, se pierde la oportunidad de actualizar los eventos de la ventana.

Ahora mismo no lo sé, pero eso quizás se resolvería llamando a un método del mainwindow que permitiera procesar los eventos del usuario. Algo así se usaba hace veinte años con los primeros sistemas operativos orientados a gráficos: en las rutinas que ocupaban mucha CPU, se incorporaban una llamada al sistema que permitía al resto de la aplicación responder a los eventos del usuario. Así, el usuario no sentía que la aplicación había quedado bloqueada cuando entraba en ese cálculo.

Hoy en día, en Perl, se suele usar Tk con la ayuda de POE, permitiendo una pseudo-multitarea, simplificando bastante ese proceso. Viene un ejemplo de lector de RSS.
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España


Volver a Básico

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 42 invitados

cron