def maya_changes(self): table = self.tableWidget old_set_list = self.set_list new_set_list = engine.set_list() changed_sets = self.returnNotMatches(new_set_list, old_set_list) new_sets = changed_sets[0][::-1] #reversed order deleted_sets = changed_sets[1] # print 'DELETED >>>>>', deleted_sets # print 'NEW>>>>', new_sets if deleted_sets: [self.delete_set(q_set) for q_set in deleted_sets if deleted_sets] if new_sets: [self.set_list.append(x) for x in new_sets] self.build_tab(table) [self.update_value(q_set) for q_set in engine.set_list()]
def delete_empty(self): [ self.delete_set(s) for s in engine.set_list() if engine.set_size(s) == 0 ] self.del_flag = 0 self.delete_all_flag = 1
def rename(self, edit_row, edit_col): table = self.tableWidget # ------------------fix row height change bug table.setRowHeight(edit_row, self.tab_row_height) # ---------rename only if name was changed,not value if edit_col != 1: # rename only if there was a change in the cell text, not the cell position if set(self.tab_items()) != set(self.tab_state): # get name input name_input = table.item(edit_row, 0).text() #check the name validity, fix it if needed and write fixed name into the tab cell new_name = self.make_valid(name_input) table.blockSignals(True) if name_input != new_name: table.item(edit_row, edit_col).setText(new_name) table.blockSignals(False) #rename the set engine.set_rename(self.recent_set, new_name) #update data self.set_list = engine.set_list() self.recent_set = table.currentItem().text() # self.set_button_text(self.b_select,new_name) self.rename_flag = 1
def refresh_list(self): table = self.tableWidget self.set_list = engine.set_list() self.build_tab(table)
def delete_all(self): [self.delete_set(s) for s in engine.set_list()] self.del_flag = 0 self.delete_all_flag = 1
def clear_all(self): [self.clear_set(s) for s in engine.set_list()] self.clear_all_flag = 1
def sets_changed(self): old_set_list = self.set_list new_set_list = engine.set_list() return old_set_list != new_set_list
def update(self): self.tab_state = self.tab_items() #----------------------------------------------if no changes in sets stop here if self.rename_flag == 1: print 'Set renamed' self.scene_items = engine.scene_items() self.rename_flag = 0 return #---------------------------------------------if renamed stop here if self.new_flag == 1: print 'new Set created' self.scene_items = engine.scene_items() self.new_flag = 0 return #---------------------------------------------if new set created stop here if self.del_flag == 1: self.del_flag = 0 self.scene_items = engine.scene_items() print 'Set deleted' return if self.delete_all_flag == 1: self.scene_items = engine.scene_items() self.delete_all_flag = 0 print ' Batch delete ' return if self.clear_all_flag == 1: self.clear_all_flag = 0 self.scene_items = engine.scene_items() print ' Batch clear ' return if self.cleared_sets: for q_set in self.cleared_sets: if not engine.set_exists(q_set): self.cleared_sets.remove(q_set) elif engine.set_size(q_set) == 0: pass else: self.update_value(q_set) self.cleared_sets.remove(q_set) #print 'set is updated' if not self.scene_changed(): return #----------------------------------------------if no changes in scene stop here if not self.sets_changed(): print 'new objects in scene, same sets though, updating table....' [self.update_value(q_set) for q_set in engine.set_list()] self.scene_items = engine.scene_items() return #----------------------------------------- if sets deleted in plugin stop here print ' sets changed in Maya' self.maya_changes() self.del_flag = 0 self.scene_items = engine.scene_items()
def setupUi(self, Sets): super(self.__class__, self).setupUi(Sets) self.setObjectName("my_set_ui") self.setAttribute(QtCore.Qt.WA_DeleteOnClose) # mylabel= QtWidgets.QLabel('BLA') # self.tlayout.addWidget(mylabel) # spacerItem = QtWidgets.QSpacerItem(700, 2, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) # self.tlayout.addItem(spacerItem) self.tlayout.addLayout(self.verticalLayout) #-------------------------------------Assign icons icon_buttons = { self.b_remove: 'remove.png', self.b_clear: 'clear.png', self.b_add: 'add.png', self.b_color: 'color.png', self.b_menu: 'menu.png', self.b_delete: 'delete.png' } {self.add_icon(k, v) for k, v in icon_buttons.items()} #------------------------------------------Set tool tips self.b_add.setToolTip('Add to set') self.b_remove.setToolTip('Remove from set') self.b_new.setToolTip('Create new set') self.b_clear.setToolTip('Clear selected set') self.b_delete.setToolTip('Delete') self.b_color.setToolTip('Assign color') self.b_menu.setToolTip('Extra functions') #---------------------------------------Button functions self.b_new.clicked.connect(self.new_set) self.b_select.clicked.connect( lambda: engine.select_set(self.recent_set)) self.b_add.clicked.connect(lambda: self.add_to(self.recent_set)) self.b_remove.clicked.connect( lambda: self.remove_from(self.recent_set)) self.b_clear.clicked.connect(lambda: self.clear_set(self.recent_set)) self.b_delete.clicked.connect(lambda: self.delete_set(self.recent_set)) self.b_menu.released.connect(self.menu_build) self.b_color.released.connect(self.color_menu) table = self.tableWidget table.itemSelectionChanged.connect(self.set_current) #---------------------------------------Assign right click menu table.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) # table.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection) table.setEditTriggers(QtWidgets.QAbstractItemView.DoubleClicked) table.customContextMenuRequested.connect(self.menu_build) #-----------------------------------------Rename Set function QtCore.QObject.connect(table, QtCore.SIGNAL("cellChanged(int, int)"), self.rename) #-----------------------------------------Table Settings # # Enable drag & drop ordering of items. table.setDragEnabled(False) # table.setAcceptDrops(True) # table.viewport().setAcceptDrops(True) # table.setDragDropOverwriteMode(False) # table.setDropIndicatorShown(True) # table.setDragDropMode(QtWidgets.QAbstractItemView.InternalMove) table.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection) table.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows) #table.setColumnWidth(0, 140) table.setColumnWidth(1, 40) header = table.horizontalHeader() header.setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch) header.setSectionResizeMode(1, QtWidgets.QHeaderView.Fixed) #header.setStretchLastSection(True) #-------------------Remove blue Focus Border table.setFocusPolicy(QtCore.Qt.NoFocus) self.set_list = engine.set_list() self.build_tab(table)