Thread HList mit sortierenden Buttons (6 answers)
Opened by Crian at 2005-08-05 18:03

Strat
 2005-08-08 16:12
#44292 #44292
User since
2003-08-04
5246 Artikel
ModeratorIn
[Homepage] [default_avatar]
ich habe dafuer mal das folgende verbrochen (haesslich, aber funktioniert fuer meine beduerfnisse; ein bind waere vielleicht schoener, ebenso eine korrekte uebergabe einer Datenstruktur @::Data fuer die Werte):
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# -------------------------------------------------
package Mlh::Callbacks;
sub SortTableByField {
   my ($table, $id) = @_;

   # sort @::Data by column $id with Schwartzian Transform
   @::Data = map { $_->[1] }
   sort { $a->[0] cmp $b->[0] }
   map { [ lc($_->[$id]), $_ ] }
   @::Data;

   # update table according to new order of @::Data
   &UpdateTable($table, \@::Data);
} # SortTableByField
# --------------------------------------------------------
sub UpdateTable {
   my ($table, $data) = @_;

   $table->delete('all', '');
   foreach my $i (0..$#$data) {
&TableInsertRow($table, $data->[$i]);
   } # foreach

} # UpdateTable
# ---------------------------------------------------------
package Mlh::Widgets;

sub Table {
   my ($frame, $headline, $browseCmd, $background, %options2) = @_;

   my %options = (-header => 1, -background => '#ffffff', -gap => 10,
  -selectmode => 'single',
  -font => $Mlh::Config::StandardFont,);
   $options{-browsecmd}        = $browseCmd if (ref $browseCmd);
   $options{-background}       = $background || '#ffffff';
   $options{-selectbackground} = $Mlh::Config::Background;

   my $hl = $frame->Scrolled('MyHList', -scrollbars => 'osoe',
     -columns => scalar(@$headline),
     %options, %options2);

   my $styleButton = $hl->ItemStyle('window');
   $styleButton->configure(-pady => 0, -padx => 0);

   foreach my $i (0..$#$headline) {
my $button = $hl->Button
 (-text => $headline->[$i], -relief => 'flat',
  -font => $Mlh::Config::FixedFont,
  -activebackground => $Mlh::Config::Background,
  -command => [ \&Mlh::Callbacks::SortTableByField, $hl, $i ],
  );

$hl->header('create', $i++, -itemtype => 'window',
   -widget => $button, -style  => $styleButton);
   } # foreach

   return $hl;
} # Table
# ------------------------------------------------
package Tk::MyHList;
use base qw(Tk::Derived Tk::HList);
Construct Tk::Widget 'MyHList';

sub Populate {
   my ($self, $args) = @_;

   my $rightClick = delete $args->{-rightClick};
ref($rightClick) and $self->bind('<ButtonPress-3>', $rightClick);

   $self->SUPER::Populate($args);
} # Populate
# ============================================
perl -le "s::*erlco'unaty.'.dk':e,y;*kn:ai;penmic;;print"
http://www.fabiani.net/

View full thread HList mit sortierenden Buttons