def __init__(self, parent=None): super(RecentlyUsedSymbolWidget, self).__init__(parent) self.layout = QGridLayout() self.color = QColor(Qt.white) self._synchronizer = SymbolSynchronizer() self.recentSymbolsDict = {} self.widgetToSymbol = {} self.setMinimumHeight(40) self.setMaximumHeight(40) # initialize to 0 self.num_recent_symbols = 0 labelWidget = QLabel("None") self.layout.addWidget(labelWidget, 0, 0, Qt.AlignVCenter) self.recentSymbols = [labelWidget] self.setLayout(self.layout)
def initialize_symbol_widget(self, knittingSymbols): """ Proxy for adding all the knitting symbols to the symbolWidget and connecting it to the symbol changed slot. NOTE: Unfortunately, the order of the connections below matters. Connect the symbolCategoryChooser only after it has been fully set up. Otherwise we get spurious selector widget switches until the chooser has established the correct order. """ symbolTracker = SymbolSynchronizer() self.connect(self.canvas, SIGNAL("activate_symbol"), self.activeSymbolWidget.active_symbol_changed) self.connect( self.canvas, SIGNAL("unactivate_symbol"), partial(self.activeSymbolWidget.active_symbol_changed, None)) self.connect(self.canvas, SIGNAL("activate_symbol"), self.recentlyUsedSymbolWidget.insert_new_symbol) self.connect( self.canvas, SIGNAL("unactivate_symbol"), partial(self.recentlyUsedSymbolWidget.insert_new_symbol, None)) self.connect(self.canvas, SIGNAL("activate_symbol"), self.set_project_dirty) self.connect(self.canvas, SIGNAL("unactivate_symbol"), self.set_project_dirty) # connection between clear button and the list of # recently used symbols self.connect(self.clearFrequentlyUsedSymbolsButton, SIGNAL("clicked()"), self.recentlyUsedSymbolWidget.clear) # the connection between canvas and symbolTracker has # to be bi-directional so the canvas can properly # undo/redo selections self.connect(symbolTracker, SIGNAL("synchronized_object_changed"), self.canvas.set_active_symbol) self.connect(self.canvas, SIGNAL("activate_symbol"), symbolTracker.select_plain) self.connect(self.canvas, SIGNAL("unactivate_symbol"), symbolTracker.unselect) (self.selectedSymbol, self.symbolSelector, self.symbolSelectorWidgets) = \ generate_symbolWidgets(knittingSymbols, self.symbolCategoryChooser, self.symbolSelectorLayout, symbolTracker) self.connect(self.symbolCategoryChooser, SIGNAL("currentIndexChanged(QString)"), self.update_symbol_widget) # this makes sure that the currently active symbol is unselected # when the users chooses a new category self.connect(self.symbolCategoryChooser, SIGNAL("currentIndexChanged(QString)"), partial(self.canvas.set_active_symbol, None)) # catch signals from custom symbol dialog in case a symbol # changed self.connect( self.manageSymbolsDialog, SIGNAL("symbol_added"), partial(self.refresh_symbol_widget_after_addition, symbolTracker)) self.connect( self.manageSymbolsDialog, SIGNAL("symbol_updated"), partial(self.refresh_symbol_widget_after_update, symbolTracker)) self.connect( self.manageSymbolsDialog, SIGNAL("symbol_deleted"), partial(self.refresh_symbol_widget_after_deletion, symbolTracker))