Python Pmw and cx_Freeze?

前端 未结 1 1468
梦毁少年i
梦毁少年i 2021-01-15 16:22

I am unable to make an executable from my python program which uses Pmw (Python mega widgets). I use cx_Freeze (through gui backend \"Gui2Exe\"). Searching Pmw site I\'ve fo

1条回答
  •  忘掉有多难
    2021-01-15 16:41

    Unfortunately, the original file has some problems with tabs and spaces (just look at the while indentation in expandlinks).

    I fixed those indentation problems, changed regsub.gsub with re.sub and eliminated the string import, using the string type methods.

    After that the script worked perfect:

       Pmw.py has been created.
       Before running freeze, also copy the following file(s):
       C:\Users\joaquin\Desktop\Pmw.1.3.2\src\Pmw\Pmw_1_3\lib\PmwBlt.py
       C:\Users\joaquin\Desktop\Pmw.1.3.2\src\Pmw\Pmw_1_3\lib\PmwColor.py
    

    Here you have the corrected script:

    #!/usr/bin/env python
    
    # Helper script when freezing Pmw applications.  It concatenates all
    # Pmw megawidget files into a single file, 'Pmw.py', in the current
    # directory.  The script must be called with one argument, being the
    # path to the 'lib' directory of the required version of Pmw.
    # To freeze a Pmw application, you will also need to copy the
    # following files to the application directory before freezing:
    #
    #    PmwBlt.py PmwColor.py
    
    import os
    import re
    import sys
    
    # The order of these files is significant.  Files which reference
    # other files must appear later.  Files may be deleted if they are not
    # used.
    files = [
        'Dialog', 'TimeFuncs', 'Balloon', 'ButtonBox', 'EntryField',
        'Group', 'LabeledWidget', 'MainMenuBar', 'MenuBar', 'MessageBar',
        'MessageDialog', 'NoteBook', 'OptionMenu', 'PanedWidget', 'PromptDialog',
        'RadioSelect', 'ScrolledCanvas', 'ScrolledField', 'ScrolledFrame',
        'ScrolledListBox', 'ScrolledText', 'HistoryText', 'SelectionDialog',
        'TextDialog', 'TimeCounter', 'AboutDialog', 'ComboBox', 'ComboBoxDialog',
        'Counter', 'CounterDialog',
    ]
    
    # Set this to 0 if you do not use any of the Pmw.Color functions:
    needColor = 1
    
    # Set this to 0 if you do not use any of the Pmw.Blt functions:
    needBlt = 1
    
    def expandLinks(path):
        if not os.path.isabs(path):
            path = os.path.join(os.getcwd(), path)
        while 1:
            if not os.path.islink(path):
                break
            dir = os.path.dirname(path)
            path = os.path.join(dir, os.readlink(path))
    
        return path
    
    def mungeFile(file):
        # Read the file and modify it so that it can be bundled with the
        # other Pmw files.
        file = 'Pmw' + file + '.py'
        text = open(os.path.join(srcdir, file)).read()
        text = re.sub('import Pmw\>', '', text)
        text = re.sub('INITOPT = Pmw.INITOPT', '', text)
        text = re.sub('\

    0 讨论(0)
提交回复
热议问题