emdding python gui in c code - OS independent

Discussion in 'Python' started by tinauser, Oct 11, 2010.

  1. tinauser

    tinauser Guest

    hi there,
    i need to embed python GUI in a c++ code. I've seen that,while on
    windows running GUI is no problem, in mac i need to use pythonw
    instead python.
    the question is,how should i tell the program that if the OS is mac,
    it should pythonw, otherwise python is fine?
    tinauser, Oct 11, 2010
    #1
    1. Advertising

  2. tinauser

    Chris Rebert Guest

    On Mon, Oct 11, 2010 at 6:16 AM, tinauser <> wrote:
    > hi there,
    > i need to embed python GUI in a c++ code. I've seen that,while on
    > windows running GUI is no problem, in mac i need to use pythonw
    > instead python.
    > the question is,how should i tell the program that if the OS is mac,
    > it should pythonw, otherwise python is fine?


    I think you have it backwards. MS Windows is where one typically needs
    to use pythonw to suppress a console window from opening when Python
    is run. *nixes (including Mac OS X) have no such problem and (I'm
    pretty sure) only have a pythonw executable for compatibility
    purposes. Just specify pythonw regardless of OS and you should be
    fine.

    Cheers,
    Chris
    --
    http://blog.rebertia.com
    Chris Rebert, Oct 11, 2010
    #2
    1. Advertising

  3. tinauser

    tinauser Guest

    On Oct 11, 6:49 pm, Chris Rebert <> wrote:
    > On Mon, Oct 11, 2010 at 6:16 AM, tinauser <> wrote:
    > > hi there,
    > > i need to embed python GUI in a c++ code. I've seen that,while on
    > > windows running GUI is no problem, in mac i need to use pythonw
    > > instead python.
    > > the question is,how should i tell the program that if the OS is mac,
    > > it should pythonw, otherwise python is fine?

    >
    > I think you have it backwards. MS Windows is where one typically needs
    > to use pythonw to suppress a console window from opening when Python
    > is run. *nixes (including Mac OS X) have no such problem and (I'm
    > pretty sure) only have a pythonw executable for compatibility
    > purposes. Just specify pythonw regardless of OS and you should be
    > fine.
    >
    > Cheers,
    > Chris
    > --http://blog.rebertia.com


    thanks:
    how do i specify pythonw programmatically?
    i tried Py_SetProgramName("pythonw");

    it doesn't raise errors, but does not solve the problem on mac, i.e. i
    get the error:

    This program needs access to the screen.
    Please run with 'pythonw', not 'python', and only when you are logged
    in on the main display of your Mac.
    tinauser, Oct 11, 2010
    #3
  4. tinauser <> writes:

    > On Oct 11, 6:49 pm, Chris Rebert <> wrote:
    >> On Mon, Oct 11, 2010 at 6:16 AM, tinauser <> wrote:
    >> > hi there,
    >> > i need to embed python GUI in a c++ code. I've seen that,while on
    >> > windows running GUI is no problem, in mac i need to use pythonw
    >> > instead python.
    >> > the question is,how should i tell the program that if the OS is mac,
    >> > it should pythonw, otherwise python is fine?

    >>
    >> I think you have it backwards. MS Windows is where one typically needs
    >> to use pythonw to suppress a console window from opening when Python
    >> is run. *nixes (including Mac OS X) have no such problem and (I'm
    >> pretty sure) only have a pythonw executable for compatibility
    >> purposes. Just specify pythonw regardless of OS and you should be
    >> fine.



    This is not entirely true, there is a difference on the mac, see below.
    >>
    >> Cheers,
    >> Chris
    >> --http://blog.rebertia.com

    >
    > thanks:
    > how do i specify pythonw programmatically?
    > i tried Py_SetProgramName("pythonw");
    >
    > it doesn't raise errors, but does not solve the problem on mac, i.e. i
    > get the error:
    >
    > This program needs access to the screen.
    > Please run with 'pythonw', not 'python', and only when you are logged
    > in on the main display of your Mac.


    I'm not sure that's your problem. It is not about the *name* of the
    program. It is about Python being a Framework build. Which the ones that
    come with OSX are, and if you link against them that's enough.

    However, you are writing your *own* binary program, and I guess that's
    the problem. I don't know without further research why there is a
    difference between commandline and GUI-programs in OSX (I guess it has
    to do with the event loop or something), but I think your umbrella
    program is the real culprit here. If it's not a proper GUI program
    (whatever that exactly means), delegating rendering of a GUI to Python
    will trigger that code that spits out your above error message.


    Diez
    Diez B. Roggisch, Oct 11, 2010
    #4
  5. Diez B. Roggisch wrote:
    > I don't know without further research why there is a
    > difference between commandline and GUI-programs in OSX (I guess it has
    > to do with the event loop or something)


    The MacOSX display server is rather picky about which processes
    it will allow to connect to it. One of the necessary conditions
    seems to be that the executable is inside an application bundle.

    If the program you're embedding Python in is being compiled as
    an application (something you can double-click to launch from
    the Finder) then it will probably be able to have a GUI. Otherwise,
    it may not.

    --
    Greg
    Gregory Ewing, Oct 13, 2010
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Scott Brady Drummonds

    Writing Compile-time Independent Code

    Scott Brady Drummonds, Jul 23, 2003, in forum: C++
    Replies:
    1
    Views:
    393
    Nick Keighley
    Jul 24, 2003
  2. Axel Kowald
    Replies:
    4
    Views:
    896
    Tak-Shing Chan
    Dec 7, 2003
  3. walter

    how to write os version independent code?

    walter, Nov 7, 2003, in forum: C Programming
    Replies:
    8
    Views:
    371
    Malcolm
    Nov 9, 2003
  4. Axel Kowald

    source code for independent component analysis ??

    Axel Kowald, Dec 6, 2003, in forum: C Programming
    Replies:
    4
    Views:
    579
    Tak-Shing Chan
    Dec 7, 2003
  5. saneman

    Platform independent code?

    saneman, Jun 14, 2008, in forum: Python
    Replies:
    2
    Views:
    496
    bukzor
    Jun 14, 2008
Loading...

Share This Page