Skip to content

Commit

Permalink
Added icon and splash file support.
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed Jul 30, 2015
1 parent 7f00ce9 commit bf349c7
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 35 deletions.
41 changes: 39 additions & 2 deletions briefcase/android.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import os
import shutil

from .app import app


Expand All @@ -7,8 +10,9 @@ class android(app):
def finalize_options(self):
# Copy over all the options from the base 'app' command
finalized = self.get_finalized_command('app')
for attr in ('formal_name', 'bundle', 'download_dir'):
setattr(self, attr, getattr(finalized, attr))
for attr in ('formal_name', 'bundle', 'icon', 'splash', 'download_dir'):
if getattr(self, attr) is None:
setattr(self, attr, getattr(finalized, attr))

# Set platform-specific options
self.platform = 'Android'
Expand All @@ -17,3 +21,36 @@ def finalize_options(self):
self.dir = self.platform

self.resource_dir = self.dir
self.icon_filename = os.path.join(self.resource_dir, self.distribution.get_name() + os.path.splitext(self.icon)[1])

def install_icon(self):
last_size = None
for size in ['180x180', '152x152', '120x120', '80x80', '76x76', '58x58', '40x40', '29x29']:
if isinstance(self.icon, dict):
try:
icon_file = self.icon[size]
last_size = size
except KeyError:
print("WARING: No %sx%s icon file available; using ." % size)
icon_file = self.icon.get(last_size, None)
else:
icon_file = self.icon

if icon_file:
shutil.copyfile(
self.icon[size],
os.path.join(self.resource_dir, self.distribution.get_name(), 'Images.xcassets', 'AppIcon.appiconset', 'icon-%s' % size + os.path.splitext(icon_file)[1])
)
else:
print("WARING: No %sx%s icon file available." % size)

def install_splash(self):
for size in ['1024x768', '1536x2048', '2048x1536', '768x1024', '640x1136', '640x960']:
try:
icon_file = self.icon[size]
shutil.copyfile(
self.icon[size],
os.path.join(self.resource_dir, self.distribution.get_name(), 'Images.xcassets', 'LaunchImage.launchimage', 'launch-%s' % size + os.path.splitext(icon_file)[1])
)
except KeyError:
print("WARING: No %sx%s splash file available.")
51 changes: 22 additions & 29 deletions briefcase/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import json
import sys

try:
from urllib.request import urlopen
except ImportError: # Python 2 compatibility
Expand All @@ -28,6 +29,10 @@ class app(Command):
"Template (or template repository URL) to use."),
('bundle', None,
'Bundle identifier for the author organization - usually a reversed domain (e.g., "org.python")'),
('icon=', None,
"Name of the icon file."),
('splash=', None,
"Name of the splash screen file."),
('app-requires', None,
'List of platform-specific requirements for this app.'),
('support-pkg=', 's',
Expand All @@ -41,6 +46,8 @@ def initialize_options(self):
self.formal_name = None
self.template = None
self.bundle = None
self.icon = None
self.splash = None
self.app_requires = None
self.support_pkg = None
self.download_dir = None
Expand Down Expand Up @@ -81,10 +88,7 @@ def run(self):
if self.template is None:
self.template = 'https://github.com/pybee/Python-%s-template.git' % self.platform

print()
print("==================================================")
print(" Writing application template...")
print("==================================================")
print(" * Writing application template...")
print("Project template: %s" % self.template)
cookiecutter(
self.template,
Expand All @@ -99,10 +103,7 @@ def run(self):
}
)

print()
print("==================================================")
print(" Installing requirements...")
print("==================================================")
print(" * Installing requirements...")
if self.distribution.install_requires:
pip.main([
'install',
Expand All @@ -114,10 +115,7 @@ def run(self):
else:
print("No requirements.")

print()
print("==================================================")
print(" Installing plaform requirements...")
print("==================================================")
print(" * Installing plaform requirements...")
if self.app_requires:
pip.main([
'install',
Expand All @@ -129,10 +127,7 @@ def run(self):
else:
print("No platform requirements.")

print()
print("==================================================")
print(" Installing project code...")
print("==================================================")
print(" * Installing project code...")
pip.main([
'install',
'--upgrade',
Expand All @@ -142,20 +137,21 @@ def run(self):
'.'
])

if self.icon:
print(" * Adding icons...")
self.install_icon()

if self.splash:
print(" * Adding splash screens...")
self.install_splash()

if self.support_pkg is None:
print()
print("==================================================")
print(" Determining best support package...")
print("==================================================")
print(" * Determining best support package...")
self.support_pkg = self.find_support_pkg()

if self.support_pkg:
print()
print("==================================================")
print(" Installing support package...")
print("==================================================")
print(" * Installing support package...")
print("Support package: ", self.support_pkg)
print()

pip.download.unpack_url(
pip.index.Link(self.support_pkg),
Expand All @@ -177,7 +173,4 @@ def run(self):

def post_run(self):
print()
print("==================================================")
print(" Installation complete.")
print("==================================================")
print()
print("Installation complete.")
43 changes: 41 additions & 2 deletions briefcase/ios.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import os
import shutil

from .app import app


Expand All @@ -7,8 +10,9 @@ class ios(app):
def finalize_options(self):
# Copy over all the options from the base 'app' command
finalized = self.get_finalized_command('app')
for attr in ('formal_name', 'bundle', 'download_dir'):
setattr(self, attr, getattr(finalized, attr))
for attr in ('formal_name', 'bundle', 'icon', 'splash', 'download_dir'):
if getattr(self, attr) is None:
setattr(self, attr, getattr(finalized, attr))

# Set platform-specific options
self.platform = 'iOS'
Expand All @@ -17,3 +21,38 @@ def finalize_options(self):
self.dir = self.platform

self.resource_dir = self.dir

if not isinstance(self.icon, dict):
raise RuntimeError('Splash image specifier must be a dictionary')

def install_icon(self):
last_size = None
for size in ['180x180', '152x152', '120x120', '80x80', '76x76', '58x58', '40x40', '29x29']:
if isinstance(self.icon, dict):
try:
icon_file = self.icon[size]
last_size = size
except KeyError:
print("WARING: No %sx%s icon file available; using ." % size)
icon_file = self.icon.get(last_size, None)
else:
icon_file = self.icon

if icon_file:
shutil.copyfile(
self.icon[size],
os.path.join(self.resource_dir, self.distribution.get_name(), 'Images.xcassets', 'AppIcon.appiconset', 'icon-%s' % size + os.path.splitext(icon_file)[1])
)
else:
print("WARING: No %sx%s icon file available." % size)

def install_splash(self):
for size in ['1024x768', '1536x2048', '2048x1536', '768x1024', '640x1136', '640x960']:
try:
icon_file = self.icon[size]
shutil.copyfile(
self.icon[size],
os.path.join(self.resource_dir, self.distribution.get_name(), 'Images.xcassets', 'LaunchImage.launchimage', 'launch-%s' % size + os.path.splitext(icon_file)[1])
)
except KeyError:
print("WARING: No %sx%s splash file available.")
18 changes: 16 additions & 2 deletions briefcase/osx.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import shutil

from .app import app

Expand All @@ -9,8 +10,9 @@ class osx(app):
def finalize_options(self):
# Copy over all the options from the base 'app' command
finalized = self.get_finalized_command('app')
for attr in ('formal_name', 'bundle', 'download_dir'):
setattr(self, attr, getattr(finalized, attr))
for attr in ('formal_name', 'bundle', 'icon', 'splash', 'download_dir'):
if getattr(self, attr) is None:
setattr(self, attr, getattr(finalized, attr))

# Set platform-specific options
self.platform = 'OSX'
Expand All @@ -20,3 +22,15 @@ def finalize_options(self):
self.resource_dir = os.path.join('%s.app' % self.formal_name, 'Contents', 'Resources')
else:
self.resource_dir = os.path.join(self.dir, '%s.app' % self.formal_name, 'Contents', 'Resources')

if isinstance(self.icon, dict):
iconfile = self.icon['icns']
else:
iconfile = self.icon
self.icon_filename = os.path.join(self.resource_dir, self.distribution.get_name() + os.path.splitext(iconfile)[1])

def install_icon(self):
shutil.copyfile(self.icon, self.icon_filename)

def install_splash(self):
raise RuntimeError("OSX doesn't support splash screens.")

0 comments on commit bf349c7

Please sign in to comment.