Esempio n. 1
0
 def update(self):
     self.glyph_window = CurrentGlyphWindow()
     if self.glyph_window is not None:
         self.glyph = CurrentGlyph()
         self.font = self.glyph.getParent()
         self.glyph_index = self.font.glyphOrder.index(self.glyph.name)
         self.font_index = self.all_fonts.index(self.font)
         self._update_text_box()
         return True
     else:
         f = CurrentFont()
         if f is not None:
             self.font = f
             self.font_index = self.all_fonts.index(self.font)
             glyph_names = get_glyphs(f)
             if len(glyph_names) > 0:
                 self.glyph = self.font[glyph_names[0]]
                 self.glyph_index = self.font.glyphOrder.index(self.glyph.name)
                 self.glyph_window = OpenGlyphWindow(self.glyph, newWindow=False)
                 self._update_text_box()
                 return True
             else:
                 print no_glyph_selected
                 return False
         else:
             print no_font_open
             return False
Esempio n. 2
0
    def _mouseDown(self, infoDict):
        mouseDownPoint = infoDict['point']
        mouseDownClickCount = infoDict['clickCount']

        # double click
        if mouseDownClickCount == 2:
            if self.lftNeighborActive is True and self.lftGlyphName:
                lftGlyph = chooseRightGlyph(self.lftFontPath,
                                            self.lftGlyphName)
                if version[0] == '2':
                    xMin, yMin, xMax, yMax = lftGlyph.bounds
                else:
                    xMin, yMin, xMax, yMax = lftGlyph.box
                if xMin < (mouseDownPoint.x + lftGlyph.width
                           ) < xMax and yMin < mouseDownPoint.y < yMax:
                    OpenGlyphWindow(glyph=lftGlyph, newWindow=True)

            if self.rgtNeighborActive is True and self.rgtGlyphName:
                rgtGlyph = chooseRightGlyph(self.rgtFontPath,
                                            self.rgtGlyphName)
                if version[0] == '2':
                    xMin, yMin, xMax, yMax = rgtGlyph.bounds
                else:
                    xMin, yMin, xMax, yMax = rgtGlyph.box
                if xMin < (mouseDownPoint.x - self.currentGlyph.width
                           ) < xMax and yMin < mouseDownPoint.y < yMax:
                    OpenGlyphWindow(glyph=rgtGlyph, newWindow=True)
Esempio n. 3
0
 def update(self):
     self.glyph_window = CurrentGlyphWindow()
     if self.glyph_window is not None:
         self.glyph = CurrentGlyph()
         self.font = self.glyph.getParent()
         self.glyph_index = self.font.glyphOrder.index(self.glyph.name)
         self.font_index = self.all_fonts.index(self.font)
         self._update_text_box()
         return True
     else:
         f = CurrentFont()
         if f is not None:
             self.font = f
             self.font_index = self.all_fonts.index(self.font)
             glyph_names = get_glyphs(f)
             if len(glyph_names) > 0:
                 self.glyph = self.font[glyph_names[0]]
                 self.glyph_index = self.font.glyphOrder.index(
                     self.glyph.name)
                 self.glyph_window = OpenGlyphWindow(self.glyph,
                                                     newWindow=False)
                 self._update_text_box()
                 return True
             else:
                 print(no_glyph_selected)
                 return False
         else:
             print(no_font_open)
             return False
Esempio n. 4
0
 def layer_up(self):
     try:
         self.glyph_window.layerUp()
     except AttributeError:
         self.glyph_window = CurrentGlyphWindow()
         self.glyph_window.layerUp()
     self.update()
Esempio n. 5
0
 def layer_up(self):
     try:
         self.glyph_window.layerUp()
     except AttributeError:
         self.glyph_window = CurrentGlyphWindow()
         self.glyph_window.layerUp()
     self.update()
Esempio n. 6
0
 def openGlyph(self, sender):
     sel = sender.getSelection()
     if sel:
         i = sel[0]
         name = sender[i]
         self._canUpdateChangeCount = False
         OpenGlyphWindow(self._font[name])
         self._canUpdateChangeCount = True
Esempio n. 7
0
 def previous_glyph(self):
     prev = previous_glyph(self.font, self.glyph_index)
     try:
         self.glyph_window.setGlyphByName(prev)
     except AttributeError:
         self.glyph_window = CurrentGlyphWindow()
         self.glyph_window.setGlyphByName(prev)
     self.update()
Esempio n. 8
0
 def next_glyph(self):
     next = next_glyph(self.font, self.glyph_index)
     try:
         self.glyph_window.setGlyphByName(next)
     except AttributeError:
         self.glyph_window = CurrentGlyphWindow()
         self.glyph_window.setGlyphByName(next)
     self.update()
Esempio n. 9
0
 def next_glyph(self):
     next = next_glyph(self.font, self.glyph_index)
     try:
         self.glyph_window.setGlyphByName(next)
     except AttributeError:
         self.glyph_window = CurrentGlyphWindow()
         self.glyph_window.setGlyphByName(next)
     self.update()
Esempio n. 10
0
 def previous_glyph(self):
     prev = previous_glyph(self.font, self.glyph_index)
     try:
         self.glyph_window.setGlyphByName(prev)
     except AttributeError:
         self.glyph_window = CurrentGlyphWindow()
         self.glyph_window.setGlyphByName(prev)
     self.update()
Esempio n. 11
0
 def mouseDown(self, info):
     pointX, pointY = info.locationInWindow()
     for loc in self.glyphLocation_in_Window:
         x, y, w, h = loc
         if x < (pointX-400)/self.scale < x+w and y < (pointY-224)/self.scale < y+h:
             self.gl.StorageGlyphCurrentLayer = self.glyphLocation_in_Window[loc]
             if info.clickCount() == 2:
                 OpenGlyphWindow(self.gl.StorageGlyphCurrentLayer)
     self.update()
Esempio n. 12
0
 def _glyphset_List_doubleClickCallback(self, sender):
     sel = sender.getSelection()
     if not sel: return
     if self.ui.glyph is None: return
     OpenGlyphWindow(self.ui.glyph)
     gw = CurrentGlyphWindow()
     appearance = NSAppearance.appearanceNamed_(
         'NSAppearanceNameVibrantDark')
     gw.window().getNSWindow().setAppearance_(appearance)
Esempio n. 13
0
 def lineViewDoubleClickCallback(self, sender):
     if sender.getSelectedGlyph() is not None:
         doodleGlyph = sender.getSelectedGlyph()
         doodleFont = doodleGlyph.getParent()
         for indexFont, eachFont in enumerate(self.fontsOrder):
             if eachFont.path == doodleFont.path:
                 roboGlyph = self.fontsOrder[indexFont][doodleGlyph.name]
                 break
         if roboGlyph is not None:
             OpenGlyphWindow(glyph=roboGlyph, newWindow=False)
Esempio n. 14
0
    def mouseDown(self, info):
        pointX, pointY = info.locationInWindow()
        didInside = False

        for loc in self.glyphLocation_in_Window:

            x, y, w, h = loc
            if x < (pointX -
                    self.margin) / self.scale - self.scrollX < x + w and y < (
                        pointY + 20) / self.scale - self.scroll < y + h:
                self.selectedGlyph = self.glyphLocation_in_Window[loc]
                didInside = True
                if info.clickCount() == 2:
                    OpenGlyphWindow(self.ui.font[self.selectedGlyph.name])

        if not didInside:
            self.selectedGlyph = None
        self.w.canvas.update()
Esempio n. 15
0
 def _up_right_callback(self, sender):
     if len(self.all_fonts) > 1:
         # get next font
         f = CurrentFont()
         i = self.all_fonts.index(f)
         try:
             next_i = i + 1
             next_font = self.all_fonts[next_i]
         except IndexError:
             next_i = 0
             next_font = self.all_fonts[next_i]
         # get glyph
         g_current = CurrentGlyph()
         if g_current is not None:
             if g_current.name in next_font:
                 next_glyph = next_font[g_current.name]
             else:
                 next_glyph = next_font[next_font.glyphOrder[0]]
             # switch to glyph window
             G = OpenGlyphWindow(next_glyph, newWindow=False)
             # update UI
             self.update()
Esempio n. 16
0
 def _down_left_callback(self, sender):
     if len(self.all_fonts) > 1:
         # get next font
         f = CurrentFont()
         i = self.all_fonts.index(f)
         try:
             prev_i = i - 1
             prev_font = self.all_fonts[prev_i]
         except IndexError:
             prev_i = -1
             prev_font = self.all_fonts[prev_i]
         # get glyph
         g_current = CurrentGlyph()
         if g_current is not None:
             if g_current.name in prev_font:
                 prev_glyph = prev_font[g_current.name]
             else:
                 prev_glyph = prev_font[prev_font.glyphOrder[0]]
             # switch to glyph window
             G = OpenGlyphWindow(prev_glyph, newWindow=False)
             # update UI
             self.update()
Esempio n. 17
0
    def openSelectedComponent(self, f, g):
        selectedComponents = [c for c in g.components if c.selected]

        if not len(selectedComponents):
            message("There is no selected components")
            return

        selectedComponent = selectedComponents[0]
        self.selectedComponentName = selectedComponent.baseGlyph
        self.selectedComponentOffset = selectedComponent.transformation[-2:]
        
        self.oldGlyph = g

        OpenGlyphWindow(f[self.selectedComponentName])

        self.currentGlyph = CurrentGlyph()

        addObserver(self, "currentGlyphChanged", "currentGlyphChanged")
        addObserver(self, "draw", "draw")
        addObserver(self, "draw", "drawPreview")
        addObserver(self, "draw", "drawInactive")
        addObserver(self, "mouseDown", "mouseDown")

        UpdateCurrentGlyphView()
Esempio n. 18
0
class switchGlyphDialog(object):

    _title = "switch"
    _padding_top = 8
    _padding = 10
    _button_1 = 30
    _button_2 = 18
    _line_height = 18
    _box_height = 23
    _width = 320
    _height = (_button_1 * 3) + (_padding_top * 2)

    _move_default = 70

    def __init__(self):
        # get fonts
        self.all_fonts = AllFonts()
        if len(self.all_fonts) > 0:
            self.w = FloatingWindow(
                        (self._width,
                        self._height),
                        self._title)
            # move buttons
            p = self._padding
            b1 = self._button_1
            b2 = self._button_2
            box = self._box_height
            x = self._padding
            y = self._padding_top
            x1 = x + b1 - 1
            x2 = x + (b1 * 2) - 2
            # buttons
            self.w._up = SquareButton(
                        (x1, y,
                        b1, b1),
                        unichr(8673),
                        callback=self._up_callback)
            self.w._up_right = SquareButton(
                        (x2 + 8, y,
                        b1 - 8, b1 - 8),
                        unichr(8599),
                        callback=self._up_right_callback,
                        sizeStyle='small')
            y += b1 - 1
            self.w._left = SquareButton(
                        (x, y,
                        b1, b1),
                        unichr(8672),
                        callback=self._left_callback)
            self.w._right = SquareButton(
                        (x2, y,
                        b1, b1),
                        unichr(8674),
                        callback=self._right_callback)
            y += b1 - 1
            self.w._down = SquareButton(
                        (x1, y,
                        b1, b1),
                        unichr(8675),
                        callback=self._down_callback)
            self.w._down_left = SquareButton(
                        (x, y + 8,
                        b1 - 8, b1 - 8),
                        unichr(8601),
                        callback=self._down_left_callback,
                        sizeStyle='small')
            # location
            y = p
            x3 = x2 + b1 + 16
            self.w.box_font = Box(
                        (x3, y,
                        -self._padding,
                        self._box_height))
            self.w.box_font.text = TextBox(
                        (5, 0,
                        -self._padding,
                        -0),
                        '',
                        sizeStyle='small')
            y += self._box_height + self._padding_top
            self.w.box_glyph = Box(
                        (x3, y,
                        -self._padding,
                        self._box_height))
            self.w.box_glyph.text = TextBox(
                        (5, 0,
                        -self._padding,
                        -0),
                        '',
                        sizeStyle='small')
            y += self._box_height + self._padding_top
            self.w.box_layer = Box(
                        (x3, y,
                        -self._padding,
                        self._box_height))
            self.w.box_layer.text = TextBox(
                        (5, 0,
                        -self._padding,
                        -0),
                        '',
                        sizeStyle='small')
            # open
            if self.update():
                self.w.open()
        else:
            print 'please open at least one font first.\n'

    # methods

    def next_glyph(self):
        next = next_glyph(self.font, self.glyph_index)
        try:
            self.glyph_window.setGlyphByName(next)
        except AttributeError:
            self.glyph_window = CurrentGlyphWindow()
            self.glyph_window.setGlyphByName(next)
        self.update()

    def previous_glyph(self):
        prev = previous_glyph(self.font, self.glyph_index)
        try:
            self.glyph_window.setGlyphByName(prev)
        except AttributeError:
            self.glyph_window = CurrentGlyphWindow()
            self.glyph_window.setGlyphByName(prev)
        self.update()

    def layer_down(self):
        try:
            self.glyph_window.layerDown()
        except AttributeError:
            self.glyph_window = CurrentGlyphWindow()
            self.glyph_window.layerDown()
        self.update()

    def layer_up(self):
        try:
            self.glyph_window.layerUp()
        except AttributeError:
            self.glyph_window = CurrentGlyphWindow()
            self.glyph_window.layerUp()
        self.update()

    def _update_text_box(self):
        self.w.box_font.text.set('%s [%s]' % (get_full_name(self.font), self.font_index))
        self.w.box_glyph.text.set('%s [%s]' % (self.glyph.name, self.glyph_index))
        self.w.box_layer.text.set(self.glyph.layerName)

    def update(self):
        self.glyph_window = CurrentGlyphWindow()
        if self.glyph_window is not None:
            self.glyph = CurrentGlyph()
            self.font = self.glyph.getParent()
            self.glyph_index = self.font.glyphOrder.index(self.glyph.name)
            self.font_index = self.all_fonts.index(self.font)
            self._update_text_box()
            return True
        else:
            f = CurrentFont()
            if f is not None:
                self.font = f
                self.font_index = self.all_fonts.index(self.font)
                glyph_names = get_glyphs(f)
                if len(glyph_names) > 0:
                    self.glyph = self.font[glyph_names[0]]
                    self.glyph_index = self.font.glyphOrder.index(self.glyph.name)
                    self.glyph_window = OpenGlyphWindow(self.glyph, newWindow=False)
                    self._update_text_box()
                    return True
                else:
                    print 'please select a glyph first.\n'
                    return False
            else:
                print 'please open a font first.\n'
                return False

    # callbacks

    def _left_callback(self, sender):
        self.previous_glyph()

    def _right_callback(self, sender):
        self.next_glyph()

    def _up_callback(self, sender):
        self.layer_up()

    def _down_callback(self, sender):
        self.layer_down()

    def _up_right_callback(self, sender):
        if len(self.all_fonts) > 1:
            # get next font
            f = CurrentFont()
            i = self.all_fonts.index(f)
            try:
                next_i = i + 1
                next_font = self.all_fonts[next_i]
            except IndexError:
                next_i = 0
                next_font = self.all_fonts[next_i]
            # get glyph
            g_current = CurrentGlyph()
            if g_current is not None:
                if next_font.has_key(g_current.name):
                    next_glyph = next_font[g_current.name]
                else:
                    next_glyph = next_font[next_font.glyphOrder[0]]
                # switch to glyph window
                G = OpenGlyphWindow(next_glyph, newWindow=False)
                # update UI
                self.update()

    def _down_left_callback(self, sender):
        if len(self.all_fonts) > 1:
            # get next font
            f = CurrentFont()
            i = self.all_fonts.index(f)
            try:
                prev_i = i - 1
                prev_font = self.all_fonts[prev_i]
            except IndexError:
                prev_i = -1
                prev_font = self.all_fonts[prev_i]
            # get glyph
            g_current = CurrentGlyph()
            if g_current is not None:
                if prev_font.has_key(g_current.name):
                    prev_glyph = prev_font[g_current.name]
                else:
                    prev_glyph = prev_font[prev_font.glyphOrder[0]]
                # switch to glyph window
                G = OpenGlyphWindow(prev_glyph, newWindow=False)
                # update UI
                self.update()
Esempio n. 19
0
 def openGlyphDiffWindow(self, sender):
     newGlyphName = sender.get()[sender.getSelection()[0]]["Glyph"]
     #print "Goto Glyph:", newGlyphName
     OpenGlyphWindow(glyph=self.font[newGlyphName])
Esempio n. 20
0
 def selectGlyph(self, sender):
     g = self.w.info.get()
     if self.w.info.getSelection() != []:
         gs = self.w.info.getSelection()[0]
         if CurrentFont() != None:
             OpenGlyphWindow(CurrentFont()[g[gs]["Name"]], newWindow=False)
Esempio n. 21
0
 def mouseDown(self, info):
     if info.clickCount() == 2:
         OpenGlyphWindow(self.ui.glyph)
Esempio n. 22
0
    def openFirstGlyph(self):

        glyphName = "A"

        if glyphName in font.keys():
            OpenGlyphWindow(self._font[glyphName])
from mojo.UI import OpenGlyphWindow

g = CurrentGlyph()

for font in AllFonts():
    print(font)
    fontG = font[g.name]
    if fontG is not None:
        OpenGlyphWindow(fontG, newWindow=True)
Esempio n. 24
0
class switchGlyphDialog(hDialog):
    """A dialog to navigate through glyphs, fonts and layers of all open fonts.

    .. image:: imgs/glyph/switch.png

    """

    # methods

    def __init__(self):
        # get fonts
        self.get_fonts()
        if len(self.all_fonts) > 0:
            self.title = "switch"
            self.text_height += 3
            self.square_button -= 4
            self.height = (self.square_button * 3) + (self.padding_y * 2)
            self.width = 320
            self.w = FloatingWindow((self.width, self.height), self.title)
            # move buttons
            x = self.padding_x
            y = self.padding_y
            x1 = x + (self.square_button * 1) - 1
            x2 = x + (self.square_button * 2) - 2
            self.w._up = SquareButton(
                (x1, y, self.square_button, self.square_button),
                chr(8673),
                callback=self._up_callback)
            self.w._up_right = SquareButton(
                (x2 + 8, y, self.square_button - 8, self.square_button - 8),
                chr(8599),
                callback=self._up_right_callback,
                sizeStyle=self.size_style)
            y += self.square_button - 1
            self.w._left = SquareButton(
                (x, y, self.square_button, self.square_button),
                chr(8672),
                callback=self._left_callback)
            self.w._right = SquareButton(
                (x2, y, self.square_button, self.square_button),
                chr(8674),
                callback=self._right_callback)
            y += self.square_button - 1
            self.w._down_left = SquareButton(
                (x, y + 8, self.square_button - 8, self.square_button - 8),
                chr(8601),
                callback=self._down_left_callback,
                sizeStyle=self.size_style)
            self.w._down = SquareButton(
                (x1, y, self.square_button, self.square_button),
                chr(8675),
                callback=self._down_callback)
            # location
            y = self.padding_y
            x3 = x2 + self.square_button + 16
            self.w.box_font = Box((x3, y, -self.padding_x, self.text_height))
            self.w.box_font.text = TextBox((5, 0, -self.padding_x, -0),
                                           '',
                                           sizeStyle=self.size_style)
            y += self.text_height + self.padding_y
            self.w.box_glyph = Box((x3, y, -self.padding_x, self.text_height))
            self.w.box_glyph.text = TextBox((5, 0, -self.padding_x, -0),
                                            '',
                                            sizeStyle=self.size_style)
            y += self.text_height + self.padding_y
            self.w.box_layer = Box((x3, y, -self.padding_x, self.text_height))
            self.w.box_layer.text = TextBox((5, 0, -self.padding_x, -0),
                                            '',
                                            sizeStyle=self.size_style)
            # open
            if self.update():
                # bind
                # self.w.bind("became key", self.update_callback)
                self.w.bind("close", self.on_close_window)
                # observers
                addObserver(self, "update_callback", "newFontDidOpen")
                addObserver(self, "update_callback", "fontDidOpen")
                addObserver(self, "update_callback", "fontDidClose")
                # open window
                self.w.open()
        else:
            print(no_font_open)

    # methods

    def get_fonts(self):
        self.all_fonts = AllFonts()

    def next_glyph(self):
        next = next_glyph(self.font, self.glyph_index)
        try:
            self.glyph_window.setGlyphByName(next)
        except AttributeError:
            self.glyph_window = CurrentGlyphWindow()
            self.glyph_window.setGlyphByName(next)
        self.update()

    def previous_glyph(self):
        prev = previous_glyph(self.font, self.glyph_index)
        try:
            self.glyph_window.setGlyphByName(prev)
        except AttributeError:
            self.glyph_window = CurrentGlyphWindow()
            self.glyph_window.setGlyphByName(prev)
        self.update()

    def layer_down(self):
        try:
            self.glyph_window.layerDown()
        except AttributeError:
            self.glyph_window = CurrentGlyphWindow()
            self.glyph_window.layerDown()
        self.update()

    def layer_up(self):
        try:
            self.glyph_window.layerUp()
        except AttributeError:
            self.glyph_window = CurrentGlyphWindow()
            self.glyph_window.layerUp()
        self.update()

    def _update_text_box(self):
        self.w.box_font.text.set(get_full_name(self.font))
        self.w.box_glyph.text.set(self.glyph.name)
        self.w.box_layer.text.set(self.glyph.layerName)

    def update(self):
        self.glyph_window = CurrentGlyphWindow()
        if self.glyph_window is not None:
            self.glyph = CurrentGlyph()
            self.font = self.glyph.getParent()
            self.glyph_index = self.font.glyphOrder.index(self.glyph.name)
            self.font_index = self.all_fonts.index(self.font)
            self._update_text_box()
            return True
        else:
            f = CurrentFont()
            if f is not None:
                self.font = f
                self.font_index = self.all_fonts.index(self.font)
                glyph_names = get_glyphs(f)
                if len(glyph_names) > 0:
                    self.glyph = self.font[glyph_names[0]]
                    self.glyph_index = self.font.glyphOrder.index(
                        self.glyph.name)
                    self.glyph_window = OpenGlyphWindow(self.glyph,
                                                        newWindow=False)
                    self._update_text_box()
                    return True
                else:
                    print(no_glyph_selected)
                    return False
            else:
                print(no_font_open)
                return False

    # callbacks

    def _left_callback(self, sender):
        self.previous_glyph()

    def _right_callback(self, sender):
        self.next_glyph()

    def _up_callback(self, sender):
        self.layer_up()

    def _down_callback(self, sender):
        self.layer_down()

    def _up_right_callback(self, sender):
        if len(self.all_fonts) > 1:
            # get next font
            f = CurrentFont()
            i = self.all_fonts.index(f)
            try:
                next_i = i + 1
                next_font = self.all_fonts[next_i]
            except IndexError:
                next_i = 0
                next_font = self.all_fonts[next_i]
            # get glyph
            g_current = CurrentGlyph()
            if g_current is not None:
                if g_current.name in next_font:
                    next_glyph = next_font[g_current.name]
                else:
                    next_glyph = next_font[next_font.glyphOrder[0]]
                # switch to glyph window
                G = OpenGlyphWindow(next_glyph, newWindow=False)
                # update UI
                self.update()

    def _down_left_callback(self, sender):
        if len(self.all_fonts) > 1:
            # get next font
            f = CurrentFont()
            i = self.all_fonts.index(f)
            try:
                prev_i = i - 1
                prev_font = self.all_fonts[prev_i]
            except IndexError:
                prev_i = -1
                prev_font = self.all_fonts[prev_i]
            # get glyph
            g_current = CurrentGlyph()
            if g_current is not None:
                if g_current.name in prev_font:
                    prev_glyph = prev_font[g_current.name]
                else:
                    prev_glyph = prev_font[prev_font.glyphOrder[0]]
                # switch to glyph window
                G = OpenGlyphWindow(prev_glyph, newWindow=False)
                # update UI
                self.update()

    def update_callback(self, sender):
        self.get_fonts()
        self.update()

    def on_close_window(self, sender):
        removeObserver(self, "newFontDidOpen")
        removeObserver(self, "fontDidOpen")
        removeObserver(self, "fontDidClose")
Esempio n. 25
0
class switchGlyphDialog(hDialog):

    """A dialog to navigate through glyphs, fonts and layers of all open fonts.

    .. image:: imgs/glyph/switch.png

    """

    # methods

    def __init__(self):
        # get fonts
        self.get_fonts()
        if len(self.all_fonts) > 0:
            self.title = "switch"
            self.text_height += 3
            self.square_button -= 4
            self.height = (self.square_button * 3) + (self.padding_y * 2)
            self.width = 320
            self.w = HUDFloatingWindow((self.width, self.height), self.title)
            # move buttons
            x = self.padding_x
            y = self.padding_y
            x1 = x + (self.square_button * 1) - 1
            x2 = x + (self.square_button * 2) - 2
            self.w._up = SquareButton(
                        (x1, y,
                        self.square_button,
                        self.square_button),
                        unichr(8673),
                        callback=self._up_callback)
            self.w._up_right = SquareButton(
                        (x2 + 8, y,
                        self.square_button - 8,
                        self.square_button - 8),
                        unichr(8599),
                        callback=self._up_right_callback,
                        sizeStyle=self.size_style)
            y += self.square_button - 1
            self.w._left = SquareButton(
                        (x, y,
                        self.square_button,
                        self.square_button),
                        unichr(8672),
                        callback=self._left_callback)
            self.w._right = SquareButton(
                        (x2, y,
                        self.square_button,
                        self.square_button),
                        unichr(8674),
                        callback=self._right_callback)
            y += self.square_button - 1
            self.w._down_left = SquareButton(
                        (x, y + 8,
                        self.square_button - 8,
                        self.square_button - 8),
                        unichr(8601),
                        callback=self._down_left_callback,
                        sizeStyle=self.size_style)
            self.w._down = SquareButton(
                        (x1, y,
                        self.square_button,
                        self.square_button),
                        unichr(8675),
                        callback=self._down_callback)
            # location
            y = self.padding_y
            x3 = x2 + self.square_button + 16
            self.w.box_font = Box(
                        (x3, y,
                        -self.padding_x,
                        self.text_height))
            self.w.box_font.text = TextBox(
                        (5, 0,
                        -self.padding_x,
                        -0),
                        '',
                        sizeStyle=self.size_style)
            y += self.text_height + self.padding_y
            self.w.box_glyph = Box(
                        (x3, y,
                        -self.padding_x,
                        self.text_height))
            self.w.box_glyph.text = TextBox(
                        (5, 0,
                        -self.padding_x,
                        -0),
                        '',
                        sizeStyle=self.size_style)
            y += self.text_height + self.padding_y
            self.w.box_layer = Box(
                        (x3, y,
                        -self.padding_x,
                        self.text_height))
            self.w.box_layer.text = TextBox(
                        (5, 0,
                        -self.padding_x,
                        -0),
                        '',
                        sizeStyle=self.size_style)
            # open
            if self.update():
                # bind
                # self.w.bind("became key", self.update_callback)
                self.w.bind("close", self.on_close_window)
                # observers
                addObserver(self, "update_callback", "newFontDidOpen")
                addObserver(self, "update_callback", "fontDidOpen")
                addObserver(self, "update_callback", "fontDidClose")
                # open window
                self.w.open()
        else:
            print no_font_open

    # methods

    def get_fonts(self):
        self.all_fonts = AllFonts()

    def next_glyph(self):
        next = next_glyph(self.font, self.glyph_index)
        try:
            self.glyph_window.setGlyphByName(next)
        except AttributeError:
            self.glyph_window = CurrentGlyphWindow()
            self.glyph_window.setGlyphByName(next)
        self.update()

    def previous_glyph(self):
        prev = previous_glyph(self.font, self.glyph_index)
        try:
            self.glyph_window.setGlyphByName(prev)
        except AttributeError:
            self.glyph_window = CurrentGlyphWindow()
            self.glyph_window.setGlyphByName(prev)
        self.update()

    def layer_down(self):
        try:
            self.glyph_window.layerDown()
        except AttributeError:
            self.glyph_window = CurrentGlyphWindow()
            self.glyph_window.layerDown()
        self.update()

    def layer_up(self):
        try:
            self.glyph_window.layerUp()
        except AttributeError:
            self.glyph_window = CurrentGlyphWindow()
            self.glyph_window.layerUp()
        self.update()

    def _update_text_box(self):
        self.w.box_font.text.set(get_full_name(self.font))
        self.w.box_glyph.text.set(self.glyph.name)
        self.w.box_layer.text.set(self.glyph.layerName)

    def update(self):
        self.glyph_window = CurrentGlyphWindow()
        if self.glyph_window is not None:
            self.glyph = CurrentGlyph()
            self.font = self.glyph.getParent()
            self.glyph_index = self.font.glyphOrder.index(self.glyph.name)
            self.font_index = self.all_fonts.index(self.font)
            self._update_text_box()
            return True
        else:
            f = CurrentFont()
            if f is not None:
                self.font = f
                self.font_index = self.all_fonts.index(self.font)
                glyph_names = get_glyphs(f)
                if len(glyph_names) > 0:
                    self.glyph = self.font[glyph_names[0]]
                    self.glyph_index = self.font.glyphOrder.index(self.glyph.name)
                    self.glyph_window = OpenGlyphWindow(self.glyph, newWindow=False)
                    self._update_text_box()
                    return True
                else:
                    print no_glyph_selected
                    return False
            else:
                print no_font_open
                return False

    # callbacks

    def _left_callback(self, sender):
        self.previous_glyph()

    def _right_callback(self, sender):
        self.next_glyph()

    def _up_callback(self, sender):
        self.layer_up()

    def _down_callback(self, sender):
        self.layer_down()

    def _up_right_callback(self, sender):
        if len(self.all_fonts) > 1:
            # get next font
            f = CurrentFont()
            i = self.all_fonts.index(f)
            try:
                next_i = i + 1
                next_font = self.all_fonts[next_i]
            except IndexError:
                next_i = 0
                next_font = self.all_fonts[next_i]
            # get glyph
            g_current = CurrentGlyph()
            if g_current is not None:
                if next_font.has_key(g_current.name):
                    next_glyph = next_font[g_current.name]
                else:
                    next_glyph = next_font[next_font.glyphOrder[0]]
                # switch to glyph window
                G = OpenGlyphWindow(next_glyph, newWindow=False)
                # update UI
                self.update()

    def _down_left_callback(self, sender):
        if len(self.all_fonts) > 1:
            # get next font
            f = CurrentFont()
            i = self.all_fonts.index(f)
            try:
                prev_i = i - 1
                prev_font = self.all_fonts[prev_i]
            except IndexError:
                prev_i = -1
                prev_font = self.all_fonts[prev_i]
            # get glyph
            g_current = CurrentGlyph()
            if g_current is not None:
                if prev_font.has_key(g_current.name):
                    prev_glyph = prev_font[g_current.name]
                else:
                    prev_glyph = prev_font[prev_font.glyphOrder[0]]
                # switch to glyph window
                G = OpenGlyphWindow(prev_glyph, newWindow=False)
                # update UI
                self.update()

    def update_callback(self, sender):
        self.get_fonts()
        self.update()

    def on_close_window(self, sender):
            removeObserver(self, "newFontDidOpen")
            removeObserver(self, "fontDidOpen")
            removeObserver(self, "fontDidClose")
Esempio n. 26
0
 def mouseDown(self, info):
     if info['clickCount'] == 2:
         x, y = info['point']
         tx, ty = self.selectedComponentOffset
         if self.oldGlyph.pointInside((x+tx, y+ty)):
             OpenGlyphWindow(self.oldGlyph)