Friday, August 31, 2012

Launching Documents in Wx

Whilst working on the port of C++ example code for Wx::PdfDocument I came across a simple cross-platform way to launch documents from Wx applications.

The necessary functions and methods have been supported in Wx for some time but I have not come across usage in wxPerl.


my $docpath = '/path/to/somefile.pdf';
my $docext = 'pdf';

  my $manager = Wx::MimeTypesManager->new();
  if( my $filetype = $manager ->GetFileTypeFromExtension($docext) ) {
    my $cmd = $filetype->GetOpenCommand($docpath);
  } else {
    Wx::LogError(qq(Could not find application for file type $docext));


It's simple, it works and it's one of my favourite snippets.

No comments:

Post a Comment