Thanks so much for taking the time.
The real reason for this rather silly test was to fill xpm
bitmaps with loadfile method. this was a first test to look if there is
something coming out of the pipe. do i have to write a handler for that,
because that would  give Kephra a total independence of config files,
if it could have also inline icons.

thanks a lot.
herbert


> Hi Herbert,
> 
> On 26/06/2013 18:11, herbert breunung wrote:
>> greetings comrads
>> I  have seen the XRC custom example in Wx::Demo and did
> ....
>>          Wx::MemoryFSHandler::AddTextFile( 'file.xpm', <<'EOB' );
> ....
>>          my $ed = Wx::TextCtrl->new($frame, -1,'');
>>          $ed->LoadFile('memory:file.xpm');
>>
>> but i get just error also loading into the bitmap doesn't work.
>> Any Suggestions?
>>
>> Thanks a lot
>> Herbert aka lichtkind
>>
> 
> I had to look at the wxWidgets source to figure out what is happening here.
> 
> It turns out that you cannot use the name of a memory file anywhere that you
> can use a filename. Only some specific methods accept the name of a 'memory'
> file. Internally, only some 'Load' methods use wxFileSystem and streams. For
> these methods, passing the name of a 'memory' file will work. In addition to
> the XRC method in Wx::Demo, Wx::HtmlWindow->LoadPage() will accept a 'memory'
> file.
> 
> Other methods, such as Wx::TextCtrl->LoadFile, are implemented as thin
> wrappers around the operating system file open / read functions. So in these
> cases 'memory:file.xpm' is not going to work.
> 
> I don't see anywhere in the documentation that you can tell which methods use
> filestreams though :(
> 
> For information, I have attached an example of how you can get a file handle
> to a memory file and read the content. It all looks pointless though and there
> seems multiple better ways to structure this in Perl.
> 
> Hope it helps
> 
> Mark
> 
> #---------------------------------------------------------------------
> #/usr/bin/perl
> 
> package MyFrame;
> use strict;
> use warnings;
> use Wx qw( :textctrl :sizer :panel :window);
> use Wx::FS;
> use base qw( Wx::Frame );
> 
> sub new {
>     my $class = shift;
>     my $self = $class->SUPER::new( @_ );
>     my $mainpanel = Wx::Panel->new($self, -1, [-1,-1], [-1,-1],
> wxTAB_TRAVERSAL|wxBORDER_NONE);
>     my $text = Wx::TextCtrl->new($mainpanel, -1, "", [-1,-1],[-1,-1]);
> 
>     # Fairly pointless use of Virtual File System directly
> 
>     # Create Virtual File System
>     {
>         my $content = 'The quick brown fox jumped over the lazy dog';
>         Wx::FileSystem::AddHandler( Wx::MemoryFSHandler->new );
>         Wx::MemoryFSHandler::AddTextFile( 'sample.txt', $content );
>     }
> 
>     # Get file content from virtual filesystem
>     {
>         my $fs = Wx::FileSystem->new;
>         my $mfile = $fs->OpenFile('memory:sample.txt');
>         my $fh = $mfile->GetStream;
>         my $textcontent = '';
>         while(<$fh>) {
>             $textcontent .= $_;
>         }
>         $text->ChangeValue($textcontent);
>     }
> 
>     # Clean up VS
>     {
>         Wx::MemoryFSHandler::RemoveFile( 'sample.txt' );
>     }
> 
>     my $panelsz = Wx::BoxSizer->new(wxVERTICAL);
>     my $framesz = Wx::BoxSizer->new(wxVERTICAL);
> 
>     $panelsz->Add($text, 1, wxEXPAND|wxALL, 0);
>     $mainpanel->SetSizer($panelsz);
>     $framesz->Add($mainpanel, 1, wxEXPAND|wxALL, 0);
>     $self->SetSizer($framesz);
> 
>     $self->Center;
>     return $self;
> }
> 
> package MyApp;
> use strict;
> use warnings;
> use Wx;
> use Wx::FS;
> use base qw( Wx::App );
> 
> sub OnInit {
>     my $self = shift;
>     my $win = MyFrame->new(undef, -1, 'Wx::FS Test');
>     $self->SetTopWindow($win);
>     $win->Show(1);
>     return 1;
> }
> 
> package main;
> use strict;
> use warnings;
> 
> my $app = MyApp->new;
> $app->MainLoop;
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 

Reply via email to