Skip to content

Instantly share code, notes, and snippets.

@okay-type
Last active September 19, 2019 18:59
Show Gist options
  • Save okay-type/06d64fcd0d2d3bcd03744510604b29ad to your computer and use it in GitHub Desktop.
Save okay-type/06d64fcd0d2d3bcd03744510604b29ad to your computer and use it in GitHub Desktop.
dropfile-ui
# jackson # [email protected]
# version 0.3 - conditional status icons
import os
from AppKit import NSFilenamesPboardType, NSDragOperationCopy
from vanilla import Window, List, Button
action = 'Do Thing'
class doThing():
def __new__(self, path):
success = '✅'
failure = '❌'
maaaybe = '⚠️'
try:
f = OpenFont(path, showInterface=False)
self.action(f)
# set status based on something
a = f.info.italicAngle
status = success
if a != None and a != 0.0:
status = maaaybe
# f.save()
f.close()
except Exception as e:
print(e)
status = failure
return status
def action(self, f):
print(f)
class getListofFiles():
supportedFontFileFormats = ['.ufo']
def __init__(self):
L = T = 0 # top / left
W = 600 # width
H = W/2 # height
p = 10 # padding
buttonHeight = p*2
title = action + ' To These Files'
self.w = Window((W, H), title, minSize=(W/3, H/3))
self.w.fileList = List(
(L, T, -0, -(p * 2 + buttonHeight)),
[],
columnDescriptions=[
{"title": "?", "width": 25}, # status
{"title": "Files", "allowsSorting": True}], # files
showColumnTitles=False,
allowsMultipleSelection=True,
enableDelete=True,
otherApplicationDropSettings = dict(
type=NSFilenamesPboardType,
operation=NSDragOperationCopy,
callback=self.dropCallback),
)
buttonText = action
buttonPos = (p, -(p + buttonHeight), -p, buttonHeight)
self.w.button = Button(buttonPos, buttonText, callback=self.buttonCallback)
self.w.open()
def buttonCallback(self, sender):
for path in self.w.fileList:
path['?'] = doThing(path['Files'])
def dropCallback(self, sender, dropInfo):
isProposal = dropInfo["isProposal"]
existingPaths = sender.get()
paths = dropInfo["data"]
paths = [path for path in paths if path not in existingPaths]
paths = [path for path in paths if os.path.splitext(path)[-1].lower() in self.supportedFontFileFormats or os.path.isdir(path)]
if not paths:
return False
if not isProposal:
for path in paths:
item = {}
item['?'] = '⚪️'
item['Files'] = path
self.w.fileList.append(item)
return True
try:
getListofFiles()
except Exception as e:
print(e)
message = 'well shit'
os.system(f'say "{message}"')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment