Skip to content

Commit

Permalink
python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
schriftgestalt committed Jun 4, 2020
1 parent fedecbb commit 9667d76
Showing 1 changed file with 33 additions and 26 deletions.
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 9667d76

Please sign in to comment.