def __init__(self, corpus): super().__init__() self.corpus = corpus self.setContentsMargins(0, 0, 0, 0) self.positive = True self.textFont = 'normal' self.styleSheetString = 'QPushButton{{font: {}}}' style = self.styleSheetString.format(self.textFont) self.setStyleSheet(style) self.default = 'All dates' self.setText(self.default) self.setFixedWidth(250) self.menu = QMenu() self.options = sorted( list({str(sign.lastUpdated) for sign in self.corpus})) for option in self.options: if not option: option = '(empty)' date = QAction(option, self, checkable=True, triggered=self.updateText) date.setChecked(True) self.menu.addAction(date) self.menu.addSeparator() selectAllAction = QAction('Select all dates', self, checkable=False, triggered=self.selectAll) self.menu.addAction(selectAllAction) deselectAllAction = QAction('Deselect all dates', self, checkable=False, triggered=self.deselectAll) self.menu.addAction(deselectAllAction) self.menu.addSeparator() self.negAction = QAction('Set negative', self, checkable=True, triggered=self.setNeg) self.menu.addAction(self.negAction) self.setMenu(self.menu)
def makeMenu(self): self.popMenu = QMenu(self) self.changeEstimateAct = QAction('Flagged as estimate', self, triggered=self.changeEstimate, checkable=True) self.notEstimateAct = QAction('NOT flagged as estimate', self, triggered=self.notEstimate, checkable=True) self.changeUncertaintyAct = QAction('Flagged as uncertain', self, triggered=self.changeUncertainty, checkable=True) self.notUncertaintyAct = QAction('NOT flagged as uncertain', self, triggered=self.notUncertainty, checkable=True) self.popMenu.addAction(self.changeEstimateAct) self.popMenu.addAction(self.notEstimateAct) self.popMenu.addSeparator() self.popMenu.addAction(self.changeUncertaintyAct) self.popMenu.addAction(self.notUncertaintyAct)
def makeMenu(self, text): self.setContextMenuPolicy(Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.showContextMenu) self.popMenu = QMenu(self) if 'Add' in text: function = self.addToFavourites elif 'Remove' in text: function = self.removeFromFavourites action = QAction(text, self, triggered=function) self.popMenu.addAction(action)
def makeMenu(self, table, text, function): table.setContextMenuPolicy(Qt.CustomContextMenu) table.customContextMenuRequested.connect(self.showContextMenu) table.popMenu = QMenu(self) action = QAction(text, self, triggered=function) table.popMenu.addAction(action)
def makeMenu(self): self.popMenu = QMenu(self) self.removeAct = QAction('Remove', self, triggered=self.removeSelectedItem, checkable=False) self.popMenu.addAction(self.removeAct)
class LastUpdateSlot(QPushButton): def __init__(self, corpus): super().__init__() self.corpus = corpus self.setContentsMargins(0, 0, 0, 0) self.positive = True self.textFont = 'normal' self.styleSheetString = 'QPushButton{{font: {}}}' style = self.styleSheetString.format(self.textFont) self.setStyleSheet(style) self.default = 'All dates' self.setText(self.default) self.setFixedWidth(250) self.menu = QMenu() self.options = sorted( list({str(sign.lastUpdated) for sign in self.corpus})) for option in self.options: if not option: option = '(empty)' date = QAction(option, self, checkable=True, triggered=self.updateText) date.setChecked(True) self.menu.addAction(date) self.menu.addSeparator() selectAllAction = QAction('Select all dates', self, checkable=False, triggered=self.selectAll) self.menu.addAction(selectAllAction) deselectAllAction = QAction('Deselect all dates', self, checkable=False, triggered=self.deselectAll) self.menu.addAction(deselectAllAction) self.menu.addSeparator() self.negAction = QAction('Set negative', self, checkable=True, triggered=self.setNeg) self.menu.addAction(self.negAction) self.setMenu(self.menu) def getSelectedDates(self): selectedDates = list() for act in self.menu.actions()[:-3]: if act.isChecked(): selectedDates.append(act.text()) return selectedDates def updateText(self): selectedDates = self.getSelectedDates() if selectedDates: if selectedDates == self.options: self.setText(self.default) else: first = selectedDates[0] if len(selectedDates) == 1: self.setText(first) else: self.setText(first + '+') else: self.setText('Please select at least one date') def deselectAll(self): for act in self.menu.actions()[:-3]: act.setChecked(False) self.updateText() def selectAll(self): for act in self.menu.actions()[:-3]: act.setChecked(True) self.updateText() def setNeg(self): if self.negAction.isChecked(): self.positive = False self.textFont = 'italic' else: self.positive = True self.textFont = 'normal' style = self.styleSheetString.format(self.textFont) self.setStyleSheet(style) def value(self): options = set() for d in self.options: year, month, day = tuple(d.split(sep='-')) options.add(date(int(year), int(month), int(day))) #print('options:') #pprint(options) selected = set() for d in self.getSelectedDates(): year, month, day = tuple(d.split(sep='-')) selected.add(date(int(year), int(month), int(day))) #print('selected:') #pprint(selected) #selected = {'' if date == '(empty)' else date for date in self.getSelectedDates()} if self.positive: return selected else: return options - selected
class CoderSlot(QPushButton): def __init__(self, corpus): super().__init__() self.corpus = corpus self.setContentsMargins(0, 0, 0, 0) self.positive = True self.textFont = 'normal' self.styleSheetString = 'QPushButton{{font: {}}}' style = self.styleSheetString.format(self.textFont) self.setStyleSheet(style) self.default = 'All coders' self.setText(self.default) self.setFixedWidth(250) self.menu = QMenu() self.options = sorted(list({sign.coder for sign in self.corpus})) for option in self.options: if not option: option = '(empty)' coder = QAction(option, self, checkable=True, triggered=self.updateText) coder.setChecked(True) self.menu.addAction(coder) self.menu.addSeparator() selectAllAction = QAction('Select all coders', self, checkable=False, triggered=self.selectAll) self.menu.addAction(selectAllAction) deselectAllAction = QAction('Deselect all coders', self, checkable=False, triggered=self.deselectAll) self.menu.addAction(deselectAllAction) self.menu.addSeparator() self.negAction = QAction('Set negative', self, checkable=True, triggered=self.setNeg) self.menu.addAction(self.negAction) self.setMenu(self.menu) def getSelectedCoders(self): selectedCoders = list() for act in self.menu.actions()[:-3]: if act.isChecked(): selectedCoders.append(act.text()) return selectedCoders def updateText(self): selectedCoders = self.getSelectedCoders() if selectedCoders: if selectedCoders == self.options: self.setText(self.default) else: first = selectedCoders[0] if len(selectedCoders) == 1: self.setText(first) else: self.setText(first + '+') else: self.setText('Please select at least one coder') def deselectAll(self): for act in self.menu.actions()[:-3]: act.setChecked(False) self.updateText() def selectAll(self): for act in self.menu.actions()[:-3]: act.setChecked(True) self.updateText() def setNeg(self): if self.negAction.isChecked(): self.positive = False self.textFont = 'italic' else: self.positive = True self.textFont = 'normal' style = self.styleSheetString.format(self.textFont) self.setStyleSheet(style) def value(self): selected = { '' if coder == '(empty)' else coder for coder in self.getSelectedCoders() } if self.positive: return selected else: return set(self.options) - selected
def __init__(self, number, field, options): super().__init__() self.number = number self.field = field self.setContentsMargins(0, 0, 0, 0) self.initialSymbol = '*' self.setText(self.initialSymbol) self.setFixedWidth(35) # 1: True, 0: Either, -1:False self.isUncertain = 0 self.isEstimate = 0 self.positive = True self.menu = QMenu() self.options = options for option in self.options: symbol = QAction(option, self, checkable=True, triggered=self.updateSymbol) self.menu.addAction(symbol) self.menu.addSeparator() selectAllAction = QAction('Select all', self, checkable=False, triggered=self.selectAll) self.menu.addAction(selectAllAction) resetToStarAction = QAction('Reset to *', self, checkable=False, triggered=self.resetToStar) self.menu.addAction(resetToStarAction) self.menu.addSeparator() self.negAction = QAction('Set negative', self, checkable=True, triggered=self.setNeg) self.menu.addAction(self.negAction) self.setMenu(self.menu) self.setContextMenuPolicy(Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.showContextMenu) self.makeMenu() if self.number == 8: self.setText(NULL) self.setEnabled(False) style = 'QPushButton{padding: 4px; background: white; border: 1px solid grey; color: grey;}' \ 'QPushButton::menu-indicator{image: none;}' elif self.number == 9: self.setText('/') self.setEnabled(False) style = 'QPushButton{padding: 4px; background: white; border: 1px solid grey; color: grey;}' \ 'QPushButton::menu-indicator{image: none;}' elif self.number == 16: self.setText('1') self.setEnabled(False) style = 'QPushButton{padding: 4px; background: white; border: 1px solid grey; color: grey;}' \ 'QPushButton::menu-indicator{image: none;}' elif self.number == 21: self.setText('2') self.setEnabled(False) style = 'QPushButton{padding: 4px; background: white; border: 1px solid grey; color: grey;}' \ 'QPushButton::menu-indicator{image: none;}' elif self.number == 26: self.setText('3') self.setEnabled(False) style = 'QPushButton{padding: 4px; background: white; border: 1px solid grey; color: grey;}' \ 'QPushButton::menu-indicator{image: none;}' elif self.number == 31: self.setText('4') self.setEnabled(False) style = 'QPushButton{padding: 4px; background: white; border: 1px solid grey; color: grey;}' \ 'QPushButton::menu-indicator{image: none;}' else: self.styleSheetString = 'QPushButton{{padding: 4px; background: {}; border: {}; color: {}; font: {}}}' self.defaultBackground = 'white' self.defaultBorder = '1px solid grey' self.defaultTextColor = 'black' self.flaggedBackground = 'grey' self.notFlaggedBackground = 'pink' self.flaggedBorder = '2px dashed black' self.notFlaggedBorder = '2px dashed red' self.multipleTextColor = 'green' self.positiveFont = 'normal' self.negativeFont = 'italic' self.background = self.defaultBackground self.border = self.defaultBorder self.textColor = self.defaultTextColor self.textFont = self.positiveFont style = self.styleSheetString.format(self.background, self.border, self.textColor, self.textFont) self.setStyleSheet(style)
class TransSlot(QPushButton): def __init__(self, number, field, options): super().__init__() self.number = number self.field = field self.setContentsMargins(0, 0, 0, 0) self.initialSymbol = '*' self.setText(self.initialSymbol) self.setFixedWidth(35) # 1: True, 0: Either, -1:False self.isUncertain = 0 self.isEstimate = 0 self.positive = True self.menu = QMenu() self.options = options for option in self.options: symbol = QAction(option, self, checkable=True, triggered=self.updateSymbol) self.menu.addAction(symbol) self.menu.addSeparator() selectAllAction = QAction('Select all', self, checkable=False, triggered=self.selectAll) self.menu.addAction(selectAllAction) resetToStarAction = QAction('Reset to *', self, checkable=False, triggered=self.resetToStar) self.menu.addAction(resetToStarAction) self.menu.addSeparator() self.negAction = QAction('Set negative', self, checkable=True, triggered=self.setNeg) self.menu.addAction(self.negAction) self.setMenu(self.menu) self.setContextMenuPolicy(Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.showContextMenu) self.makeMenu() if self.number == 8: self.setText(NULL) self.setEnabled(False) style = 'QPushButton{padding: 4px; background: white; border: 1px solid grey; color: grey;}' \ 'QPushButton::menu-indicator{image: none;}' elif self.number == 9: self.setText('/') self.setEnabled(False) style = 'QPushButton{padding: 4px; background: white; border: 1px solid grey; color: grey;}' \ 'QPushButton::menu-indicator{image: none;}' elif self.number == 16: self.setText('1') self.setEnabled(False) style = 'QPushButton{padding: 4px; background: white; border: 1px solid grey; color: grey;}' \ 'QPushButton::menu-indicator{image: none;}' elif self.number == 21: self.setText('2') self.setEnabled(False) style = 'QPushButton{padding: 4px; background: white; border: 1px solid grey; color: grey;}' \ 'QPushButton::menu-indicator{image: none;}' elif self.number == 26: self.setText('3') self.setEnabled(False) style = 'QPushButton{padding: 4px; background: white; border: 1px solid grey; color: grey;}' \ 'QPushButton::menu-indicator{image: none;}' elif self.number == 31: self.setText('4') self.setEnabled(False) style = 'QPushButton{padding: 4px; background: white; border: 1px solid grey; color: grey;}' \ 'QPushButton::menu-indicator{image: none;}' else: self.styleSheetString = 'QPushButton{{padding: 4px; background: {}; border: {}; color: {}; font: {}}}' self.defaultBackground = 'white' self.defaultBorder = '1px solid grey' self.defaultTextColor = 'black' self.flaggedBackground = 'grey' self.notFlaggedBackground = 'pink' self.flaggedBorder = '2px dashed black' self.notFlaggedBorder = '2px dashed red' self.multipleTextColor = 'green' self.positiveFont = 'normal' self.negativeFont = 'italic' self.background = self.defaultBackground self.border = self.defaultBorder self.textColor = self.defaultTextColor self.textFont = self.positiveFont style = self.styleSheetString.format(self.background, self.border, self.textColor, self.textFont) self.setStyleSheet(style) def resetToStar(self): for act in self.menu.actions()[:-3]: act.setChecked(False) self.updateSymbol() def selectAll(self): for act in self.menu.actions()[:-3]: act.setChecked(True) self.updateSymbol() def setNeg(self): if self.negAction.isChecked(): self.positive = False self.textFont = self.negativeFont else: self.positive = True self.textFont = self.positiveFont style = self.styleSheetString.format(self.background, self.border, self.textColor, self.textFont) self.setStyleSheet(style) def makeMenu(self): self.popMenu = QMenu(self) self.changeEstimateAct = QAction('Flagged as estimate', self, triggered=self.changeEstimate, checkable=True) self.notEstimateAct = QAction('NOT flagged as estimate', self, triggered=self.notEstimate, checkable=True) self.changeUncertaintyAct = QAction('Flagged as uncertain', self, triggered=self.changeUncertainty, checkable=True) self.notUncertaintyAct = QAction('NOT flagged as uncertain', self, triggered=self.notUncertainty, checkable=True) self.popMenu.addAction(self.changeEstimateAct) self.popMenu.addAction(self.notEstimateAct) self.popMenu.addSeparator() self.popMenu.addAction(self.changeUncertaintyAct) self.popMenu.addAction(self.notUncertaintyAct) def notEstimate(self): # estimate checked if self.changeEstimateAct.isChecked(): # not estimate checked if self.notEstimateAct.isChecked(): self.changeEstimateAct.setChecked(False) self.isEstimate = -1 self.border = self.notFlaggedBorder else: self.isEstimate = 1 self.border = self.flaggedBorder # estimate not checked else: # not estimate checked if self.notEstimateAct.isChecked(): self.isEstimate = -1 self.border = self.notFlaggedBorder else: self.isEstimate = 0 self.border = self.defaultBorder style = self.styleSheetString.format(self.background, self.border, self.textColor, self.textFont) self.setStyleSheet(style) def notUncertainty(self): # uncertainty checked if self.changeUncertaintyAct.isChecked(): # not uncertainty checked if self.notUncertaintyAct.isChecked(): self.changeUncertaintyAct.setChecked(False) self.isUncertain = -1 self.background = self.notFlaggedBackground else: self.isUncertain = 1 self.background = self.flaggedBackground # uncertainty not checked else: # not uncertainty checked if self.notUncertaintyAct.isChecked(): self.isUncertain = -1 self.background = self.notFlaggedBackground else: self.isUncertain = 0 self.background = self.defaultBackground style = self.styleSheetString.format(self.background, self.border, self.textColor, self.textFont) self.setStyleSheet(style) def showContextMenu(self, point): self.popMenu.exec_(self.mapToGlobal(point)) def changeEstimate(self): # estimate checked if self.changeEstimateAct.isChecked(): # not estimate checked if self.notEstimateAct.isChecked(): self.notEstimateAct.setChecked(False) self.isEstimate = 1 self.border = self.flaggedBorder else: self.isEstimate = 1 self.border = self.flaggedBorder # estimate not checked else: # not estimate checked if self.notEstimateAct.isChecked(): self.isEstimate = -1 self.border = self.notFlaggedBorder else: self.isEstimate = 0 self.border = self.defaultBorder style = self.styleSheetString.format(self.background, self.border, self.textColor, self.textFont) self.setStyleSheet(style) def changeUncertainty(self): # uncertainty checked if self.changeUncertaintyAct.isChecked(): # not uncertainty checked if self.notUncertaintyAct.isChecked(): self.notUncertaintyAct.setChecked(False) self.isUncertain = 1 self.background = self.notFlaggedBackground else: self.isUncertain = 1 self.background = self.flaggedBackground # uncertainty not checked else: # not uncertainty checked if self.notUncertaintyAct.isChecked(): self.isUncertain = -1 self.background = self.notFlaggedBackground else: self.isUncertain = 0 self.background = self.defaultBackground style = self.styleSheetString.format(self.background, self.border, self.textColor, self.textFont) self.setStyleSheet(style) def getSelectedSymbols(self): selectedSymbols = list() for act in self.menu.actions(): if act.isChecked(): selectedSymbols.append(act.text()) if 'Set negative' in selectedSymbols: selectedSymbols.remove('Set negative') return selectedSymbols def updateSymbol(self): selectedSymbols = self.getSelectedSymbols() if selectedSymbols: first = selectedSymbols[0] self.setText(first) if len(selectedSymbols) >= 2: self.textColor = self.multipleTextColor else: self.textColor = self.defaultTextColor else: self.setText(self.initialSymbol) self.textColor = self.defaultTextColor style = self.styleSheetString.format(self.background, self.border, self.textColor, self.textFont) self.setStyleSheet(style) def value(self): symbols = set(self.getSelectedSymbols()) | {self.text()} results = { 'selected': symbols, 'options': self.options, 'positive': self.positive, 'flag_estimate': self.isEstimate, 'flag_uncertain': self.isUncertain } return results
def makeMenu(self): self.popMenu = QMenu(self) self.editHandshapeAct = QAction('Edit handshape', self, triggered=self.editHandshape) self.popMenu.addAction(self.editHandshapeAct)