Schrift
[thread]5235[/thread]

wxPerl Verständnisfrage: Wie kann ich auf Objekte zugreifen?

Tags: Ähnliche Threads

Leser: 3


<< >> 2 Einträge, 1 Seite
Gast Gast
 2006-09-11 11:55
#45830 #45830
Hi zusammen,

ich bin grad dabei, mein erstes Programm mit wxPerl zu schreiben:

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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/perl -w
use strict;
use Wx;

package MyFrame;

#use base qw(Wx::Frame);

use vars qw(@ISA);

@ISA = qw(Wx::Frame);


# import the event registration function
use Wx::Event qw(EVT_BUTTON);
use Wx::Event qw(EVT_CHECKLISTBOX);


sub new {
my $ref = shift;
my $self = $ref->SUPER::new( undef, # parent window
-1, # Fenter id
'WxPerl Window', # Titel
[60,-1], # Position x/y
[870, 500] # Größe x/y
);
# load an icon and set it as frame icon
$self->SetIcon( Wx::GetWxPerlIcon() );

# controls should not be placed directly inside
# a frame, use a Wx::Panel instead
my $panel = Wx::Panel->new( $self, # parent window
-1, # ID
);


# create the bündel checklistbox überschrift
my $b_text = Wx::StaticText->new( $panel, # parent window
-1, # ID
'Dateien', # label
[30, 80], # position
[-1, -1], # default size
);

# create the bündel checklistbox
my $leftchecklistbox = Wx::CheckListBox->new( $panel,
-1,
[30, 100],
[400, 220],
[ qw(Full_Package_1 Upd_Package_1_1 Upd_Package_1_2 Upd_Package_1_3
Full_Package_2 Upd_Package_2_2 Full_Package_3 Upd_Package_3_1 Upd_Package_3_2) ]
);


# create the daten übernehmen button
my $du_button = Wx::Button->new( $panel, # parent window
-1, # ID
'Datei laden', # label
[30, 330], # position
[-1, -1], # default size
);

# register the OnClick method as an handler for the
# 'button clicked' event. The first argument is a Wx::EvtHandler
# that receives the event
EVT_BUTTON( $self, $du_button, \&OnClick );

# create the pakete checklistbox überschrift
my $p_text = Wx::StaticText->new( $panel, # parent window
-1, # ID
'Auswahl', # label
[440, 80], # position
[-1, -1], # default size
);

my $rightchecklistbox = Wx::CheckListBox->new( $panel, # parent window
-1, # ID
[440, 100], # position
[400, 220],
); # default size

# create the daten löschen button
my $dl_button = Wx::Button->new( $panel, # parent window
-1, # ID
'Daten löschen', # label
[440, 330], # position
[-1, -1], # default size
);

# register the OnClick method as an handler for the
# 'button clicked' event. The first argument is a Wx::EvtHandler
# that receives the event
EVT_BUTTON( $self, $dl_button, \&OnClick );

# create the makecd button
my $mi_button = Wx::Button->new( $panel, # parent window
-1, # ID
'CD-Images erzeugen', # label
[720, 330], # position
[120, -1], # default size
);

# register the OnClick method as an handler for the
# 'button clicked' event. The first argument is a Wx::EvtHandler
# that receives the event
EVT_BUTTON( $self, $mi_button, \&OnClick );

# create a status bar
my $status = Wx::StatusBar->new( $self, -1 );
$status -> SetFieldsCount( 1 );
$status -> SetStatusText( "Programm gestartet!" );
$self->SetStatusBar($status);


return $self;
}

# this method receives as its first parameter the first argument
# passed to the EVT_BUTTON function. The second parameter
# always is a Wx::Event subclass
sub OnClick {
my( $self, $event ) = @_;

# Question: Which button was pressed????
my $b_pressed = "dont know";

# Ausgewählte Dateien einlesen und in Liste einfügen
# Question: Wie????

$self -> SetStatusText("Daten wurden aktualisiert!");

}


package MyWindow; # Definition des obersten Objekts
use base qw(Wx::App); # Inherit from Wx::App

sub OnInit {
my $frame = MyFrame->new;
$frame->Show( 1 );
}


package main;
my $wxobj = MyWindow->new(); #Hier wird die Anwendung gestartet
$wxobj->MainLoop;


Sieht auch schon gut aus, nur weiß ich im Moment nicht, wie ich das mit Leben fülle. In dem linken Fenster leftchecklistbox soll der Benutzer Files auswählen, wenn er auf den Button du_button drückt, soll der Inhalt dieser Dateien ins rechte Fenster geschrieben werden.

Jetzt hab ich zwei Fragen (siehe Smilies im Code):
Wie finde ich heraus, welcher der Buttons gedrückt wurde, wenn ich für alle die gleiche Funktion verwende?
Und wie erfahre ich, welche Zeilen markiert wurden und wie fülle ich rightchecklistbox mit meinen Daten? In dem Moment hab ich ja nicht mehr diese Variable, also muss ich irgendwie auf das Objekt zugreifen, nur wie???

Ich stell mich wahrscheinlich grad ein bißchen glatt an... Help!

Gruß Daniel
lichtkind
 2006-09-11 12:04
#45831 #45831
User since
2004-03-22
5679 Artikel
ModeratorIn + EditorIn
[Homepage]
user image
einfügen meist mit append siehe wxwidgets doku. und normal macht man das ja nicht das mehrere button das gleiche machen aber du dann doch wissen willst wer gedrückt wurde.
vielleicht aber:

EVT_BUTTON( $self, $dl_button, sub {OnClick (@_, 'button_id')} );
Wiki:Tutorien in der Wiki, mein zeug:
kephra, baumhaus, garten, gezwitscher

Es beginnt immer mit einer Entscheidung.
<< >> 2 Einträge, 1 Seite



View all threads created 2006-09-11 11:55.