If wxPython is not installed

classic Classic list List threaded Threaded
30 messages Options
12
Reply | Threaded
Open this post in threaded view
|

If wxPython is not installed

Boštjan Mejak-4
Please look at my code snippet here: https://bpaste.net/show/721e8d0044c4. Notice that my code wouldn't work if the user (that'll use my app on his/her machine) doesn't have wxPython installed, because the exception would raise its own exception.

My goal is to tell the user to install wxPython, but tell the user in a message box, not via the exception message string. Got any idea how should I tackle with my challenge?

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: If wxPython is not installed

Igor Korot
Hi,

On Fri, Jun 12, 2015 at 12:22 PM, Boštjan Mejak
<[hidden email]> wrote:
> Please look at my code snippet here: https://bpaste.net/show/721e8d0044c4.
> Notice that my code wouldn't work if the user (that'll use my app on his/her
> machine) doesn't have wxPython installed, because the exception would raise
> its own exception.
>
> My goal is to tell the user to install wxPython, but tell the user in a
> message box, not via the exception message string. Got any idea how should I
> tackle with my challenge?

If the wxPython is not installed, you are out of luck...
But... can't you just create an executable bundle which will include wxPython?

Thank you.

>
> --
> You received this message because you are subscribed to the Google Groups
> "wxPython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [hidden email].
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: If wxPython is not installed

David Woods-3
In reply to this post by Boštjan Mejak-4

You'd have to use some other GUI toolkit to manage the message box.  You could check to see if QT is installed and use that if it is, I suppose.

David 

On Jun 12, 2015 12:26 PM, "Boštjan Mejak" <[hidden email]> wrote:
Please look at my code snippet here: https://bpaste.net/show/721e8d0044c4. Notice that my code wouldn't work if the user (that'll use my app on his/her machine) doesn't have wxPython installed, because the exception would raise its own exception.

My goal is to tell the user to install wxPython, but tell the user in a message box, not via the exception message string. Got any idea how should I tackle with my challenge?

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: If wxPython is not installed

nepix32
On Friday, June 12, 2015 at 7:35:18 PM UTC+2, David Woods wrote:

You'd have to use some other GUI toolkit to manage the message box.  You could check to see if QT is installed and use that if it is, I suppose.

David 

 
Actually it would be smarter to use a GUI toolkit already included in python: Tkinter 

def show_no_wx():
   
import tkMessageBox
   
   
# we have to create a main window to be able to hide it
   
# see http://stackoverflow.com/questions/17280637/tkinter-messagebox-without-window
   
import Tkinter
    root
= Tkinter.Tk()
    root
.withdraw()

    tkMessageBox
.showerror("No wx", "Error: no wxPython, install it first!")
   
try:
   
import _wx
except ImportError:
   
# wx not installed
    show_no_wx
()
   
raise


This was actually fun!

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: If wxPython is not installed

nepix32
wx was written as _wx so that it could be tested on a machine which has wx, sorry for not fixing that

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: If wxPython is not installed

Tim Roberts
In reply to this post by nepix32
nepix32 wrote:
>  
> Actually it would be smarter to use a GUI toolkit already included in
> python: Tkinter

This is a good answer.  Tkinter is built-in and will always be available.

--
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: If wxPython is not installed

Mike Driscoll


On Friday, June 12, 2015 at 4:18:33 PM UTC-5, Tim Roberts wrote:
nepix32 wrote:
>  
> Actually it would be smarter to use a GUI toolkit already included in
> python: Tkinter

This is a good answer.  Tkinter is built-in and will always be available.

--
Tim Roberts, <a href="javascript:" target="_blank" gdf-obfuscated-mailto="r9BzBxQGWeIJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">ti...@...
Providenza & Boekelheide, Inc.

Except on Mac...I don't know why. I had to specifically install ActiveState's TCL library to use Tkinter on Mac 10.6+ (https://www.python.org/download/mac/tcltk/)...

Mike

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: If wxPython is not installed

Chris Barker - NOAA Federal
Well, it's there but buggy. 

I think this is getting addressed in future, if not the latest, releases.

Cnut there are no other platform independent options.

-Chris

On Jun 12, 2015, at 2:25 PM, Mike Driscoll <[hidden email]> wrote:



On Friday, June 12, 2015 at 4:18:33 PM UTC-5, Tim Roberts wrote:
nepix32 wrote:
>  
> Actually it would be smarter to use a GUI toolkit already included in
> python: Tkinter

This is a good answer.  Tkinter is built-in and will always be available.

--
Tim Roberts, <a href="javascript:" target="_blank" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">ti...@...
Providenza & Boekelheide, Inc.

Except on Mac...I don't know why. I had to specifically install ActiveState's TCL library to use Tkinter on Mac 10.6+ (https://www.python.org/download/mac/tcltk/)...

Mike

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: If wxPython is not installed

Boštjan Mejak-4
I think I'll stick with the current ImportError message to inform the user to install wxPython. Since you mentioned that there's no built-in Tkinker on a Python for Mac, I won''t achieve the crossplatform solution I'm looking for.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: If wxPython is not installed

Boštjan Mejak-4
Uhm, Chris, what did you mean to say with the word "cnut"? Is it a typo?

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: If wxPython is not installed

Dev Player

Or a more cross-platform way; open a browser with a local HTML file which is distributed by you.

I googled "popup a message box".

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: If wxPython is not installed

Boštjan Mejak-4
Dev Player, thanks for the link. I exctracted some important code from it:
mshta "javascript:var sh=new ActiveXObject('WScript.Shell'); sh.Popup('wxPython GUI toolkit is missing. Please install it.', 0, 'Application Error', 64); close()"

I now have this line of code in a file wxmissing,bat. I am, however, experiencing a problem that double clicking on the .bat file displays a popup message box as I wanted, but the Command Prompt window is also displayed alongside the message box. How can I suppress the Command Prompt window?

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: If wxPython is not installed

Boštjan Mejak-4
Found something even better than the batch script solution. ctypes to the rescue!

import ctypes
ctypes.windll.user32.MessageBoxW(0, "wxPython is missing.", "App Error", 0)

Works like a charm! ;)

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: If wxPython is not installed

GadgetSteve
In reply to this post by Boštjan Mejak-4
Personally I would like to write the error message complete with a download link to a file then use webbrowser.open this would be cross platform and allow the user to just click the link.  Win32 only works on windows.



Sent from Samsung Mobile on O2


-------- Original message --------
From: Boštjan Mejak <[hidden email]>
Date: 14/06/2015 10:49 (GMT+00:00)
To: wxPython Help <[hidden email]>
Subject: Re: [wxPython-users] If wxPython is not installed

Found something even better than the batch script solution. ctypes to the rescue!

import ctypes
ctypes.windll.user32.MessageBoxW(0, "wxPython is missing.", "App Error", 0)

Works like a charm! ;)

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: If wxPython is not installed

Boštjan Mejak-4
Okay, I found a solution. My application is meant for Windows anyway. So here's the code that works 100% on Windows.

import ctypes
import sys


def wxMissing(parentWindow=None,
              message="wxPython GUI toolkit is missing. Please install it.",
              caption="Application Error",
              style=0):
    """
    Show a warning in a message box that wxPython is missing and inform the user
    to install it.
    """

    if sys.version_info.major == 2:
        ctypes.windll.user32.MessageBoxA(parentWindow,
                                         message,
                                         caption,
                                         style)
    else:
        ctypes.windll.user32.MessageBoxW(parentWindow,
                                         message,
                                         caption,
                                         style)

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

wxmissing.py (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: If wxPython is not installed

Boštjan Mejak-4
Adjust the message and caption strings to your specific needs and use the module in your app with  import wxmissing

Then in your module just call  wxmissing.wxMissing()  (without any parameters) and you're golden.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: If wxPython is not installed

Karsten Hilbert
In reply to this post by Boštjan Mejak-4
On Sun, Jun 14, 2015 at 11:49:30AM +0200, Boštjan Mejak wrote:

> Found something even better than the batch script solution. ctypes to the
> rescue!
>
> import ctypes
> ctypes.windll.user32.MessageBoxW(0, "wxPython is missing.", "App Error", 0)
>
> Works like a charm! ;)

And extremely cross-platform, indeed.

Karsten
--
GPG key ID E4071346 @ eu.pool.sks-keyservers.net
E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: If wxPython is not installed

Boštjan Mejak-4
I wasn't aiming for platform independency here. On Windows, you'd just use ctypes for this purpose, but on Linux I can't say what is there to use. Got a clue?

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: If wxPython is not installed

Karsten Hilbert
On Sun, Jun 14, 2015 at 02:07:16PM +0200, Boštjan Mejak wrote:

> I wasn't aiming for platform independency here.

Then I must have misunderstood. Your first postings to me
seemed to imply as much.

> On Windows, you'd just use ctypes for this purpose, but on
> Linux I can't say what is there to use. Got a clue?

Not beyond what was already suggested:

- use tkinter
- use webbrowser.open()

Karsten
--
GPG key ID E4071346 @ eu.pool.sks-keyservers.net
E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: If wxPython is not installed

Chris Barker - NOAA Federal
In reply to this post by Boštjan Mejak-4
On Sat, Jun 13, 2015 at 12:19 AM, Boštjan Mejak <[hidden email]> wrote:
Uhm, Chris, what did you mean to say with the word "cnut"? Is it a typo?

typo -- was supposed to be 'but' -- not sure how that happened!

And it turns out I was wrong the browser option is cross platform and would work well -- even better if the app has a web page to refer to!

note that it is probably possible to use ctypes to do platform-specific things for other platforms. Though On Linux at least, a regular old console message would probably be fine.

On OS-X, I note that Apple's built-in Python has a (likely old) version of wx out of the box.

-Chris

 

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.



--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

[hidden email]

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
12