Skip to content

Commit

Permalink
Merge pull request #10 from schriftgestalt/master
Browse files Browse the repository at this point in the history
Python 3
  • Loading branch information
chrissimpkins authored Jun 8, 2020
2 parents 859d20c + 9667d76 commit e144cd6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 55 deletions.
16 changes: 4 additions & 12 deletions FilterListManager.glyphsPlugin/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDisplayName</key>
<string>Filter List Manager</string>
<string>en</string>
<key>CFBundleExecutable</key>
<string>plugin</string>
<key>CFBundleIdentifier</key>
Expand All @@ -14,12 +12,10 @@
<string>6.0</string>
<key>CFBundleName</key>
<string>FilterListManager</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleVersion</key>
<string>50</string>
<key>CFBundleShortVersionString</key>
<string>0.5.0</string>
<string>0.5.1</string>
<key>CFBundleVersion</key>
<string>51</string>
<key>UpdateFeedURL</key>
<string>https://raw.githubusercontent.com/source-foundry/FilterListManager/master/FilterListManager.glyphsPlugin/Contents/Info.plist</string>
<key>productPageURL</key>
Expand All @@ -30,9 +26,5 @@
<string>Copyright 2018 Christopher Simpkins, Apache License 2.0</string>
<key>NSPrincipalClass</key>
<string>FilterListManager</string>
<key>PyMainFileNames</key>
<array>
<string>../MacOS/main.py</string>
</array>
</dict>
</plist>
16 changes: 0 additions & 16 deletions FilterListManager.glyphsPlugin/Contents/MacOS/main.py

This file was deleted.

Binary file modified FilterListManager.glyphsPlugin/Contents/MacOS/plugin
Binary file not shown.
1 change: 0 additions & 1 deletion FilterListManager.glyphsPlugin/Contents/PkgInfo

This file was deleted.

59 changes: 33 additions & 26 deletions FilterListManager.glyphsPlugin/Contents/Resources/plugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# encoding: utf-8
from __future__ import division, print_function, unicode_literals

# ##########################################################################################################
###########################################################################################################
#
#
# Filter List Manager
Expand All @@ -9,16 +10,20 @@
# Apache License 2.0
#
#
# ##########################################################################################################
###########################################################################################################

import logging
import objc
import os
import plistlib
import shutil
import subprocess
import urllib2
import urlparse
try:
import urllib2 as urllibrequest
import urlparse as urllibparse
except:
import urllib.request as urllibrequest
import urllib.parse as urllibparse

from GlyphsApp import *
from GlyphsApp.plugins import *
Expand Down Expand Up @@ -84,45 +89,43 @@


class FilterListManager(GeneralPlugin):
@objc.python_method
def settings(self):
self.update_name = Glyphs.localize(
{
"en": u"Update Filter Lists",
"de": u"Filterlisten aktualisieren"
"en": "Update Filter Lists",
"de": "Filterlisten aktualisieren"
}
)
self.restoredefault_name = Glyphs.localize(
{
"en": u"Restore Default Filter Lists",
"de": u"Standard-Filterlisten wiederherstellen",
"en": "Restore Default Filter Lists",
"de": "Standard-Filterlisten wiederherstellen",
}
)
self.opendir_name = Glyphs.localize(
{
"en": u"Open GlyphsFilters Directory",
"de": u"Verzeichnis GlyphsFilters öffnen",
"en": "Open GlyphsFilters Directory",
"de": "Verzeichnis GlyphsFilters öffnen",
}
)

@objc.python_method
def start(self):
try:
# new API in Glyphs 2.3.1-910
new_update_menu_item = NSMenuItem(self.update_name, self.update_filters)
new_restore_menu_item = NSMenuItem(
self.restoredefault_name, self.restore_filters
)
new_opendir_menu_item = NSMenuItem(
self.opendir_name, self.open_glyphsfilters_directory
)
new_update_menu_item = NSMenuItem(self.update_name, self.updateFilters_)
new_restore_menu_item = NSMenuItem(self.restoredefault_name, self.restoreFilters_)
new_opendir_menu_item = NSMenuItem(self.opendir_name, self.openGlyphsfiltersDirectory_)
Glyphs.menu[EDIT_MENU].append(new_update_menu_item)
Glyphs.menu[EDIT_MENU].append(new_restore_menu_item)
Glyphs.menu[EDIT_MENU].append(new_opendir_menu_item)
except Exception:
main_menu = Glyphs.mainMenu()
update_selector = objc.selector(self.update_filters, signature="v@:@")
restore_selector = objc.selector(self.restore_filters, signature="v@:@")
update_selector = objc.selector(self.updateFilters_, signature="v@:@")
restore_selector = objc.selector(self.restoreFilters_, signature="v@:@")
open_selector = objc.selector(
self.open_glyphsfilters_directory, signature="v@:@"
self.openGlyphsfiltersDirectory_, signature="v@:@"
)
new_update_menu_item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
self.update_name, update_selector, ""
Expand All @@ -140,7 +143,7 @@ def start(self):
new_open_menu_item.setTarget_(self)
main_menu.itemWithTag_(5).submenu().addItem_(new_open_menu_item)

def update_filters(self, sender):
def updateFilters_(self, sender):
"""Perform the list filter update"""
# Expected filter definitions directory test
if not self.filter_directory_is_present():
Expand Down Expand Up @@ -311,7 +314,7 @@ def update_filters(self, sender):
"The filter list updates were successful. Please quit and restart the Glyphs application to view the new filter lists."
)

def restore_filters(self, sender):
def restoreFilters_(self, sender):
"""Perform restore of default list filters"""
# copy the default definitions to the Glyphs application
try:
Expand All @@ -335,7 +338,7 @@ def restore_filters(self, sender):
"The default filter list restoration was successful. Please quit and restart the Glyphs application to view the filter lists."
)

def open_glyphsfilters_directory(self, sender):
def openGlyphsfiltersDirectory_(self, sender):
"""Called from a plugin Edit menu item and opens the ~/GlyphsFilters directory in the macOS Finder"""
if not os.path.isdir(FLM_GLYPHSFILTERS_DIR):
Glyphs.showNotification(
Expand All @@ -351,13 +354,15 @@ def open_glyphsfilters_directory(self, sender):
"The ~/GlyphsFilters directory was opened with the Edit menu item."
)

@objc.python_method
def filter_directory_is_present(self):
"""Tests for presence of the ~/GlyphsFilters directory"""
if not os.path.isdir(FLM_GLYPHSFILTERS_DIR):
return False
else:
return True

@objc.python_method
def get_local_filter_definitions_list(self):
"""Reads and launches parsing of local definition files, returns a Python list of
Filter objects that are created from the parse"""
Expand Down Expand Up @@ -392,6 +397,7 @@ def get_local_filter_definitions_list(self):

return local_definitions_list

@objc.python_method
def get_remote_filter_definitions_list(self):
"""Pulls, reads, and launches parsing of remote definition files, returns a Python list of
Filter objects that are created from the parse"""
Expand All @@ -410,20 +416,21 @@ def get_remote_filter_definitions_list(self):
else:
# unquote URL defined in list to define file name
# (in case the user pasted a urlencoded string)
decoded_url = urllib2.unquote(url)
parsed_url = urlparse.urlparse(decoded_url).path
decoded_url = urllibparse.unquote(url)
parsed_url = urllibparse.urlparse(decoded_url).path
parsed_path = os.path.split(parsed_url)
filter_defintion_filename = parsed_path[1]
new_filter = Filter(filter_defintion_filename)

# quote URL defined in list to make HTTP GET request
response = urllib2.urlopen(url)
response = urllibrequest.urlopen(url)
text = response.read()
new_filter.define_list_with_newline_delimited_text(text)
remote_definitions_list.append(new_filter)

return remote_definitions_list

@objc.python_method
def __file__(self):
"""Glyphs plugin API specific method. Please leave this method unchanged"""
return __file__
Expand Down

0 comments on commit e144cd6

Please sign in to comment.