コード例 #1
0
    def contextMenuEvent(self, event):
        # - Init
        self.tab_groupKern.menu = QtGui.QMenu(self)
        self.tab_groupKern.menu.setTitle('Class Actions:')

        # - Build menus
        self.tab_groupKern.menu.addMenu(self.menu_class)
        self.tab_groupKern.menu.addSeparator()
        self.tab_groupKern.menu.addMenu(self.menu_type)
        self.tab_groupKern.menu.addSeparator()
        self.tab_groupKern.menu.addMenu(self.menu_memb)

        self.tab_groupKern.menu.popup(QtGui.QCursor.pos())
コード例 #2
0
    def __init__(self, parentWidget):
        super(WKernGroups, self).__init__()

        # - Init
        self.upper_widget = parentWidget
        self.active_font = pFont()
        self.kern_group_data = {}  #self.active_font.kerning_groups_to_dict()

        # - Interface
        lbl_name = QtGui.QLabel('Kerning classes')
        lbl_act = QtGui.QLabel('Actions (selected items):')
        lbl_name.setMaximumHeight(20)
        lbl_act.setMaximumHeight(20)

        self.cmb_layer = QtGui.QComboBox()
        self.cmb_layer.addItems(self.active_font.masters())
        self.cmb_layer.currentIndexChanged.connect(
            lambda: self.update_data(self.kern_group_data))

        self.btn_apply = QtGui.QPushButton('Apply changes')
        self.btn_write = QtGui.QPushButton('Write changes')
        self.btn_reset = QtGui.QPushButton('Clear font classes')

        self.btn_apply.clicked.connect(lambda: self.apply_changes(False))
        self.btn_write.clicked.connect(lambda: self.apply_changes(True))
        self.btn_reset.clicked.connect(lambda: self.reset_classes())

        self.tab_groupKern = GroupTableView()

        # - Menus & Actions
        # -- Main Database actions
        self.menu_data = QtGui.QMenu('Class Data', self)
        act_data_open = QtGui.QAction('Open TypeRig Classes (JSON)', self)
        act_data_save = QtGui.QAction('Save TypeRig Classes (JSON)', self)
        act_data_import = QtGui.QAction('Import FontLab Classes (JSON)', self)
        act_data_export = QtGui.QAction('Export FontLab Classes (JSON)', self)
        act_data_import_font = QtGui.QAction('Import Classes from Font', self)
        act_data_build_composite = QtGui.QAction(
            'Build Classes from References', self)
        act_data_reset = QtGui.QAction('Reset Font Class Data', self)
        act_data_write = QtGui.QAction('Write class data to Font', self)

        self.menu_data.addAction(act_data_open)
        self.menu_data.addAction(act_data_save)
        self.menu_data.addSeparator()
        self.menu_data.addAction(act_data_import)
        self.menu_data.addAction(act_data_export)
        self.menu_data.addSeparator()
        self.menu_data.addAction(act_data_import_font)
        self.menu_data.addAction(act_data_build_composite)
        self.menu_data.addSeparator()
        self.menu_data.addAction(act_data_reset)
        self.menu_data.addAction(act_data_write)

        act_data_open.triggered.connect(lambda: self.file_load_groups(True))
        act_data_save.triggered.connect(lambda: self.file_save_groups(True))
        act_data_import.triggered.connect(lambda: self.file_load_groups(False))
        #act_data_export.triggered.connect()
        act_data_import_font.triggered.connect(lambda: self.from_font())
        act_data_build_composite.triggered.connect(
            lambda: self.from_composites())
        act_data_reset.triggered.connect(lambda: self.reset_classes())
        act_data_write.triggered.connect(lambda: self.apply_changes(True))

        # -- Main Class actions
        self.menu_class = QtGui.QMenu('Class Management', self)
        act_class_add = QtGui.QAction('Add new class', self)
        act_class_find = QtGui.QAction('Find and replace class names', self)
        act_class_copy = QtGui.QAction('Duplicate classes', self)
        act_class_merge = QtGui.QAction('Merge classes to new', self)
        act_class_mdel = QtGui.QAction('Merge and remove classes', self)
        act_class_del = QtGui.QAction('Remove classes', self)

        self.menu_class.addAction(act_class_add)
        self.menu_class.addAction(act_class_find)
        self.menu_class.addAction(act_class_copy)
        self.menu_class.addAction(act_class_merge)
        self.menu_class.addAction(act_class_mdel)
        self.menu_class.addAction(act_class_del)

        act_class_add.triggered.connect(lambda: self.class_add_new())
        act_class_find.triggered.connect(lambda: self.class_find_replace())
        act_class_copy.triggered.connect(lambda: self.class_copy())
        act_class_merge.triggered.connect(lambda: self.class_merge(False))
        act_class_mdel.triggered.connect(lambda: self.class_merge(True))
        act_class_del.triggered.connect(lambda: self.class_del())

        # -- Change class type
        self.menu_type = QtGui.QMenu('Class Type', self)
        act_type_Left = QtGui.QAction('Set KernLeft (1st)', self)
        act_type_Right = QtGui.QAction('Set KernRight (2nd)', self)
        act_type_Both = QtGui.QAction('Set KernBothSide (1st and 2nd)', self)
        act_type_toggle = QtGui.QAction('Toggle class type', self)

        act_type_Left.triggered.connect(lambda: self.set_type('KernLeft'))
        act_type_Right.triggered.connect(lambda: self.set_type('KernRight'))
        act_type_Both.triggered.connect(lambda: self.set_type('KernBothSide'))
        act_type_toggle.triggered.connect(lambda: self.toggle_type())

        self.menu_type.addAction(act_type_Left)
        self.menu_type.addAction(act_type_Right)
        self.menu_type.addAction(act_type_Both)
        self.menu_type.addAction(act_type_toggle)

        # -- Modify Members
        self.menu_memb = QtGui.QMenu('Class Members', self)
        act_memb_sel = QtGui.QAction('Select Glyphs', self)
        act_memb_clean = QtGui.QAction('Cleanup', self)
        act_memb_upper = QtGui.QAction('Members to uppercase', self)
        act_memb_lower = QtGui.QAction('Members to lowercase', self)
        act_memb_strip = QtGui.QAction('Strip member suffixes', self)
        act_memb_suff = QtGui.QAction('Add suffix to members', self)
        act_memb_addglyphs = QtGui.QAction('Selected glyphs to members', self)

        act_memb_sel.triggered.connect(lambda: self.memb_select())
        act_memb_clean.triggered.connect(lambda: self.memb_cleanup())
        act_memb_upper.triggered.connect(lambda: self.memb_change_case(True))
        act_memb_lower.triggered.connect(lambda: self.memb_change_case(False))
        act_memb_strip.triggered.connect(lambda: self.memb_stripSuffix())
        act_memb_suff.triggered.connect(lambda: self.memb_addSuffix())
        act_memb_addglyphs.triggered.connect(lambda: self.memb_addGlyphs())

        self.menu_memb.addAction(act_memb_sel)
        self.menu_memb.addAction(act_memb_clean)
        self.menu_memb.addAction(act_memb_upper)
        self.menu_memb.addAction(act_memb_lower)
        self.menu_memb.addAction(act_memb_strip)
        self.menu_memb.addAction(act_memb_suff)
        self.menu_memb.addAction(act_memb_addglyphs)

        # - Table auto preview selection
        self.chk_preview = QtGui.QCheckBox('Auto select/preview class.')
        self.tab_groupKern.selectionModel().selectionChanged.connect(
            lambda: self.auto_preview())

        # - Build
        self.lay_grid = QtGui.QGridLayout()
        self.lay_grid.addWidget(lbl_name, 0, 0, 1, 42)
        self.lay_grid.addWidget(QtGui.QLabel('Master:'), 0, 40, 1, 2)
        self.lay_grid.addWidget(self.cmb_layer, 0, 42, 1, 6)
        self.lay_grid.addWidget(self.tab_groupKern, 1, 0, 9, 42)
        self.lay_grid.addWidget(self.chk_preview, 2, 42, 1, 6)
        self.lay_grid.addWidget(self.btn_apply, 1, 42, 1, 6)
        self.lay_grid.addWidget(self.btn_reset, 8, 42, 1, 6)
        self.lay_grid.addWidget(self.btn_write, 9, 42, 1, 6)

        for i in range(1, 8):
            self.lay_grid.setRowStretch(i, 2)

        self.setLayout(self.lay_grid)