Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a 'setIcon' method to allow the Window's icon to be changed #10

Closed
wants to merge 2 commits into from

Conversation

CViniciusSDias
Copy link

Currently the only way to set the icon is to call directly the protected method setWm. If we don't want to follow the approach of extending MainWindow we should still be able to set its icon.

This PR addresses that concern, making public a setIcon method that receives the path for the icon bitmap file. As it was added to the docblock, / should be used as directory separator even on Windows. When trying to use \ I received the following error:

image

PHP Fatal error:  Uncaught Tkui\TclTk\Exceptions\EvalException: Eval: bitmap "C:WindowsSystem32OneDrive.ico" not defined in C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\Tcl.php:63
Stack trace:
#0 C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\Interp.php(54): Tkui\TclTk\Tcl->eval(Object(Tkui\TclTk\Interp), 'wm iconbitmap ....')
#1 C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\TkApplication.php(86): Tkui\TclTk\Interp->eval('wm iconbitmap ....')
#2 C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\TkWindowManager.php(209): Tkui\TclTk\TkApplication->tclEval('wm', 'iconbitmap', '.', 'C:\\Windows\\Syst...')
#3 C:\Users\carlo\Documents\code\untitled\index.php(38): Tkui\TclTk\TkWindowManager->setWm('iconbitmap', 'C:\\Windows\\Syst...')
#4 {main}
  thrown in C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\Tcl.php on line 63

Fatal error: Uncaught Tkui\TclTk\Exceptions\EvalException: Eval: bitmap "C:WindowsSystem32OneDrive.ico" not defined in C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\Tcl.php on line 63

Tkui\TclTk\Exceptions\EvalException: Eval: bitmap "C:WindowsSystem32OneDrive.ico" not defined in C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\Tcl.php on line 63

Call Stack:
    0.0002     412616   1. {main}() C:\Users\carlo\Documents\code\untitled\index.php:0
    0.1035     887664   2. Tkui\TclTk\TkWindowManager->setWm($command = 'iconbitmap', ...$value = variadic('C:\\Windows\\System32\\OneDrive.ico')) C:\Users\carlo\Documents\code\untitled\index.php:38
    0.1035     888040   3. Tkui\TclTk\TkApplication->tclEval(...$args = variadic('wm', 'iconbitmap', '.', 'C:\\Windows\\System32\\OneDrive.ico')) C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\TkWindowManager.php:209
    0.1035     888496   4. Tkui\TclTk\Interp->eval($script = 'wm iconbitmap . C:\\Windows\\System32\\OneDrive.ico') C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\TkApplication.php:86
    0.1035     888496   5. Tkui\TclTk\Tcl->eval($interp = class Tkui\TclTk\Interp { private Tkui\TclTk\Tcl $tcl = class Tkui\TclTk\Tcl { private FFI $ffi = class FFI { ... } }; private FFI\CData $interp = class FFI\CData { public $0 = class FFI\CData { ... } }; private ?Psr\Log\LoggerInterface $logger = NULL }, $script = 'wm iconbitmap . C:\\Windows\\System32\\OneDrive.ico') C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\Interp.php:54

@skoro
Copy link
Owner

skoro commented Oct 28, 2022

Thanks for your contribution! For me it's better to use iconphoto since it allows attaching png images of various sizes.

@CViniciusSDias
Copy link
Author

I tried that and got the following error:

PHP Fatal error:  Uncaught Tkui\TclTk\Exceptions\EvalException: Eval: can't use "C:\Users\carlo\OneDrive\Imagens\icon.png" as iconphoto: not a photo image in C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\Tcl.php:63
Stack trace:
#0 C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\Interp.php(54): Tkui\TclTk\Tcl->eval(Object(Tkui\TclTk\Interp), 'wm iconphoto . ...')
#1 C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\TkApplication.php(86): Tkui\TclTk\Interp->eval('wm iconphoto . ...')
#2 C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\TkWindowManager.php(220): Tkui\TclTk\TkApplication->tclEval('wm', 'iconphoto', '.', Array)
#3 C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\TkWindowManager.php(49): Tkui\TclTk\TkWindowManager->setWm('iconphoto', Array)
#4 C:\Users\carlo\Documents\code\untitled\index.php(59): Tkui\TclTk\TkWindowManager->setIcon('C:\\Users\\carlo\\...')
#5 {main}
  thrown in C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\Tcl.php on line 63

Fatal error: Uncaught Tkui\TclTk\Exceptions\EvalException: Eval: can't use "C:\Users\carlo\OneDrive\Imagens\icon.png" as iconphoto: not a photo image in C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\Tcl.php on line 63

Tkui\TclTk\Exceptions\EvalException: Eval: can't use "C:\Users\carlo\OneDrive\Imagens\icon.png" as iconphoto: not a photo image in C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\Tcl.php on line 63

Call Stack:
    0.0002     412688   1. {main}() C:\Users\carlo\Documents\code\untitled\index.php:0
    0.1324    1115128   2. Tkui\TclTk\TkWindowManager->setIcon($iconBitmapFilePath = 'C:\\Users\\carlo\\OneDrive\\Imagens\\icon.png', $isDefaultForOtherWindows = ???) C:\Users\carlo\Documents\code\untitled\index.php:59
    0.1324    1115504   3. Tkui\TclTk\TkWindowManager->setWm($command = 'iconphoto', ...$value = variadic([0 => 'C:\\Users\\carlo\\OneDrive\\Imagens\\icon.png'])) C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\TkWindowManager.php:49
    0.1324    1115880   4. Tkui\TclTk\TkApplication->tclEval(...$args = variadic('wm', 'iconphoto', '.', [0 => 'C:\\Users\\carlo\\OneDrive\\Imagens\\icon.png'])) C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\TkWindowManager.php:220
    0.1324    1116352   5. Tkui\TclTk\Interp->eval($script = 'wm iconphoto . {C:\\Users\\carlo\\OneDrive\\Imagens\\icon.png}') C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\TkApplication.php:86
    0.1324    1116352   6. Tkui\TclTk\Tcl->eval($interp = class Tkui\TclTk\Interp { private Tkui\TclTk\Tcl $tcl = class Tkui\TclTk\Tcl { private FFI $ffi = class FFI { ... } }; private FFI\CData $interp = class FFI\CData { public $0
 = class FFI\CData { ... } }; private ?Psr\Log\LoggerInterface $logger = NULL }, $script = 'wm iconphoto . {C:\\Users\\carlo\\OneDrive\\Imagens\\icon.png}') C:\Users\carlo\Documents\code\untitled\vendor\skoro\tkui\src\TclTk\Interp.php:54

This was my attempted implementation:

    public function setIcon(string $iconFilePath, $isDefaultForOtherWindows = false): self
    {
        $arguments = [];
        if ($isDefaultForOtherWindows) {
            $arguments[] = '-deafult';
        }
        $arguments[] = $iconFilePath;

        return $this->setWm('iconphoto', $arguments);
    }

Since I am not familiar with Tcl/Tk at all, I went for the easier approach, which was to use iconbitmap. I will try to dig deeper into this issue today after my work hours. :-)

PS.: Thank you for your work on this component. ⭐

@skoro
Copy link
Owner

skoro commented Oct 28, 2022

Take a look at #13 and run one of the demos

@CViniciusSDias
Copy link
Author

Now I get it. It's not just a matter of passing the path as a string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants