How to add some graphic label to the glyph cell in font overview
RafaŁ Buchner last edited by gferreira
I would like to add a system of marking the changes to my script.
For different reasons, it cannot affect color marking (
The obvious solution for me would be drawing some graphic label on top of the glyph cells in the font overview. Is there any way to achieve that?
Thanks in advance for your help!
there are some glyph cell view notifications:
glyphCollectionDrawis called and provides the collection view. You can draw on top of all the glyph cells.
glyphCellDrawis called for each glyph cell, you can draw additional data inside each cell, this is in glyph coordinates space. The notification provides the
glyphCellview and the
rectof the cell.
hope this helps!!
I'm not sure if this way of dealing with the problem is proper:
let's say that I have a list of glyph names that were somehow changed by the "Action".
I'm labelling the glyphs from the list by:
- checking if the event's glyph is in that list
- refreshing the glyphs in that list with
from mojo.events import addObserver, removeObserver from mojo.drawingTools import * import vanilla class Test: def __init__(self): self.w = vanilla.FloatingWindow((200,50),"TEST") self.w.bind("close", self.closeCB) self.w.open() self.w.button = vanilla.SquareButton((0,0,-0,-0),"Action",callback=self.actionCB) addObserver(self,"drawCell","glyphCellDraw") self.changedGlyphs =  self.f = CurrentFont() def drawCell(self, info): glyphName = info["glyph"].name if glyphName in self.changedGlyphs: fill(1,0,0) rect(0,0,10,10) def actionCB(self,sender): self.changedGlyphs = ["a","b","c"] # making sure that cells will be labeled: # (are cells only labeled after the glyph.changed()?) for glyphName in self.changedGlyphs: self.f[glyphName].changed() def closeCB(self,sender): removeObserver(self,"glyphCellDraw") # cleaning the cells for glyphName in self.changedGlyphs: self.f[glyphName].changed() Test()
Is it ok? or there is there a better way to achieve that?
@RafaŁ-Buchner makes sense to me. nice example for the docs :)
Thanks, feel free to use it
I would store your data in the
glyph.liband draw from the lib data.
glyph.lib["com.rafalbuchner.toolName"] = "changedToSomething"
def drawCell(self, info): glyph = info["glyph"] data = glyph.lib.get("com.rafalbuchner.toolName") if data: fill(1,0,0) rect(0,0,10,10)
the big advantage is the glyph get proper updates when you set or change the data in the glyph.lib.
added to the docs as an example. thanks!