Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^4: pp macOS external file

by IB2017 (Pilgrim)
on Apr 20, 2018 at 14:22 UTC ( [id://1213253]=note: print w/replies, xml ) Need Help??


in reply to Re^3: pp macOS external file
in thread pp macOS external file

I have solved it in this way, even if I am not very happy to use the $0 variable

use strict; use warnings; use FindBin; $0 = "stealth"; use Tk; use Tk::PNG; my $png = "$FindBin::Bin/myicon.png"; my $mw = Tk::MainWindow->new(); my $icon = $mw->Photo(-file => $png); my $btn = $mw->Button( -image => $icon, ); $btn->pack(); $mw->MainLoop();

Replies are listed 'Best First'.
Re^5: pp macOS external file
by marto (Cardinal) on Apr 20, 2018 at 14:26 UTC

    Are you sure this is the solution you are looking for? If I move this exe into a different location from all the source (the perl and png file) I get:

    marto@Shemp:~/perlmonks$ ./test2 Cannot open '/home/marto/perlmonks/myicon.png' in mode 'r' at Tk/Image +.pm line 21

      I understand what you mean. However, the problem I am facing has a more general character: in the version created with pp I have the problem to "link" any sort of file to my executable (for example a SQLite database the app creates the first time it is run). This fails because of the issue with the path. I actually would like the executable to behave like my Terminal script in terms of paths. Just a side note: on Windows I do not have this issue.

        Maybe you should have a configuration file in user's home dir pointing to all your resources, read-only, like icons but also re-writable like the SQLlite file! This solves also the problem of when you want to preserve the contents of the database for the next run. An installer of some sort (can just be a shell script) will also allow you taking care of different users.

        Alternatively, create a shell script which will call your perl pp file from within a certain folder which you will know that program resources (ro/rw) are located. You achieve this via a "cd" (change dir) first. Call that script instead of the pp executable from anywhere you like, it will first cd to proper dir. Firefox for example does this: 1) install resources to user dir, 2) install firefox binary and libs in system bindir, 3) create a shell script (mine is /usr/bin/firefox) which finds resources, checks things and then it calls the real firefox binary. However, that "cd" I do not like.

        p.s. for joining filenames and paths in different OS, I use the portable File::Spec->catfile.

        p.s. 2 in windows I often found that two bugs combined together could result in correct program flow!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1213253]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-07-16 10:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.