Scribus Forums

Development => Code => Topic started by: PK on February 27, 2023, 01:11:30 PM

Title: Direct script failed but successed in console!
Post by: PK on February 27, 2023, 01:11:30 PM
Hi,

I have a strange behavior for my script

https://github.com/patricekaratchentzeff/Scribus/tree/main/typo

named typoImprimerieNationale.py

If you test it (there is also a test Scribus doc in my GitHub repository), it is OK in the console (load and run in console), but when you try directly through the script menu, I got

Traceback (most recent call last):
  File "<string>", line 11, in <module>
  File "<string>", line 768, in <module>
  File "<string>", line 754, in main_wrapper
  File "<string>", line 668, in main
  File "<string>", line 465, in welcome_banner
NameError: name 'ICON_INFORMATION' is not defined

The script seems not to recognize the Scribus environment, at least, this is the way I interpret the error message, because this is the first step in the script where you call a pop-up message (so a Qt widget...).

It is quiet difficult to debug without console :)

Is there a way to debug this problem? Or, better, do you a track for helping me?

Thanks,

PK
Title: Re: Direct script failed but successed in console!
Post by: a.l.e on February 27, 2023, 05:02:38 PM
see https://github.com/patricekaratchentzeff/Scribus/blob/main/typo/typoImprimerieNationale.py#L585 for the way to do it : - )

... you have the same error multiple times in your script...
Title: Re: Direct script failed but successed in console!
Post by: PK on February 27, 2023, 06:02:19 PM
Thanks, I read a lot before to understand :)

All is good now  ;D

I just want to understand why my script run before only in console. when you are in console, the dialog environment, like icon name, are already load?

Thanks in any cases !
Title: Re: Direct script failed but successed in console!
Post by: a.l.e on February 27, 2023, 08:47:17 PM
it's because in the console the functions and constants from the scribus namespace are loaded into the global namespace.

you could do that in your script, too... but, personally, i would advise you not to do it and put scribus. in front of each call of the scribus API: a bit more verbose, but IMO much easier to understand what is going on.

btw, since you're on the line: it would be a good idea to remove the

#!/usr/bin/env python3

at the beginning of your script.

this is only useful if you start the script from a terminal, but that is not possible since -- as you correctly let your script say a few lines later -- the script must be started from inside scribus.
Title: Re: Direct script failed but successed in console!
Post by: PK on February 27, 2023, 09:17:57 PM
OK, thanks for all.

I removed the first line too.