Advertisement

03.16.2007 at 05:31AM PDT, ID: 22453687
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.6

Perl tk object instances

Asked by Morcalavin in Perl Programming Language

Tags: , ,

I'm working on a msn style "toast" alert in perl/tk.  While I'm still early on in development, I've hit a bit of a snag.  I'm not too familiar with how perl handes object insances, but I seem to be having a problem where my objects seem to be interfering with one another.

Example, when clicking on the "Toast" button on the main window, the toast window appears and begins it's routine.  When the ".toast" window is selected on the Toast window, the window shrinks like it's supposed to.  However, if I open another toast window while there is already one displayed, the second window will shrink like it's supposed to, but the first window will not and it looks like the geometry values it's getting are from the second window, not the first.  Create a couple of toast windows, wait for them to load, then try to close them all to see what I mean.  How do I make it so variables are unique to each instance of a Toast object?

Toast.pm

package Tk::Toast;

use vars qw($VERSION);
$VERSION = '0.1';

use strict;
use Carp;
use Tk::StayOnTop;
use Tk::After;
use base qw(Tk::Toplevel);

Construct Tk::Widget 'Toast';


sub Populate {
      my ($self, $args) = @_;
      $self->update;
      $self->overrideredirect(1);
      my $widgetwidth = $self->height;
      my $widgetheight = $self->width;
      my $widgetx = $self->toplevel->screenwidth - $widgetwidth;
      my $widgety = $self->toplevel->screenheight;
      $self->stayOnTop;
      $self->geometry("$widgetwidth" . 'x' . "$widgetheight" . '+' . "$widgetx" . '+' . "$widgety");
}


sub Grow {
      my ($self, $args) = @_;
      my $grow;
      $grow = $self->repeat(10, sub{ Grow_backend($self, $grow);});
}

sub Grow_backend {
      my ($self, $timer) = @_;
      my @growy = split(/\+/, $self->geometry);
      my $growy = $growy[2];
      $growy--;
      my $growwidgetwidth = $self->height;
      my $growwidgetheight = $self->width;
      my $growwidgetx = $self->toplevel->screenwidth - $growwidgetwidth;
      my $growwidgety = $self->toplevel->screenheight;
      if($growy < ($growwidgety - $growwidgetheight)) {
            $timer->cancel;
      }
      $self->geometry("$growwidgetwidth" . 'x' . "$growwidgetheight" . '+' . "$growwidgetx" . '+' . "$growy");
      print $self->geometry . "\n";
}

sub Shrink {
      my ($self, $args) = @_;
      my $shrink;
      $shrink = $self->repeat(10, sub{ Shrink_backend($self, $shrink);});
}

sub Shrink_backend {
      my ($self, $timer) = @_;
      my @shrinky = split(/\+/, $self->geometry);
      my $shrinky = $shrinky[2];
      $shrinky++;
      my $shrinkwidgetwidth = $self->height;
      my $shrinkwidgetheight = $self->width;
      my $shrinkwidgetx = $self->toplevel->screenwidth - $shrinkwidgetwidth;
      my $shrinkwidgety = $self->toplevel->screenheight;
      if($shrinky > $shrinkwidgety) {
            $timer->cancel;
      }
      $self->geometry("$shrinkwidgetwidth" . 'x' . "$shrinkwidgetheight" . '+' . "$shrinkwidgetx" . '+' . "$shrinky");
      print $self->geometry . "\n";
}

1;


Test.pl

use lib 'c:/perl/';
use Tk;
use Toast;

$main = new MainWindow();
$button = $main->Button(-text => 'Toast!', -command => \&toaster)->pack();
MainLoop;


sub toaster() {
      $toast = $main->Toast();
      $button2 = $toast->Button(-text => $toast, -command => sub{$toast->Shrink;})->pack();
      $toast->Grow();
}Start Free Trial
[+][-]03.16.2007 at 07:22AM PDT, ID: 18734942

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Perl Programming Language
Tags: perl, tk, toplevel
Sign Up Now!
Solution Provided By: Adam314
Participating Experts: 1
Solution Grade: A
 
 
[+][-]03.16.2007 at 07:33AM PDT, ID: 18735051

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.16.2007 at 03:02PM PDT, ID: 18738207

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32