Schrift
[thread]5161[/thread]

3 TableMatrix Probleme...

Leser: 1


<< |< 1 2 3 >| >> 22 Einträge, 3 Seiten
zipster
 2006-02-20 14:26
#45244 #45244
User since
2004-09-06
458 Artikel
BenutzerIn
[default_avatar]
Hi,

ich habe 3 Probleme mit dem Modul Tablematrix und ich hoffe ihr könnt mir weiterhelfen.

Problem 1:
Ich würde gerne den Hintergrund aller Felder weiß haben.
Aber nur die Felder.
Wenn man das
Code (perl): (dl )
-bg => 'white',

nutzt wird alles weiß auch da wo keine Felder mehr sind.
Kann man das irgendwie anders lösen?

Habe mir gedacht das man es vieleicht mit
Code (perl): (dl )
$t->tagConfigure('title',  -bg => 'white', -fg => 'black');

lösen kann aber weiß nicht was man bei title eintragen muss damit alle Felder eingefärbt werden.

Problem 2:
Höhe der Tablematrix.
Ich habe zwar ne Höhe eingestellt aber wenn man weniger "Rows" hat passt sich die Tablematrix automatisch der Höhe an. Aber das möchte ich nicht haben.
Hat jemand ne Lösung für mich?

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
my $t = $page1->Scrolled(TableMatrix=>
            -cols => 8,
            -rows => 2,
            -colstretchmode => 'last',               
            -rowstretchmode => 'last',               
            -selectmode => 'extended',       
            -titlerows => 1,
            -variable => $arrayVar,
            -resizeborders => none,
            -height => 7 ,
            -width => 8,
            -maxwidth => 900,
            -scrollbars => 'oe',
               
 )->grid();


Ich bräuchte so was wie -minheight gibt&’s aber leider nicht

Problem 3:
Ich würde die einträge sortieren wenn man auf den title klickt.
weiß aber nicht wie ich das machen soll.



Wäre cool wenn mir jemand weiterhelfen könnte...

Gruß
Seri\n\n

<!--EDIT|zipster|1140438453-->
Crian
 2006-02-20 17:09
#45245 #45245
User since
2003-08-04
5866 Artikel
ModeratorIn
[Homepage]
user image
Die Mindesthöhe könntest du durch pack-Optionen erreichen (-expand => 1, -fill => 'both') bzw. analoges bei grid...

Zum Sortieren hätt ich nur ein Snippet für die HList... (http://www.duehl.de/christian/perl/perlmain.html#tksniphlist3) - vermutlich nicht sehr hilfreich :(\n\n

<!--EDIT|Crian|1140448273-->
s--Pevna-;s.([a-z]).chr((ord($1)-84)%26+97).gee; s^([A-Z])^chr((ord($1)-52)%26+65)^gee;print;

use strict; use warnings; Link zu meiner Perlseite
zipster
 2006-02-20 17:26
#45246 #45246
User since
2004-09-06
458 Artikel
BenutzerIn
[default_avatar]
Erstmal Danke für deine Antwort.

Code (perl): (dl )
 pack(-expand => 1, -fill => 'both');

Habe ich erst benutzt, ABER dann füllt die Tablematrix die ganze Notebook seite aus und das wollte ich dann auch nicht.

Dein Codeschnippsel habe ich erst benutzt. Bis mein Chef kam und gesagt hat "Es wäre schon wenn man die Einträge direkt in der Hlist ändern könnte..."
Crian
 2006-02-20 17:36
#45247 #45247
User since
2003-08-04
5866 Artikel
ModeratorIn
[Homepage]
user image
:D :(

wenn du das irgendwie hinbekommst, würd ich das wohl gern als weiteres Snippet aufnehmen :)\n\n

<!--EDIT|Crian|1140449815-->
s--Pevna-;s.([a-z]).chr((ord($1)-84)%26+97).gee; s^([A-Z])^chr((ord($1)-52)%26+65)^gee;print;

use strict; use warnings; Link zu meiner Perlseite
renee
 2006-02-21 03:37
#45248 #45248
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Man könnte vielleicht mit Bindings und Entries arbeiten:
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
use Tk::HList;
use Tk::ItemStyle;

my $mw = MainWindow->new();
my $hlist = $mw->Scrolled("HList",
-header => 1,
-columns => 4,
-scrollbars => 'osoe',
-width => 70,
-selectbackground => 'SeaGreen3',
-background => 'white',
)
->pack();


my $headerstyle = $hlist->ItemStyle('window',
-padx => 0,
-pady => 0,
);

my $btn_from = $hlist->Button(-text => 'From', -relief => 'flat', -command => [ \&MyTk::HList::order, 0, 0 ]);
my $btn_subj = $hlist->Button(-text => 'Subject', -relief => 'flat', -command => [ \&MyTk::HList::order, 1, 0 ]);
my $btn_date = $hlist->Button(-text => 'Date', -relief => 'flat', -command => [ \&MyTk::HList::order, 2, 0 ]);
my $btn_size = $hlist->Button(-text => 'Size', -relief => 'flat', -command => [ \&MyTk::HList::order, 3, 1 ]);

$hlist->header('create', 0, -itemtype => 'window', -widget => $btn_from, -style => $headerstyle);
$hlist->header('create', 1, -itemtype => 'window', -widget => $btn_subj, -style => $headerstyle);
$hlist->header('create', 2, -itemtype => 'window', -widget => $btn_date, -style => $headerstyle);
$hlist->header('create', 3, -itemtype => 'window', -widget => $btn_size, -style => $headerstyle);

my @x_coords = (2);

my @mails = (['test@email.de', 'Re:HList?', '1999-11-20', '1432'],
["dummy\@foo.com", "Re: HList?", "1999-11-21", "2335"],
['abc@foo.com', 'Re: Re: HList xxx?', '2004-10-12', '965'],
);

for my $index (0..$#mails) {
$hlist->add($index);
for my $textin (0..scalar(@{$mails[$index]}-1)) {
$hlist->itemCreate($index, $textin,
-text => $mails[$index]->[$textin],
);
}
}

my $x = 2;
for(0..3){
$x += $hlist->columnWidth(0);
push(@x_coords,$x);
}
print $_,"\n" for(@x_coords);

my $entry;
$hlist->bind('<Double-1>',[\&MyTk::HList::edit,Ev('x'),Ev('y')]);
$hlist->bind('<Button-1>',sub{if(defined $entry){$entry->destroy();$entry = undef}});

MainLoop();


# -----------------------------------------------------------------------------

package MyTk::HList;

my $last_btn;
my $switch;

BEGIN {
$last_btn = -1;
$switch = 0;
}

sub order {
my ($which, $numorder) = @_;

$hlist->delete('all');

my @sorted_mails = $numorder
? sort{$a->[$which] <=> $b->[$which]} @mails
: sort{$a->[$which] cmp $b->[$which]} @mails;

if ($which == $last_btn) {
$switch = 1 if $switch == 0;
$switch = -$switch;
@sorted_mails = reverse @sorted_mails if $switch == -1;
}
else {
$last_btn = $which;
$switch = 0;
}

for my $index(0..$#sorted_mails) {
$hlist->add($index);
for my $textin(0..scalar(@{$sorted_mails[$index]}-1)) {
$hlist->itemCreate($index, $textin,
-text => $sorted_mails[$index]->[$textin],
);
}
}
}

sub edit{
my ($hlist,$x,$y,$entryref) = @_;
my ($col,$width);
my $entryPath = $hlist->nearest($y);
if($hlist->info('exists',$entryPath)){
($col) = grep{$x > $x_coords[$_] && $x <= $x_coords[$_+1]}0..scalar(@x_coords)-1;
$width = $x_coords[$col+1] - $x_coords[$col];
print "X: $x .. Col: ",$col," -> ",$x_coords[$col],"/",$x_coords[$col+1]," .. Width: ",$width,"\n";
}
$entry = $mw->Entry()->place('-x' => $x_coords[$col], '-y' => $y);
}
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/
ptk
 2006-02-21 10:01
#45249 #45249
User since
2003-11-28
3645 Artikel
ModeratorIn
[default_avatar]
Ich habe dein Skript etwas verfeinert:
* keine Verwendung von absoluten Zahlen wie 2, sondern die aktuellen Werte von borderwidth und highlightthickness
* Fix beim Ausrechnen der @x_coords
* Versuch, das Entry exakt auf die Zelle zu positionieren. Außerdem ist das Entry jetzt weiß, wie das sonstige HList, und hat keinen Rahmen mehr.
* Füllen des Entries mit dem aktuellen Zellwert
Unter X11 sieht das jetzt anständig aus, unter Windows könnten vielleicht Widgets verschoben sein. Man müsste jetzt noch den Cursor im Entry richtig positionieren (Fleißarbeit, Benutzung von index() und fontMeasure()) und vielleicht ein <Return>-binding ans Entry hängen.

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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
use Tk::HList;
use Tk::ItemStyle;

my $mw = MainWindow->new();
my $hlist = $mw->Scrolled("HList",
-header => 1,
-columns => 4,
-scrollbars => 'osoe',
-width => 70,
-selectbackground => 'SeaGreen3',
-background => 'white',
)
->pack();


my $headerstyle = $hlist->ItemStyle('window',
-padx => 0,
-pady => 0,
);

my $btn_from = $hlist->Button(-text => 'From', -relief => 'flat', -command => [ \&MyTk::HList::order, 0, 0 ]);
my $btn_subj = $hlist->Button(-text => 'Subject', -relief => 'flat', -command => [ \&MyTk::HList::order, 1, 0 ]);
my $btn_date = $hlist->Button(-text => 'Date', -relief => 'flat', -command => [ \&MyTk::HList::order, 2, 0 ]);
my $btn_size = $hlist->Button(-text => 'Size', -relief => 'flat', -command => [ \&MyTk::HList::order, 3, 1 ]);

$hlist->header('create', 0, -itemtype => 'window', -widget => $btn_from, -style => $headerstyle);
$hlist->header('create', 1, -itemtype => 'window', -widget => $btn_subj, -style => $headerstyle);
$hlist->header('create', 2, -itemtype => 'window', -widget => $btn_date, -style => $headerstyle);
$hlist->header('create', 3, -itemtype => 'window', -widget => $btn_size, -style => $headerstyle);

my @x_coords = ($hlist->cget(-borderwidth) + $hlist->cget(-highlightthickness));

my @mails = (['test@email.de', 'Re:HList?', '1999-11-20', '1432'],
["dummy\@foo.com", "Re: HList?", "1999-11-21", "2335"],
['abc@foo.com', 'Re: Re: HList xxx?', '2004-10-12', '965'],
);

for my $index (0..$#mails) {
$hlist->add($index);
for my $textin (0..scalar(@{$mails[$index]}-1)) {
$hlist->itemCreate($index, $textin,
-text => $mails[$index]->[$textin],
);
}
}

my $x = $x_coords[0];
for(0..3){
$x += $hlist->columnWidth($_);
push(@x_coords,$x);
}
print $_,"\n" for(@x_coords);

my $entry;
$hlist->bind('<Double-1>',[\&MyTk::HList::edit,Ev('x'),Ev('y')]);
$hlist->bind('<Button-1>',sub{if(defined $entry){$entry->destroy();$entry = undef}});

MainLoop();


# -----------------------------------------------------------------------------

package MyTk::HList;

my $last_btn;
my $switch;

BEGIN {
$last_btn = -1;
$switch = 0;
}

sub order {
my ($which, $numorder) = @_;

$hlist->delete('all');

my @sorted_mails = $numorder
? sort{$a->[$which] <=> $b->[$which]} @mails
: sort{$a->[$which] cmp $b->[$which]} @mails;

if ($which == $last_btn) {
$switch = 1 if $switch == 0;
$switch = -$switch;
@sorted_mails = reverse @sorted_mails if $switch == -1;
}
else {
$last_btn = $which;
$switch = 0;
}

for my $index(0..$#sorted_mails) {
$hlist->add($index);
for my $textin(0..scalar(@{$sorted_mails[$index]}-1)) {
$hlist->itemCreate($index, $textin,
-text => $sorted_mails[$index]->[$textin],
);
}
}
}

sub edit{
my ($hlist,$x,$y,$entryref) = @_;
my ($col,$width);
my $entryPath = $hlist->nearest($y);
if($hlist->info('exists',$entryPath)){
($col) = grep{$x > $x_coords[$_] && $x <= $x_coords[$_+1]}0..scalar(@x_coords)-1;
$width = $x_coords[$col+1] - $x_coords[$col];
print "X: $x .. Col: ",$col," -> ",$x_coords[$col],"/",$x_coords[$col+1]," .. Width: ",$width,"\n";
}
$y = ($hlist->infoBbox($entryPath))[1];
my $y2 = ($hlist->infoBbox($entryPath))[3];
my $height = $y2-$y;
my $e = $hlist->itemCget($entryPath, $col, -text);
$entry = $hlist->Entry(-textvariable => \$e, -borderwidth => 0, -bg => $hlist->cget(-bg))->place('-x' => $x_coords[$col], '-y' => $y + $btn_from->height + $hlist->cget(-highlightthickness) + $hlist->cget(-borderwidth), -width => $width, -height => $height);
# XXX an die richtige Stelle positionieren: $entry->index(...);
}
zipster
 2006-02-21 10:09
#45250 #45250
User since
2004-09-06
458 Artikel
BenutzerIn
[default_avatar]
Jetzt bin ich Sprachlos... WOW...

Danke!

Will ja jetzt nicht unverschämt sein aber gibt es vieleicht noch die möglichkeit ein Feld als Browseentry und eins als Checkbutton darzustellen?
ptk
 2006-02-21 10:18
#45251 #45251
User since
2003-11-28
3645 Artikel
ModeratorIn
[default_avatar]
Das sollte analog funktionieren.

Alternativ kann man Widgets mittels "DisplayItems" in ein HList einbetten. Die Manpage dazu ist Tk::DItem. Ein Beispielskript findet man in der widget-Demonstration: "HList and ItemStyle, multicolumn listbox with individual cell styles".
zipster
 2006-02-21 16:25
#45252 #45252
User since
2004-09-06
458 Artikel
BenutzerIn
[default_avatar]
Hab die Demo gefunden.
Wenn ich sie ein wenig umstricke und mit dem Code oben kombiniere ist es genau das was ich will.

Ich verstehe nur ein Teil in dem Code der Demo nicht.

Kann mir mal jemand erklären was da passiert?
Code (perl): (dl )
1
2
3
4
5
6
7
8
    my $rnd_window = sub {
    my $yn = int(rand(10));
    if ($yn == 3) {
        ('Button', 'Entry')[rand(2)];
    } else {
        undef;
    }
    };


Bis dann
Seri\n\n

<!--EDIT|zipster|1140531994-->
Crian
 2006-02-21 17:12
#45253 #45253
User since
2003-08-04
5866 Artikel
ModeratorIn
[Homepage]
user image
$rnd_window ist eine Codereferenz. Ruft man sie auf ($rnd_window->()), dann gibt der Code entweder undef oder 'Button' oder 'Entry' zurück.
s--Pevna-;s.([a-z]).chr((ord($1)-84)%26+97).gee; s^([A-Z])^chr((ord($1)-52)%26+65)^gee;print;

use strict; use warnings; Link zu meiner Perlseite
<< |< 1 2 3 >| >> 22 Einträge, 3 Seiten



View all threads created 2006-02-20 14:26.