def create_screenshot(settings): icons_size = int(settings.get("icon_size")[0]) application = settings.get("applications")[0] button_list = settings.get("buttons") button_folders, button_names = get_button_folders(button_list, settings) buttons = IconButton(button_folders, button_names, settings, settings.get("applications")) icons = list(buttons.get_icons()) icons.sort() icons_per_row = settings.get("icons_per_row", 18) rows = int(math.ceil(float(len(icons))/icons_per_row)) top_image = Image.open(os.path.join("files", "top.png")) toolbar_image = Image.open(os.path.join("files", "toolbar-back.png")) app_icon = Image.open(os.path.join("files", "icons", "{}.png".format(application))) if app_icon.mode != 'RGBA': app_icon = app_icon.convert('RGBA') height = top_image.size[1] + (toolbar_image.size[1] * rows) width = (icons_size + 8) * icons_per_row image = Image.new("RGB", (width, height), (0, 0, 0, 0)) sized_top = top_image.resize((width, top_image.size[1])) top_height = top_image.size[1] image.paste(sized_top, (0, 0) + sized_top.size) icon_width, icon_height = app_icon.size image.paste(app_icon, (4, (top_height-icon_height)/2), app_icon) draw = ImageDraw.Draw(image) font = ImageFont.truetype(settings.get("screen_shot_font"), settings.get("screen_shot_font_size", 11)) app_name = settings.get("applications_data")[application][0][0] draw.text((icon_width + 9, (top_height-icon_height)/2 + 1), app_name, font=font, fill=(0, 0, 0)) draw.text((icon_width + 8, (top_height-icon_height)/2), app_name, font=font, fill=(255, 255, 255)) sized_toolbar = toolbar_image.resize((width, toolbar_image.size[1])) toolbar_width, toolbar_height = sized_toolbar.size for i in range(rows): image.paste(sized_toolbar, (0, top_height + (i * toolbar_height), toolbar_width, top_height + ((i + 1) * toolbar_height))) for i, icon in enumerate(icons): icon_img = Image.open(button.get_image(settings, settings.get("icon_size")[0], icon)) image.paste(icon_img, (4 + (i % icons_per_row) * (icons_size + 8), (i // icons_per_row * toolbar_height)+top_height+(toolbar_height-icons_size)/2), icon_img) image_name = settings.get("output_file", "{}.png".format("".join(settings.get("applications")))) file_name = os.path.join(settings.get("project_root"), settings.get("output_folder"), image_name) image.save(file_name, "png")
def build_extension(settings, output=None, project_root=None, button_locales=None): button_locales, buttons, locales = create_objects(settings, button_locales) xpi_file_name = os.path.join( settings.get("project_root"), settings.get("output_folder"), settings.get("output_file", "toolbar_buttons.xpi") % settings) if output: xpi = zipfile.ZipFile(output, "w", zipfile.ZIP_DEFLATED) else: xpi = zipfile.ZipFile(xpi_file_name, "w", zipfile.ZIP_DEFLATED) for file, data in buttons.get_js_files().items(): xpi.writestr(os.path.join("chrome", "content", file + ".js"), data.replace("{{uuid}}", settings.get("extension_id"))) for file_name, data in buttons.get_files(): xpi.writestr(os.path.join("chrome", "content", file_name), bytes_string(data)) if settings.get("fix_meta"): locale_name = locales[0] if len(locales) == 1 else None locale_str = buttons.locale_string( button_locale=button_locales, locale_name=locale_name) labels = sorted((locale_str("label", button) for button in buttons.buttons()), key=unicode.lower) if len(buttons) == 1: button = buttons.buttons()[0] settings["name"] = labels[0] + " Button" settings["description"] = buttons.get_description(button) if not settings.get("icon"): settings["icon"] = buttons.get_icons(button) else: description = u"A customized version of {} including the buttons: {}" settings["description"] = description.format( settings["name"], u", ".join(labels)) options = buttons.get_options() for file, data in options.items(): xpi.writestr(os.path.join("chrome", "content", "%s.xul" % file), data) for image in buttons.option_icons: xpi.write(get_image(settings, "32", image), os.path.join("chrome", "skin", "option", image)) locale_prefix = settings.get("locale_file_prefix") for locale, file_name, data in buttons.locale_files(button_locales): xpi.writestr(os.path.join("chrome", "locale", locale, locale_prefix + file_name), bytes_string(data)) for chrome_string in buttons.get_chrome_strings(): xpi.writestr(chrome_string.file_name, bytes_string(chrome_string.data)) for chrome_file in buttons.get_chrome_files(): xpi.write(chrome_file.path, chrome_file.file_name) css, result_images, image_data = buttons.get_css_file() xpi.writestr(os.path.join("chrome", "skin", "button.css"), bytes_string(css)) for size, image_list in result_images.items(): for image in set(image_list): if size is not None: try: xpi.write(get_image(settings, size, image), os.path.join("chrome", "skin", size, image)) except (OSError, IOError): xpi.write(get_image(settings, size, "picture-empty.png"), os.path.join("chrome", "skin", size, image)) print("can not find file %s" % image) for file_name, data in image_data.items(): xpi.writestr(os.path.join("chrome", file_name), data) if settings.get("icon"): path = get_image(settings, "32", settings.get("icon")) xpi.write(path, "icon.png") xpi.write(path, os.path.join("chrome", "skin", "icon.png")) else: path = os.path.join(settings.get("project_root"), "files", "icon.png") xpi.write(path, "icon.png") xpi.write(path, os.path.join("chrome", "skin", "icon.png")) xpi.close() if not output and settings.get("profile_folder"): with open(xpi_file_name, "r") as xpi_fp: data = xpi_fp.read() for folder in settings.get("profile_folder"): try: with open(os.path.join(folder, "extensions", settings.get("extension_id") + ".xpi"), "w") as fp: fp.write(data) except IOError: print("Failed to write extension to profile folder") return buttons
def build_extension(settings, output=None, project_root=None, button_locales=None): button_locales, buttons, locales = create_objects(settings, button_locales) xpi_file_name = os.path.join( settings.get("project_root"), settings.get("output_folder"), settings.get("output_file", "toolbar_buttons.xpi") % settings) if output: xpi = zipfile.ZipFile(output, "w", zipfile.ZIP_DEFLATED) else: xpi = zipfile.ZipFile(xpi_file_name, "w", zipfile.ZIP_DEFLATED) for file, data in buttons.get_js_files().items(): xpi.writestr(os.path.join("chrome", "content", file + ".js"), data.replace("{{uuid}}", settings.get("extension_id"))) for file_name, data in buttons.get_files(): xpi.writestr(os.path.join("chrome", "content", file_name), bytes_string(data)) if settings.get("fix_meta"): locale_name = locales[0] if len(locales) == 1 else None locale_str = buttons.locale_string(button_locale=button_locales, locale_name=locale_name) labels = sorted( (locale_str("label", button) for button in buttons.buttons()), key=unicode.lower) if len(buttons) == 1: button = buttons.buttons()[0] settings["name"] = labels[0] + " Button" settings["description"] = buttons.get_description(button) if not settings.get("icon"): settings["icon"] = buttons.get_icons(button) else: description = u"A customized version of {} including the buttons: {}" settings["description"] = description.format( settings["name"], u", ".join(labels)) options = buttons.get_options() for file, data in options.items(): xpi.writestr(os.path.join("chrome", "content", "%s.xul" % file), data) for image in buttons.option_icons: xpi.write(get_image(settings, "32", image), os.path.join("chrome", "skin", "option", image)) locale_prefix = settings.get("locale_file_prefix") for locale, file_name, data in buttons.locale_files(button_locales): xpi.writestr( os.path.join("chrome", "locale", locale, locale_prefix + file_name), bytes_string(data)) for chrome_string in buttons.get_chrome_strings(): xpi.writestr(chrome_string.file_name, bytes_string(chrome_string.data)) for chrome_file in buttons.get_chrome_files(): xpi.write(chrome_file.path, chrome_file.file_name) css, result_images, image_data = buttons.get_css_file() xpi.writestr(os.path.join("chrome", "skin", "button.css"), bytes_string(css)) for size, image_list in result_images.items(): for image in set(image_list): if size is not None: try: xpi.write(get_image(settings, size, image), os.path.join("chrome", "skin", size, image)) except (OSError, IOError): xpi.write(get_image(settings, size, "picture-empty.png"), os.path.join("chrome", "skin", size, image)) print("can not find file %s" % image) for file_name, data in image_data.items(): xpi.writestr(os.path.join("chrome", file_name), data) if settings.get("icon"): path = get_image(settings, "32", settings.get("icon")) xpi.write(path, "icon.png") xpi.write(path, os.path.join("chrome", "skin", "icon.png")) else: path = os.path.join(settings.get("project_root"), "files", "icon.png") xpi.write(path, "icon.png") xpi.write(path, os.path.join("chrome", "skin", "icon.png")) xpi.close() if not output and settings.get("profile_folder"): with open(xpi_file_name, "r") as xpi_fp: data = xpi_fp.read() for folder in settings.get("profile_folder"): try: with open( os.path.join(folder, "extensions", settings.get("extension_id") + ".xpi"), "w") as fp: fp.write(data) except IOError: print("Failed to write extension to profile folder") return buttons
def create_screenshot(settings): icons_size = int(settings.get("icon_size")[0]) application = settings.get("applications")[0] button_list = settings.get("buttons") button_folders, button_names = get_button_folders(button_list, settings) buttons = IconButton(button_folders, button_names, settings, settings.get("applications")) icons = list(buttons.get_icons()) icons.sort() icons_per_row = settings.get("icons_per_row", 18) rows = int(math.ceil(float(len(icons)) / icons_per_row)) top_image = Image.open(os.path.join("files", "top.png")) toolbar_image = Image.open(os.path.join("files", "toolbar-back.png")) app_icon = Image.open( os.path.join("files", "icons", "{}.png".format(application))) if app_icon.mode != 'RGBA': app_icon = app_icon.convert('RGBA') height = top_image.size[1] + (toolbar_image.size[1] * rows) width = (icons_size + 8) * icons_per_row image = Image.new("RGB", (width, height), (0, 0, 0, 0)) sized_top = top_image.resize((width, top_image.size[1])) top_height = top_image.size[1] image.paste(sized_top, (0, 0) + sized_top.size) icon_width, icon_height = app_icon.size image.paste(app_icon, (4, (top_height - icon_height) / 2), app_icon) draw = ImageDraw.Draw(image) font = ImageFont.truetype(settings.get("screen_shot_font"), settings.get("screen_shot_font_size", 11)) app_name = settings.get("applications_data")[application][0][0] draw.text((icon_width + 9, (top_height - icon_height) / 2 + 1), app_name, font=font, fill=(0, 0, 0)) draw.text((icon_width + 8, (top_height - icon_height) / 2), app_name, font=font, fill=(255, 255, 255)) sized_toolbar = toolbar_image.resize((width, toolbar_image.size[1])) toolbar_width, toolbar_height = sized_toolbar.size for i in range(rows): image.paste(sized_toolbar, (0, top_height + (i * toolbar_height), toolbar_width, top_height + ((i + 1) * toolbar_height))) for i, icon in enumerate(icons): icon_img = Image.open( button.get_image(settings, settings.get("icon_size")[0], icon)) image.paste(icon_img, (4 + (i % icons_per_row) * (icons_size + 8), (i // icons_per_row * toolbar_height) + top_height + (toolbar_height - icons_size) / 2), icon_img) image_name = settings.get( "output_file", "{}.png".format("".join(settings.get("applications")))) file_name = os.path.join(settings.get("project_root"), settings.get("output_folder"), image_name) image.save(file_name, "png")