Os Wilhelm

2,440 views
2,288 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,440
On SlideShare
0
From Embeds
0
Number of Embeds
44
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Os Wilhelm

  1. 1. wxPerl Agile Cross-Platform GUI Development (What I had to Learn the Hard Way) Eric Wilhelm Scratch Computing http://scratchcomputing.com
  2. 2. wxPerl bindings for wxWidgets GUI toolkit ● multi-platform ● native widgets ● object-oriented ● event driven ●
  3. 3. wxWidgets platforms Win32 – Mac OS X – GTK+ – X11 – Motif – WinCE – and more –
  4. 4. Windows
  5. 5. Linux
  6. 6. Mac
  7. 7. Why Desktop Apps? local machine resources ● large files – soundcard – cpu – private data ● encryption ● airplanes ●
  8. 8. Why Perl? freedom from ● static code – compilers – quot;cross-platform reinvention of string – librariesquot; easier reuse ● common (e.g. company-wide) modular – code web apps – command-line apps –
  9. 9. The “Wx” distribution (aka wxPerl) wraps wxWidgets in XS and some Perl ● 332K tarball ● breakdown: ●   xs:          ~21680 (57.42%)   perl:          8685 (23.00%)   cpp:           7395 (19.58%)   xsp:          ~1662 note: SLOCCOUNT doesn't really speak XS but very little documentation ●
  10. 10. Compare to WxGTK (i.e. core+gtk port) 6.9M of C++ ! ● 20x21k cpp:         416710 (77.09%)  ansic:       112754 (20.86%)  sh:           10026 (1.85%)  python:         645 (0.12%)  lex:            194 (0.04%)  yacc:           128 (0.02%)  pascal:          74 (0.01%)  lisp:             6 (0.00%) generated using David A. Wheeler's 'SLOCCount'
  11. 11. dotReader open-source e-book reader in Perl read, annotate, and search books ● browse the web, send mail, etc ● shared annotations ● online/offline network fun – DRM (makes publishers happy) ● flexible, environment-agnostic architecture ● open source ● plugins, plugins, plugins ●
  12. 12. dotReader details today's raw numbers (Jun. 25th, 2007) ● 13K SLOC 98 modules + ~1200 line Build subclass drop-in distributions ● linux/qdos - PAR – mac - PerlWrapper + ExtUtils::MacMaker – embedded html widgets ● IE (activeX) – Webkit – Mozilla –
  13. 13. Getting Started with wxPerl Finding Documentation wxPerl specific ● a slow wiki (somebody please make a US – mirror) not much pod – some perlmonks stuff – demo directory – C++ documentation ● C++ examples ● wxGlade ●
  14. 14. Cross-platform Development (aka fun with vnc) svk and working copy on linux workstation ● more and better tools – 80% or more development is command-line – tests ● ● small utilities ● good discipline ● good for architecture rsync+fam ● rdesktop/vnc to windows+cygwin ● vnc to mac ●
  15. 15. Cross-platform Builds automate ● automate ● automate ● Module::Build ● CPDK + remote ssh automation ● nightly builds ● cross-platform repackaging from linux ●
  16. 16. Installation (aka fun with make/nmake/bake/shake/quake) Linux ● debian (sarge, etch) – Windows ● camelpack + sourceforge PPMs – ExtUtils::FakeConfig ● Strawberry – Mac ● xcode – cpan –
  17. 17. wxGlade
  18. 18. BAD code generation and why it is (maybe) a good idea XRC (speed?) ● segregate generated code ● have a consistent environment ● windows vs linux, glade versions – use version control! ● use subversion – have to make it be valid (strict) Perl ● stupid regular expressions do the trick –
  19. 19. Getting Past Getting Started copy and paste is evil ● strive for deep clarity, not superficial ● don't ape glade ● don't ape C++ ● don't even ape the examples ●
  20. 20. Leaving “Getting Started” Way Behind modularity ● subclassing ● traits ● CMT / POE for responsiveness ● subprocesses ● discipline ● as always, but particularly because we don't – have “best practices” in this realm yet
  21. 21. Eliminating Tabular Code   EVT_MENU( $self, 5007, sub {$_[0]­>activate_sidebar($_[1])});   EVT_MENU( $self, 5011, sub {$_[0]­>activate_reader($_[1])});   ...   my $acc_table = Wx::AcceleratorTable­>new(     [0,             WXK_F2,   5007, ], # activate sidebar     [0,             WXK_F3,   5011, ], # activate widget     ...   );   $self­>SetAcceleratorTable($acc_table); my $acc_table = Wx::AcceleratorTable­>new(   map({$self­>_accel(@$_)}     ['F2',     sub {$_[0]­>activate_sidebar($_[1]);}],     ['F3',     sub {$_[0]­>activate_reader($_[1]); }],     ...   ), ); $self­>SetAcceleratorTable($acc_table);
  22. 22. needs Perlin' ... if($stroke =~ s/^(.*)+//) {   my $mk = 'wxACCEL_' . $1;   Wx­>can($mk) or croak(quot;cannot find modifier key $mkquot;);   $mod = Wx­>$mk; } ... if($kl > 1) {   my $key_const = 'WXK_' . $key;   Wx­>can($key_const) or croak(quot;cannot find keyquot;);   $key = Wx­>$key_const; } else {   # it's a letter   $key = ord(uc($key)); } my $id = Wx::NewId; Wx::Event::EVT_MENU($self, $id, $subref); return([$mod, $key, $id]);
  23. 23. More Perlification can() doesn't work right ● wxPerl::Constructors ● wxPerl::Styles ● wxPerl::Lay_er_outer ??? ●
  24. 24. What we really want is a better wxGlade? stealing ideas from smalltalk ● (without losing unixness) – named objects and accessors ● DSL / YAML ● read + write and in-process dynamicism ● procedural / config-integration ● and/or code-snippet insertion? ●
  25. 25. Other Thoughts menu introspection ● (WxPerl::MenuMaker) event driven OOP ● break into small pieces (e.g. – backend_file_open) callbacks ● closures – method calls – NOT &subname, please – accessors ● Needs more Perlin' -- WxPerl/foo.pm ●
  26. 26. Wx::Perl/wxPerl Modules on CPAN wxPerl::Constructors ● wxPerl::Styles ● Wx::Perl::Throbber ● Wx::Perl::ProcessStream ● Wx::Perl::Imagick ● Wx::TreeListCtrl ●
  27. 27. Browser Widgets wxMozilla / Wx::Mozilla ● my eyes are bleeding! – Wx::WebKit ● Wx::ActiveX ● move along, nothing to see here – wxWebCore / Wx::WebCore ● Apple's Objective-C experiment (take 2) – cross-platform – “The Future” –
  28. 28. Logger Log::Log4perl ● dynamically configurable – init_and_watch – SIGHUP – insanely configurable ● 5 levels – any depth of 'class' hierarchy – levels are even implicit classes – don't get carried away here –
  29. 29. wrap it not ● $logger = Log::Log4perl­>get_logger('blahblahblah'); $logger­>debug('foo'); just returns a singleton, so: ● use dtRdr::Logger; L - logging in caller() package – L­>debug('foo'); RL - arbitrary logging – trapping ● $SIG{__WARN__}, logging to file – trapping $SIG{__DIE__} (popup) –
  30. 30. Testing ./Build test ● standard tests ● 300 lines of custom test-support code – 3200 5400 lines of regular tests – only 400 600 of that is gui – t/location   1 t             5 t/logger     2 t/_gui        9 t/multitask  3 t/annotation  8 t/plugins    3 t/book       34 t/range      1 t/config      4 t/search     3 t/_sync       5 t/toc        5 t/history     3 t/user       1 t/library     3
  31. 31. Building make a custom Module::Build class ● (not with a HEREdoc) – Custom targets ● ./Build par – ./Build starter_data – ./Build books – ./Build binpush – ./Build bindistribute –
  32. 32. Testing ./Build testall ● 'test', 'testsync', and 'testgui' – ./Build testgui ● is t/_gui/*.gt + Module::Build hack –
  33. 33. Packaging and Deployment Windows and Linux ● PAR – (Wx::ActiveX hack) ● bundle the dlls, etc -- no dependencies for ● user a bit slow to rebuild ● startup speed needs work here ● Mac ● needs an AppBundle –
  34. 34. PerlWrapper (Mac) wxPerl (appbundle) ● required to even get a working GUI – compiled with xcode, resource file, etc – automated tests work fine, but no focus – before click PerlWrapper ● a perl interpreter embedded in a compiled C – app allows quot;open myAppquot; from command-line – ExtUtils::MacMaker ● uh, no I don't run xcode on dos and linux –
  35. 35. No really! Testing ./Build testgui ● outside-in ● X11::GUITest – Win32::GuiTest – inside-out ● EVT_IDLE – Wx::Timer – DISPLAY=localhost:3 ./Build testall –
  36. 36. Manual Testing just hacks: ● Ctrl+Shift+F5 does Module::Refresh – F7 quick window resize (to see console) – production stuff ● Ctrl+L activate library pane – F2/F3 focus switch – command-line options or parameters ● ./run test_packages/foo/book.xml – dual-purpose tests ● perl -Ilib t/_gui/note_editor.gt foo –
  37. 37. Acceptance Tests ala data-driven testing ● scripted manual verifications ● automate actions as much as possible ● still need better GUI test frameworks ●
  38. 38. Questions?
  39. 39. Thanks scratchcomputing.com ● wxperl.sourceforge.net ● dotreader.com ●

×