Nasser Al-Hilal
Nasser Al-Hilal

Reputation: 56

pyGTK app looks different frozen using cx_freeze

My application looks different after I freeze it using cx_freeze (I'm using Gui2Exe to create and run the cx_freeze script) and when I run it using the python interpreter.

[As I'm not allowed to post images, here are the links to the UI, edit?]

Script run:

Application as run from the command line

Frozen run:

Application as run after being frozen by cx_freeze

I have tried both including and not including the manifest file in the cx_freeze script, yet I'm unsure what could be causing the application UI to change so dramatically.

Here is the cx_freeze script:

# ======================================================== #
# File automagically generated by GUI2Exe version 0.5.3
# Copyright: (c) 2007-2012 Andrea Gavana
# ======================================================== #

# Let's start with some default (for me) imports...

from cx_Freeze import setup, Executable



# Process the includes, excludes and packages first

includes = ['ast', 'gobject', 'gtk']
excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger',
            'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl',
            'Tkconstants', 'Tkinter']
packages = ['BeautifulSoup', 'mechanize', 'pygtk']
path = []

# This is a place where the user custom code may go. You can do almost
# whatever you want, even modify the data_files, includes and friends
# here as long as they have the same variable name that the setup call
# below is expecting.

# No custom code added

# The setup for cx_Freeze is different from py2exe. Here I am going to
# use the Python class Executable from cx_Freeze


GUI2Exe_Target_1 = Executable(
    # what to build
    script = "moodle-downloader.py",
    initScript = None,
    base = 'Win32GUI',
    targetDir = r"md",
    targetName = "moodle-downloader.exe",
    compress = True,
    copyDependentFiles = True,
    appendScriptToExe = True,
    appendScriptToLibrary = True,
    icon = r"C:\Users\Nasser.Al-Hilal\Dropbox\CodeN\Projects\Applications\Personal\MoodleDownloader\res\md.ico"
    )


# That's serious now: we have all (or almost all) the options cx_Freeze
# supports. I put them all even if some of them are usually defaulted
# and not used. Some of them I didn't even know about.

setup(

    version = "0.3",
    description = "An app to assist in downloading assignment submissions from Moodle LMS.",
    author = "Nasser Al-Hilal",
    name = "Moodle Downloader",

    options = {"build_exe": {"includes": includes,
                             "excludes": excludes,
                             "packages": packages,
                             "path": path
                             }
               },

    executables = [GUI2Exe_Target_1]
    )

# This is a place where any post-compile code may go.
# You can add as much code as you want, which can be used, for example,
# to clean up your folders or to do some particular post-compilation
# actions.

# No post-compilation code added


# And we are done. That's a setup script :-D

I would prefer if I can get the application to look the same as when run from the interpreter.

Upvotes: 2

Views: 670

Answers (3)

hdanielv12
hdanielv12

Reputation: 1

This is just a translation of Blasito's answer:

"For this to work correctly, first download and install GTK-runtime on your computer. Then navigate to GTK-runtime installation folder (in Program Files) and copy over the lib and share folders over to the generated build folder. Finally, copy the contents of the bin folder (in the installation directory) into the build folder."

I can verify this works.

Upvotes: 0

Blasito
Blasito

Reputation: 221

For you to work you have to download gtkruntime, install it on your system, then copy the lib folder and share your generated build folder, then copies the contents of the bin folder gtkruntime your build folder, and then you work.

Upvotes: 2

ljgww
ljgww

Reputation: 3538

My installation:

  • windows 7
  • Python 2.7.9
  • GTK2 (python -m pip install pygtk)
    • pycairo (1.8.10) pygobject (2.28.3) pygoocanvas (0.14.2) pygtk (2.24.0) pygtksourceview (2.10.1)
  • cx-Freeze (python -m pip install cx-Freeze)
    • cx-Freeze (4.3.4)

cx-freeze compile command:

 \Py279\Scripts\cxfreeze  MyGUIapp.py --target-dir somewheredir --base-name=Win32GUI

(in essence, all done without any setup command files, although some can be created :) )

once cx-freeze compiles to exe and copy dll it believes that are needed I get motif/x11 look/feel however, when I add to somewheredir all .dll files from:

\Py279\Lib\site-packages\gtk-2.0\runtime\lib\gtk-2.0\2.10.0\engines\

to:

somewheredir\lib\gtk-2.0\2.10.0\engines\

I get windows look and feel.

Files found there in my case are:

  • libpixmap.dll
  • libsvg.dll
  • libwimp.dll

that's all.

Plus:

some further design customization influence can be achieved by creating .gtkrc-2.0 in the user's home folder c:\Users\myuser. Namely one can influence default font face and size used, window background color and such. For example, following code (hints from elsewhere)

    style "win32-font" {
      # make default font larger
      font_name = "Sans 12"
      # set the background to a light grey
      bg[NORMAL] = "#f6f6f6"
    }
    class "*" style "win32-font"

placed in c:\Users\myuser\.gtkrc-2.0 would change 'default' font size and change top window background for pygtk applications run by user (meaning each user can set its own preferences there).

Upvotes: 0

Related Questions