Opened 7 years ago

Last modified 17 months ago

#14 new enhancement

Add hooks for PyGTK themes

Reported by: openticket Owned by: giovannibajo
Priority: low Milestone: PyInstaller 3.0
Component: Hooks Version:
Severity: normal Keywords:
Cc:

Description

I have tried to build a simple PyGTK program, by using PyInstaller? 1.3, accordingly to the suggestions reported in the tickets about PyGTK (hidden imports and Pango files).

Under Windows XP, I have chosen a "theme" for GTK applications, by using the "Theme Selector" application; theme is a sort of visual "look and feel": when I run the script, the chosen theme applies to the window controls; when I run the executable, a standard theme is used instead.

It is probably due to some GTK library settings: if you have fixed the pango problem, I think you should also be able to fix this. All I can tell you is that custom themes (for example, the ones in the user's computer - since it's the user who chooses the themes) are kept under $GTK_HOME/share/themes, and every theme has got a separate directory.

I do not know if this applies to Linux, too.

Change History (5)

comment:1 Changed 5 years ago by MeV

I successfully added the MS-Windows theme (for better windows integration) to my application by using a code like this:

# First we have to know where gtk is installed, we get this from registry
import _winreg
import msvcrt
try:
    k = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 'Software\\GTK2-Runtime')
except EnvironmentError:
    print 'You must install the Gtk+ 2.2 Runtime Environment to run this program'
    while not msvcrt.kbhit():
        pass
    sys.exit(1)
else:    
    gtkdir = str(_winreg.QueryValueEx(k, 'InstallationDirectory')[0])
    gtkversion = str(_winreg.QueryValueEx(k, 'BinVersion')[0])

#Then we want to go to the directory where the gtkrcfile is located
gtkrc_dir = os.path.join('share', 'themes', 'MS-Windows', 'gtk-2.0')

#Add gtkrc file to exe
extra_datas = [ ('gtkrc', os.path.join(gtkdir, gtkrc_dir, 'gtkrc'), 'DATA') ]

#Add libwimp.dll to exe (needed for the MS-Windows theme)
extra_binaries = [ (os.path.join(engines_dir, 'libwimp.dll'), \
                   os.path.join(gtkdir, engines_dir, 'libwimp.dll'), 'BINARY') ]

#Finally the EXE declaration should looks like this:
exe = EXE( pyz,
          a.scripts,
          a.binaries + extra_binaries,
          a.zipfiles,
          a.datas + extra_datas,
          name = os.path.join('dist', 'myapp.exe'),
          icon = os.path.join('icon', 'myicon.ico'),
          debug = False,
          strip = False,
          upx = True,
          console = False )
Last edited 2 years ago by htgoebel (previous) (diff)

comment:2 Changed 5 years ago by MeV

I forgot to say that I had to use the following code to load my theme:

import os, gtk
try:

    basedir = os.environ['_MEIPASS2']

except KeyError:

    basedir = sys.path[0]

#Use embedded gtkrc
gtkrc = os.path.join(basedir, 'gtkrc')
gtk.rc_set_default_files([gtkrc])
gtk.rc_reparse_all_for_settings(gtk.settings_get_default(), True)

To use it, save the code into a file named 'useGTK.py' and add the path to this file to ANALYSIS

comment:3 Changed 2 years ago by htgoebel

  • Milestone set to PyInstaller 2.1
  • Priority changed from normal to low
  • Summary changed from PyGTK themes do not work for frozen executables to Add hooks for PyGTK themes
  • Type changed from defect to enhancement

Thanks for the receipt! I've added a link to the wiki.

comment:4 Changed 2 years ago by htgoebel

  • Component changed from PyInstaller to Hooks

comment:5 Changed 17 months ago by matysek

  • Milestone changed from PyInstaller 2.1 to PyInstaller 2.2
Note: See TracTickets for help on using tickets.