moderne apps in wxperl - lichtkind.de · .... später nicht alles ist so einfach wie: use wx;...

69
Moderne Apps in WxPerl

Upload: others

Post on 26-Jun-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Moderne Apps in WxPerl

Page 2: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Moderne Apps in WxPerl

Page 3: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Moderne Kunst

Page 4: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Wir [sind] modern !

Page 5: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Moderne Zeiten

Page 6: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Verloren in der Moderne

Page 7: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

brauchen wir das ?

Page 8: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

modern = einfach + funktional

Page 9: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Wenn Perl ein Auto wäre:

Page 10: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Was ich modern meine:

Page 11: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Audacity

Page 12: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Kephra: wie Editoren sein sollen

Page 13: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

native crossplattform

Page 14: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

native crossplattform

Page 15: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

native crossplattform

Page 16: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Schön

Page 17: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

einfacher Harmonograph

Page 18: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Echter Harmonograph

Page 19: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Hözernes Buch

Page 20: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Blackburn 1844

Page 21: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

http://wxformbuilder.org/

Page 22: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Wx::XRC FBP

Page 23: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Wx::XRC

Page 24: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Erich Schubert

lass uns endlich coden

Page 25: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

.... später

Nicht alles ist so einfach wie:

use Wx;Wx::SimpleApp->new->MainLoop;

Wirklich alles coden?

Page 26: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

use Wx::XRC;

Wx::InitAllImageHandlers();my $xr = Wx::XmlResource->new();$xr->InitAllHandlers();$xr->Load('share/Harmonograph.xrc');

XRC einbinden

Page 27: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

use Wx::XRC;

Wx::InitAllImageHandlers();my $xr = Wx::XmlResource->new();$xr->InitAllHandlers();$xr->Load('share/Harmonograph.xrc');

my $frame = $xr->LoadFrame(undef, 'MyFrame1');

Irgendetwas laden

Page 28: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

use Wx::XRC;

Wx::InitAllImageHandlers();my $xr = Wx::XmlResource->new();$xr->InitAllHandlers();$xr->Load('share/Harmonograph.xrc');

my $frame = $xr->LoadFrame(undef, 'MyFrame1');

my $slider = $frame->FindWindow('m_slider1');

Widgets finden

Page 29: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Adam Kennedy: FBP

Page 30: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

my %wx;$wx{ $_ } = $frame->FindWindow($_)

for qw(m_slider1 m_slider2 ...);

Widgets finden

Page 31: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

my %wx;tie $wx{ $_ }, 'Tie::Wx', $frame->FindWindow($_)

for qw(m_slider1 m_slider2 ...);

Widgets finden

Page 32: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

sub TIESCALAR {my $class = shift;my $wx = shift;die "$wx is no Wx widget"

unless substr(ref $wx, 0, 4) eq 'Wx::';return bless { w => $wx, }, $class;

}sub FETCH { $_[0]->{'w'}->GetValue }sub STORE { $_[0]->{'w'}->SetValue($_[1]) }

package Tie::Wx;

Page 33: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Wozu das ganze?

$app{'text'.$_}->SetValue ($app{'slider'.$_}->GetValue) for 1..7;

Page 34: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Wozu das ganze?

$app{'text'.$_}->SetValue ($app{'slider'.$_}->GetValue) for 1..7;

$app{'text'.$_} = $app{'slider'.$_} for 1..7;

Page 35: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

OOP

Class::Accessor::Fast

MooseX::NonMoose

Page 36: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Anfangswerte setzensub set_defaults {

my $which = shift;my @label = qw(X Y X Y Betrag Reibung Dauer);my @ranges = (

[1,1,27],[1,1,27], [0,$amp, $amp*2], [0,$amp, $amp*2],[0,1,20],[0,0,100],[0,12,35],

);if ($which == -1){

for my $nr (1..7){$app{'label'.$nr}->SetLabel( $label[$nr-1].' : ' );$app{'slider'.$nr}->SetRange(@{$ranges[$nr-1]}[0,2]);$app{'keinerot'}->SetValue(1);set_defaults($nr);

}} elsif ($which > 0 and $which < 8){

$app{'text'.$which}->SetValue($ranges[$which-1][1]);$app{'slider'.$which}->SetValue($ranges[$which-1][1]);

Page 37: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Fallen

„normale“ API - Tücken

Page 38: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Alles ist ein Objekt

Seiteneffekt von C++

Oft umständlich für Perler

Klassen und Methoden sind CamelCase

Makros sind Uppercase

Konstanten auch nur wx-Präfix nicht

Page 39: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Parameter - Reihenfolge

Wx::Window->new ($elternwidget, # coderef

$id, # programmweit, $inhalt, # wert, text, klicked … etc $pos, # [ $x, $y ] Wx::Point->new( $x, $y ) $groesse, # [ $x, $y ] Wx::Size->new( $b, $h ) $stil, # benannte Konstanten … $name,);

Page 40: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Mach irgendetwas Wert = -1

Wx::Window->new ($elternwidget, # coderef, (undef)

$id, # programmweit, -1 aka wxID_ANY $inhalt, # wert, text, klicked … etc $pos, # [ -1, -1 ] $groesse, # [ -1, -1 ] $stil, # -1 = wxDEFAULT_FRAME_STYLE … $name,);

Page 41: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Parameter - Gruppen

my @def_par = ( $panel, -1, '' , [ -1, -1], [ -1, -1] ) ;

Wx::TextCtrl->new( @def_par, wxINTERESSANT );

Page 42: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Konstanten

use Wx;

Page 43: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Konstanten

use Wx; use Wx qw/ wxALL /;

Page 44: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Konstanten

use Wx; use Wx qw/ wxALL /; use Wx qw/ :everything /;

Page 45: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Konstanten

use Wx; use Wx qw/ wxALL /; use Wx qw/ :everything /;

wxALL => &Wx::wxALL;

Page 46: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Konstanten

use Wx; use Wx qw/ wxALL /; use Wx qw/ :everything /;

wxALL => &Wx::wxALL;

use Wx::Events qw/ :everything /;

Wx::Event::EVT_CHECKBOX( $cb, -1, sub { … } );

Page 47: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Sizer - Konstanten

my $std_al = wxALIGN_CENTER_VERTICAL | wxALL;

my $sizer_al = wxALL | wxGROW ;

my $last_al = wxLEFT | wxRIGHT | wxEXPAND ;

Page 48: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Rückgabewerte

package Harmonograph;use base qw(Wx::App);

sub OnInit {...1;

}

Page 49: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Hilfe

$widget->SetToolTip( 'Ich erklär dir mal die Welt' );

Page 50: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Tastaturbinding

$hframe->SetAcceleratorTable (Wx::AcceleratorTable->new (

[wxACCEL_CTRL, ord 'w', wxID_CLOSE], [wxACCEL_NORMAL, 27, wxID_CLOSE],));

wxNullAcceleratorTable

Page 51: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Logging

...

Page 52: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Bildbearbeitung

Wx::PaintDC->new( … );

EVT_PAINT( $self, sub {my( $self, $event ) = @_;

Page 53: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Bildbearbeitung

$dc->Clear();my $brush = Wx::Brush->new( wxGREEN, wxSOLID );$dc->SetBrush( );# grünes Rechteck als Hintergrund$dc->DrawRectangle( 0, 0, $x, $y );$dc->SetTextForeground( wxBLUE );# 3 Grad geneigter Text$dc->DrawRotatedText( "schräg", 30, 40, 3 );$dc->SetPen( Wx::Pen->new( $orange, 1, wxSOLID ) );# Kreisbogen von 30 Grad bis 130# auf einer 120x120 grossen "Ellipse"$dc->DrawEllipticArc( 90, 90, 120, 120, 30, 130 );

Page 54: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

AUI

use Wx::AUI;

Wx::Notebook => Wx::AuiNotebook

Page 55: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

AUI

use Wx::AUI;

Wx::Notebook => Wx::AuiNotebook

$manager = Wx::AuiManager->new();$manager->SetManagedWindow( $frame );

Page 56: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

AUI

use Wx::AUI;

Wx::Notebook => Wx::AuiNotebook

$manager = Wx::AuiManager->new();$manager->SetManagedWindow( $frame );

# package ...; our $manager

Page 57: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

AUI

$manager = Wx::AuiManager->new();$manager->SetManagedWindow( $frame );

$manager->AddPane( # wie AddPanel$widget, # oder $panelWx::AuiPaneInfo->new->( Konstanten… ),# Floatable, Movable, Resizable

);

$manager->Update; # ganz wichtig

Page 58: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

AUI Introspektion

$manager->Update; # ganz wichtig

my $pane = $manager->GetPane( $widget );$pane->Is..." ;

# Floatable, Movable, Resizable

Page 59: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

AUI Marshalling

my $string = $manager->SavePaneInfo ( $auiinfo );

# ... anderswo, andere Zeit$manager->LoadPaneInfo (

$string,Wx::AuiPaneInfo->new()

);$manager->Update; # ganz wichtig

Page 60: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

AUI Marshalling

my $string = $manager->SavePerspective();

# ... anderswo, andere Zeit$manager->LoadPerspective($string, 1);# 1 spart das $manager->Update;

Page 61: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

WxPerl::MenuMaker

[ {

name => 'file_open' ,icon => 'kephra.ico' ,tooltip => 'Öffnen' ,longhelp => 'Was ich schon …' ,associate => 'file_open' ,Menu => [ ... ] ,

} ,]

Page 62: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

wxPerl::Constructors

wxPerl::Frame->new ( $parent ,

$title , id => -1 , position => Wx::wxDefaultPosition(), size => Wx::wxDefaultSize(), style => Wx::wxDEFAULT_FRAME_STYLE(), name => wxFrameNameStr, );

Page 63: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Wx::GCL

panel (line (

label „X: “ blue slider 0 1 100 text

)seperator

button „Cancel“ button „Ok“)

Page 64: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Wx::Docular

Page 65: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Dicker Klopper

Page 66: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

Es gäbe der Beispiele mehr

Page 67: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

search.cpan.org/~mbarbon/Wx/

wxperl.sf.net

wxperl.info – Wiki

docs.wxwidgets.org/trunk – gute Doku

CPAN> install Wx::Demo

www.wxperl.co.uk - binäre Pakete

wxformbuilder.org

URL's

Page 68: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

www.himmelblauergarten.de/vortraege/perl.html

wiki.perl-community.de/Main/HerbertBreunung

wiki.perl-community.de/Wissensbasis/WxPerlTafel

de.perl.org

search.cpan.org/~lichtkind/

meine URL

Page 69: Moderne Apps in WxPerl - lichtkind.de · .... später Nicht alles ist so einfach wie: use Wx; Wx::SimpleApp->new->MainLoop; Wirklich alles coden?

www.himmelblauergarten.de/vortraege/perl.html

wiki.perl-community.de/Main/HerbertBreunung

wiki.perl-community.de/Wissensbasis/WxPerlTafel

de.perl.org

search.cpan.org/~lichtkind/

Danke