Tasks

 view release on metacpan or  search on metacpan

application/tasks.pl  view on Meta::CPAN

  dprint("set_task($name)\n", 2);
  stop_timer();
  $current_task = $task;
  $task_comment = '';
  start_timer() if ($task && $task->{name});
  $win->{basic}{mn_tasks}->configure(-text => $name,
				     -background => $color);
}

# Edit task
# Parameters:
#   $task - (optional) pointer to task, if not defined $current_task used
sub edit_task {
  my $task = shift;
  $task = $current_task unless $task;
  dprint("edit_task()\n", 2);
  unless ($task) {
    error("No task to edit");
    return;
  }
  my $popup = $win->{main}->Toplevel(-title => "Edit task \"$task->{name}\"");
  push(@{$win->{popups}}, $popup);

  my %t = ();
  map { $t{$_} = $task->{$_}; } ('name', 'id', '_text', 'priority',
				 'private', 'inactive');

  my %edit_win = ();

  # Create frames
  $edit_win{fr_buttons}  = $popup->Frame()->pack(-side=>'bottom');
  $edit_win{fr_note}     = $popup->Frame()->pack(-side=>'bottom');
  $edit_win{fr_subtasks} = $popup->Frame()->pack(-side=>'bottom');
  $edit_win{fr_main}     = $popup->Frame()->pack(-side=>'top', -fill=>'both',
						 -expand => "true");
  
  # Main entries
  my ($c1, $c2);
  $c1 = $edit_win{fr_main}->Label(-text => 'Task Name');
  $c2 = $edit_win{fr_main}->Entry(-textvariable => \$t{name});
  $c1->grid($c2, -sticky => 'w');
  
  $c1 = $edit_win{fr_main}->Label(-text => 'Priority');
  $c2 = $edit_win{fr_main}->Scale(-orient=>'horizontal', -length=>'30m',
				  -sliderlength=>'5m', -width=>'3m',
				  -from=>'0', -to=>'5',
				  -variable=>\$t{priority});
  $c1->grid($c2, -sticky => 'w');

  $c1 = $edit_win{fr_main}->Label(-text => 'Task is Private');
  $c2 = $edit_win{fr_main}->Checkbutton(-variable=>\$t{private});
  $c1->grid($c2, -sticky => 'w');

  $c1 = $edit_win{fr_main}->Label(-text => 'Inactivate task');
  $c2 = $edit_win{fr_main}->Checkbutton(-variable=>\$t{inactive},
					-text => '(almost the same as delete)');
  $c1->grid($c2, -sticky => 'w');

  # Statistics
  $c1 = $edit_win{fr_main}->Label(-text => 'Time statistics:');
  $c1->grid(-columnspan => 2, -sticky => 'ew');

  my ($l1, $l2, $time);
  $time = $tasks->get_total_time($task);
  $c1 = $edit_win{fr_main}->Label(-text => 'Time with subtasks');
  $c2 = $edit_win{fr_main}->Frame()->pack(-expand => 1, -fill => 'x');
  $l1 = $c2->Label(-text => convert_time($time))->pack(-side => 'left');
  $c2->Button(-text => 'Zero time',
	      -command => sub {
		$tasks->zero_time($task);
		$l1->configure(-text => convert_time(0));
		$l2->configure(-text => convert_time(0));
		})->pack(-side => 'right', -anchor => 'w');
  $c1->grid($c2, -sticky => 'w');
  $c2->gridConfigure(-sticky => 'we');

  $time = $tasks->get_total_time($task, {'this_only' => 1});
  $c1 = $edit_win{fr_main}->Label(-text => 'Time without subtasks');
  $c2 = $edit_win{fr_main}->Frame()->pack(-expand => 1, -fill => 'x');
  $l2 = $c2->Label(-text => convert_time($time))->pack(-side => 'left');
  $c2->Button(-text => 'Zero time',
	      -command => sub {
		$tasks->zero_time($task, 1);
		$l2->configure(-text => convert_time(0));
		$time = $tasks->get_total_time($task);
		$l1->configure(-text => convert_time($time));
	      })->pack(-side => 'right', -anchor => 'w');
  $c1->grid($c2, -sticky => 'w');
  $c2->gridConfigure(-sticky => 'we');

  my $total = $tasks->get_total_time(undef);
  $time     = $tasks->get_total_time($task);
  my $pcnt = $total ? $time * 100 / $total : 0;
  $pcnt =~ s/\.(..).*$/\.$1/g;
  $pcnt .= '%';
  $c1 = $edit_win{fr_main}->Label(-text => 'Percent of total time');
  $c2 = $edit_win{fr_main}->Label(-text => $pcnt);
  $c1->grid($c2, -sticky => 'w');

  my ($c, $r) = $edit_win{fr_main}->gridSize();
  for (my $i = 0; $i < $c; $i++) {
    $edit_win{fr_main}->gridColumnconfigure($i, -weight => 1);
  }
  
  # Subtasks
  my ($sel, $par);
  if (scalar(@{$task->{_tasks}})) {
    my $lv_height = scalar(@{$task->{_tasks}});
    map { $lv_height += scalar(@{$_->{_tasks}});} @{$task->{_tasks}};
    $lv_height = 5 if ($lv_height > 5);
    $edit_win{fr_subtasks}->Label(-text => 'SubTasks:')->pack(-side => 'top');
    $edit_win{lv_sub} = $edit_win{fr_subtasks}->Listbox(-selectmode=>'browse',
							-font => FIXED_FONT);
    $edit_win{sb_sub} = $edit_win{fr_subtasks}->
	Scrollbar(-command => [$edit_win{lv_sub} => 'yview'])
	    ->pack(-side => 'right', -fill => 'y');
    $edit_win{lv_sub}->configure(-yscrollcommand=>[$edit_win{sb_sub}=>'set']);
    $edit_win{lv_sub}->configure(-height => $lv_height,
				 -width => $g_listview_width);
    $edit_win{lv_sub}->pack(-side => 'top', -expand => 'true', -fill =>'both');
    $edit_win{lv_sub}->bind('<Double-ButtonPress-1>', sub {



( run in 1.260 second using v1.01-cache-2.11-cpan-2398b32b56e )