Skip to content
This repository has been archived by the owner on Jan 17, 2019. It is now read-only.

Commit

Permalink
Merge branch 'master' of https://github.com/typesupply/dialogKit
Browse files Browse the repository at this point in the history
  • Loading branch information
typemytype committed Aug 24, 2018
2 parents d0442ac + 1437832 commit d049131
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 70 deletions.
Binary file added Lib/dialogKit/__init__.pyc
Binary file not shown.
Binary file added Lib/dialogKit/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file not shown.
114 changes: 57 additions & 57 deletions Lib/dialogKit/_dkFL.py
Expand Up @@ -43,7 +43,7 @@ def __init__(self, posSize, title=None, okText="OK", cancelText="Cancel", okCall
#
self._okCallback=okCallback
self._cancelCallback=cancelCallback

def __setattr__(self, attr, value):
if isinstance(value, UIBaseObject):
assert not hasattr(self, attr), "attribute '%s' can not be replaced" % attr
Expand Down Expand Up @@ -90,30 +90,30 @@ def __setattr__(self, attr, value):
# it doesn't matter if the value does not have a callback
# assigned. the _callbackWrapper method safely handles
# those cases. the reason it is not handled here is that
# custom controls (used by _CanvasWrapper) use the method
# custom controls (used by _CanvasWrapper) use the method
# normally reserved for control hits to paint the control.
setattr(self, 'on_%s' % value._contentID, value._callbackWrapper)
super(ModalDialog, self).__setattr__(attr, value)
super(ModalDialog, self).__setattr__(attr, value)

def open(self):
"""open the dialog"""
self._dialog.Run()

def close(self):
"""close the dialog"""
self._dialog.End()

def on_cancel(self, code):
if self._cancelCallback is not None:
self._cancelCallback(self)

def on_ok(self, code):
if self._okCallback is not None:
self._okCallback(self)


class UIBaseObject(object):

def __init__(self, posSize, title, callback=None, content=None):
self._posSize = posSize
self._title = title
Expand All @@ -122,16 +122,16 @@ def __init__(self, posSize, title, callback=None, content=None):

def _setDialog(self, dialog):
self._dialog = weakref.ref(dialog)

def _callbackWrapper(self, code):
if self._callback is not None:
self._callback(self)

def _setupContent(self):
# set the attribute data in the parent class.
# this will be used for GetValue and PutValue operations.
setattr(self._dialog(), self._contentID, self._content)

def enable(self, value):
"""
enable the object by passing True
Expand All @@ -140,15 +140,15 @@ def enable(self, value):
value = int(value)
dialog = self._dialog()
dialog._dialog.Enable(self._contentID, value)

def show(self, value):
"""
show the object by passing True
hide the object by passing False
"""
dialog = self._dialog()
dialog._dialog.Show(self._contentID, value)

def set(self, value):
"""
set the content of the object
Expand All @@ -166,7 +166,7 @@ def set(self, value):
dialog._dialog.PutValue(self._contentID)
# reset the callback
self._callback = callback

def get(self):
"""
return the contents of the object
Expand All @@ -175,36 +175,36 @@ def get(self):
dialog._dialog.GetValue(self._contentID)
self._content = getattr(dialog, self._contentID)
return self._content


class Button(UIBaseObject):

_type = BUTTONCONTROL
_style = STYLE_BUTTON

def __init__(self, posSize, title, callback=None):
super(Button, self).__init__(posSize=posSize, title=title, callback=callback, content=title)

def set(self, value):
"""
Not implemented for Button
"""
raise NotImplementedError, "It is not possible to set the text in a button"
raise NotImplementedError("It is not possible to set the text in a button")


class PopUpButton(UIBaseObject):

_type = CHOICECONTROL
_style = STYLE_CHOICE

def __init__(self, posSize, items, callback=None):
super(PopUpButton, self).__init__(posSize=posSize, title='', callback=callback, content=items)

def _setupContent(self):
super(PopUpButton, self)._setupContent()
self._contentIndexID = self._contentID + '_index'
self.setSelection(0)

def setSelection(self, value):
"""
set the selected item
Expand All @@ -221,7 +221,7 @@ def setSelection(self, value):
dialog._dialog.PutValue(self._contentID)
# reset the callback
self._callback = callback

def getSelection(self):
"""
return the index of the selected item
Expand All @@ -236,10 +236,10 @@ def getSelection(self):


class List(UIBaseObject):

_type = LISTCONTROL
_style = STYLE_LIST

def __init__(self, posSize, items, callback=None):
super(List, self).__init__(posSize=posSize, title='', callback=callback, content=items)

Expand All @@ -250,14 +250,14 @@ def _setupContent(self):

def __len__(self):
return len(self._content)

def __getitem__(self, index):
return self._content[index]

def __setitem__(self, index, value):
self._content[index] = value
self.set(self._content)

def __delitem__(self, index):
del self._content[index]
self.set(self._content)
Expand Down Expand Up @@ -297,14 +297,14 @@ def replace(self, index, item):
del self._content[index]
self._content.insert(index, item)
self.set(self._content)

#

def setSelection(self, value):
"""
set the selected item index(es)
value should be a list of indexes
in FontLab, it setting multiple
selection indexes is not possible.
"""
Expand All @@ -315,7 +315,7 @@ def setSelection(self, value):
value = value[0]
setattr(dialog, self._contentIndexID, value)
dialog._dialog.PutValue(self._contentID)

def getSelection(self):
"""
return a list of selected item indexes
Expand All @@ -329,7 +329,7 @@ def getSelection(self):
# a 'wrong' index value from the specified LISTCONTROL.
# If the selected index is n, it will return n-1. For example, when
# the index is 1, it returns 0; when it's 2, it returns 1, and so on.
# If the selection is empty, FLS v5.2 returns -2, while the old v5.0
# If the selection is empty, FLS v5.2 returns -2, while the old v5.0
# returned None.
# See also:
# - https://github.com/robofab-developers/robofab/pull/14
Expand All @@ -343,7 +343,7 @@ def getSelection(self):
if index == -1:
return []
return [index]

def set(self, value):
"""
set the contents of the list
Expand All @@ -352,7 +352,7 @@ def set(self, value):
dialog = self._dialog()
setattr(dialog, self._contentID, value)
dialog._dialog.PutValue(self._contentID)

def get(self):
"""
return the contents of the list
Expand All @@ -361,38 +361,38 @@ def get(self):


class EditText(UIBaseObject):

_type = EDITCONTROL
_style = STYLE_EDIT

def __init__(self, posSize, text="", callback=None):
super(EditText, self).__init__(posSize=posSize, title='', callback=callback, content=text)

def set(self, value):
if osName == 'mac':
value = '\r'.join(value.splitlines())
super(EditText, self).set(value)


class TextBox(UIBaseObject):

_type = STATICCONTROL
_style = STYLE_LABEL

def __init__(self, posSize, text):
super(TextBox, self).__init__(posSize=posSize, title=text, callback=None, content=text)

def set(self, value):
if osName == 'mac':
value = '\r'.join(value.splitlines())
super(TextBox, self).set(value)


class CheckBox(UIBaseObject):

_type = CHECKBOXCONTROL
_style = STYLE_CHECKBOX

def __init__(self, posSize, title, callback=None, value=False):
value = int(value)
super(CheckBox, self).__init__(posSize=posSize, title=title, callback=callback, content=value)
Expand All @@ -404,7 +404,7 @@ def set(self, value):
"""
value = int(value)
super(CheckBox, self).set(value)

def get(self):
"""
returns a boolean representing the state of the object
Expand Down Expand Up @@ -481,10 +481,10 @@ def _fontIndex(font):


class GlyphLineView(UIBaseObject):

_type = PREVIEWCONTROL
_style = STYLE_LABEL

def __init__(self, posSize, text="", font=None, rightToLeft=False):
if font is None:
self._fontIndex = fl.ifont
Expand All @@ -493,24 +493,24 @@ def __init__(self, posSize, text="", font=None, rightToLeft=False):
self._rightToLeft = False
text = self._makeText(text)
super(GlyphLineView, self).__init__(posSize=posSize, title="", callback=None, content=text)

def _makeText(self, text):
text = "f:%d|d:%s|r:%d" % (self._fontIndex, text, self._rightToLeft)
return text

def set(self, text):
"""
set the text displayed text string
"""
text = self._makeText(text)
super(GlyphLineView, self).set(text)

def get(self):
"""
return the displayed text string
"""
return self._content[6:-4]

def setFont(self, font):
"""
set the index for the font that should be displayed
Expand All @@ -520,7 +520,7 @@ def setFont(self, font):
else:
self._fontIndex = _fontIndex(font)
self.set(self.get())

def setRightToLeft(self, value):
"""
set the setting directon of the display
Expand All @@ -530,7 +530,7 @@ def setRightToLeft(self, value):


class GlyphView(_CanvasWrapper):

def __init__(self, posSize, font, glyph, margin=30,
showFill=True, showOutline=False,
showDescender=True, showBaseline=True, showXHeight=True,
Expand All @@ -555,7 +555,7 @@ def __init__(self, posSize, font, glyph, margin=30,
self._showOnCurvePoints = showOnCurvePoints
#
self.set(font, glyph)

def set(self, font, glyph):
"""
change the glyph displayed in the view
Expand All @@ -566,7 +566,7 @@ def set(self, font, glyph):
else:
self._font = _unwrapRobofab(font)
self._glyph = _unwrapRobofab(glyph)

###

def getShowFill(self):
Expand Down Expand Up @@ -642,12 +642,12 @@ def setShowOnCurvePoints(self, value):
self._showOnCurvePoints = value

###

def update(self):
if hasattr(self, '_dialog'):
dialog = self._dialog()
dialog._dialog.Repaint(self._contentID)

def _paint(self, canvas):
if self._font is None or self._glyph is None:
return
Expand Down
Binary file added Lib/dialogKit/_dkVanilla.pyc
Binary file not shown.

0 comments on commit d049131

Please sign in to comment.