Skip to content

Commit

Permalink
Top-level script is not optimized under py2exe.
Browse files Browse the repository at this point in the history
Fixes #12
  • Loading branch information
Marginal committed Jul 2, 2015
1 parent 72becef commit c36ce2a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
28 changes: 11 additions & 17 deletions EDMarketConnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, master):
elif platform == 'linux2':
from PIL import Image, ImageTk
icon = ImageTk.PhotoImage(Image.open("EDMarketConnector.png"))
root.tk.call('wm', 'iconphoto', root, '-default', icon)
self.w.tk.call('wm', 'iconphoto', self.w, '-default', icon)
style = ttk.Style()
style.theme_use('clam')

Expand Down Expand Up @@ -78,18 +78,18 @@ def __init__(self, master):
from Foundation import NSBundle
# https://www.tcl.tk/man/tcl/TkCmd/menu.htm
apple_menu = tk.Menu(menubar, name='apple')
apple_menu.add_command(label="About %s" % applongname, command=lambda:root.call('tk::mac::standardAboutPanel'))
apple_menu.add_command(label="About %s" % applongname, command=lambda:self.w.call('tk::mac::standardAboutPanel'))
apple_menu.add_command(label="Statistics", command=lambda:stats.StatsDialog(self.w, self.session))
apple_menu.add_command(label="Check for Update", command=lambda:self.updater.checkForUpdates())
menubar.add_cascade(menu=apple_menu)
window_menu = tk.Menu(menubar, name='window')
menubar.add_cascade(menu=window_menu)
# https://www.tcl.tk/man/tcl/TkCmd/tk_mac.htm
root.createcommand('tkAboutDialog', lambda:root.call('tk::mac::standardAboutPanel'))
root.createcommand("::tk::mac::Quit", self.onexit)
root.createcommand("::tk::mac::ShowPreferences", lambda:prefs.PreferencesDialog(self.w, self.login))
root.createcommand("::tk::mac::ReopenApplication", self.w.deiconify) # click on app in dock = restore
root.protocol("WM_DELETE_WINDOW", self.w.withdraw) # close button shouldn't quit app
self.w.createcommand('tkAboutDialog', lambda:self.w.call('tk::mac::standardAboutPanel'))
self.w.createcommand("::tk::mac::Quit", self.onexit)
self.w.createcommand("::tk::mac::ShowPreferences", lambda:prefs.PreferencesDialog(self.w, self.login))
self.w.createcommand("::tk::mac::ReopenApplication", self.w.deiconify) # click on app in dock = restore
self.w.protocol("WM_DELETE_WINDOW", self.w.withdraw) # close button shouldn't quit app
else:
file_menu = tk.Menu(menubar, tearoff=tk.FALSE)
file_menu.add_command(label="Statistics", command=lambda:stats.StatsDialog(self.w, self.session))
Expand All @@ -98,7 +98,7 @@ def __init__(self, master):
file_menu.add_separator()
file_menu.add_command(label="Exit", command=self.onexit)
menubar.add_cascade(label="File", menu=file_menu)
root.protocol("WM_DELETE_WINDOW", self.onexit)
self.w.protocol("WM_DELETE_WINDOW", self.onexit)
if platform == 'linux2':
# Fix up menu to use same styling as everything else
(fg, bg, afg, abg) = (style.lookup('TLabel.label', 'foreground'),
Expand Down Expand Up @@ -127,8 +127,8 @@ def __init__(self, master):

# Load updater after UI creation (for WinSparkle)
import update
self.updater = update.Updater(master)
master.bind_all('<<Quit>>', self.onexit) # user-generated
self.updater = update.Updater(self.w)
self.w.bind_all('<<Quit>>', self.onexit) # user-generated


# call after credentials have changed
Expand Down Expand Up @@ -265,14 +265,8 @@ def onexit(self, event=None):
self.w.destroy()


# Run the app
if __name__ == "__main__":

if platform=='win32' and getattr(sys, 'frozen', False):
# By deault py2exe tries to write log to dirname(sys.executable) which fails when installed
import tempfile
sys.stderr = open(join(tempfile.gettempdir(), '%s.log' % appname), 'wt')

# Run the app
root = tk.Tk()
app = AppWindow(root)
root.mainloop()
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ def iterRecipes(module=recipes):
name = APPLONGNAME,
version = VERSION,
app = [APP],
windows = [ {'script': APP,
windows = [ {'dest_base': APPNAME,
'script': 'winlauncher.py',
'icon_resources': [(0, '%s.ico' % APPNAME)],
'copyright': u'© 2015 Jonathan Harris',
'name': APPNAME, # WinSparkle
Expand Down
20 changes: 20 additions & 0 deletions winlauncher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/python
#
# Launcher when running py2exe

import sys
getattr(sys, 'frozen') # Only intended to be run under py2exe

# By deault py2exe tries to write log to dirname(sys.executable) which fails when installed
from os.path import join
import tempfile
from config import appname
sys.stderr = open(join(tempfile.gettempdir(), '%s.log' % appname), 'wt')

import Tkinter as tk
from EDMarketConnector import AppWindow

# Run the app
root = tk.Tk()
app = AppWindow(root)
root.mainloop()

0 comments on commit c36ce2a

Please sign in to comment.