-
-
Save gferreira/96299931cfdea56a4da46546efb6affc to your computer and use it in GitHub Desktop.
dropfile-ui
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# jackson # [email protected] | |
import os | |
from AppKit import NSFilenamesPboardType, NSDragOperationCopy | |
from vanilla import Window, List, Button | |
class doThing(): | |
def __init__(self, path): | |
f = OpenFont(path, showInterface=False) | |
# do something here | |
print(f.info.familyName, f.info.styleName) | |
# f.save() | |
f.close() | |
class getListofFiles(): | |
supportedFontFileFormats = ['.ufo'] | |
def __init__(self): | |
L = 0 # left | |
T = 0 # top | |
W = 600 # width | |
H = 300 # height | |
p = 10 # padding | |
buttonHeight = 20 | |
self.w = Window((W, H), "Do Thing To These Files", 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), | |
) | |
self.w.open() | |
buttonText = 'Do Thing' | |
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: | |
doThing(path['Files']) | |
path['?'] = '✅' | |
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: | |
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