def init_value_box(self): self.value_box.setEnabled(True) self.value_box.setText('') self.value_box.setInputMask('') self.value_box.setValidator(None) col = self.current_col if not col: return action = self.current_action if not action: return m = self.fm[col] dt = m['datatype'] tt = '' if col == 'identifiers': tt = _('Enter either an identifier type or an ' 'identifier type and value of the form identifier:value') elif col == 'languages': tt = _('Enter a 3 letter ISO language code, like fra for French' ' or deu for German or eng for English. You can also use' ' the full language name, in which case calibre will try to' ' automatically convert it to the language code.') elif dt in ('int', 'float', 'rating'): tt = _('Enter a number') v = QIntValidator if dt == 'int' else QDoubleValidator self.value_box.setValidator(v(self.value_box)) elif dt == 'datetime': if action == 'count_days': self.value_box.setValidator(QIntValidator(self.value_box)) tt = _( 'Enter the maximum days old the item can be. Zero is today. ' 'Dates in the future always match') elif action == 'older count days': self.value_box.setValidator(QIntValidator(self.value_box)) tt = _( 'Enter the minimum days old the item can be. Zero is today. ' 'Dates in the future never match') elif action == 'older future days': self.value_box.setValidator(QIntValidator(self.value_box)) tt = _('Enter the maximum days in the future the item can be. ' 'Zero is today. Dates in the past always match') elif action == 'newer future days': self.value_box.setValidator(QIntValidator(self.value_box)) tt = _('Enter the minimum days in the future the item can be. ' 'Zero is today. Dates in the past never match') else: self.value_box.setInputMask('9999-99-99') tt = _('Enter a date in the format YYYY-MM-DD') else: tt = _('Enter a string.') if 'pattern' in action: tt = _('Enter a regular expression') elif m.get('is_multiple', False): tt += '\n' + _( 'You can match multiple values by separating' ' them with %s') % m['is_multiple']['ui_to_list'] self.value_box.setToolTip(tt) if action in ('is set', 'is not set', 'is true', 'is false', 'is undefined'): self.value_box.setEnabled(False)
def __init__(self, *args): QWidget.__init__(self, *args) lo = QHBoxLayout(self) lo.setContentsMargins(0, 0, 0, 0) lo.setSpacing(5) # type selector self.wtypesel = QComboBox(self) for i, tp in enumerate(self.ValueTypes): self.wtypesel.addItem(tp.__name__) QObject.connect(self.wtypesel, SIGNAL("activated(int)"), self._selectTypeNum) typesel_lab = QLabel("&Type:", self) typesel_lab.setBuddy(self.wtypesel) lo.addWidget(typesel_lab, 0) lo.addWidget(self.wtypesel, 0) self.wvalue = QLineEdit(self) self.wvalue_lab = QLabel("&Value:", self) self.wvalue_lab.setBuddy(self.wvalue) self.wbool = QComboBox(self) self.wbool.addItems(["false", "true"]) self.wbool.setCurrentIndex(1) lo.addWidget(self.wvalue_lab, 0) lo.addWidget(self.wvalue, 1) lo.addWidget(self.wbool, 1) self.wvalue.hide() # make input validators self._validators = { int: QIntValidator(self), float: QDoubleValidator(self) } # select bool type initially self._selectTypeNum(0)
def __init__(self, rddtDataExtractor, notifyImgurAPI): """ The Dialog that handles changing settings for how the program operates :type rddtDataExtractor: RedditDataExtractor.redditDataExtractor.RedditDataExtractor :type notifyImgurAPI: function """ QDialog.__init__(self) # Set up the user interface from Designer. self.setupUi(self) self.userLists = rddtDataExtractor.userLists self.subredditLists = rddtDataExtractor.subredditLists self.currentUserListName = rddtDataExtractor.defaultUserListName self.currentSubredditListName = rddtDataExtractor.defaultSubredditListName self.avoidDuplicates = rddtDataExtractor.avoidDuplicates self.getExternalContent = rddtDataExtractor.getExternalContent self.getCommentExternalContent = rddtDataExtractor.getCommentExternalContent self.getSelftextExternalContent = rddtDataExtractor.getSelftextExternalContent self.getSubmissionContent = rddtDataExtractor.getSubmissionContent self.subSort = rddtDataExtractor.subSort self.subLimit = rddtDataExtractor.subLimit self.operMap = rddtDataExtractor.operMap self.validOperForPropMap = rddtDataExtractor.validOperForPropMap self.connectMap = rddtDataExtractor.connectMap self.filterExternalContent = rddtDataExtractor.filterExternalContent self.filterSubmissionContent = rddtDataExtractor.filterSubmissionContent self.restrictDownloadsByCreationDate = rddtDataExtractor.restrictDownloadsByCreationDate self.showImgurAPINotification = rddtDataExtractor.showImgurAPINotification self.avoidVideos = rddtDataExtractor.avoidVideos self.getAuthorsCommentsOnly = rddtDataExtractor.getAuthorsCommentsOnly self.notifyImgurAPI = notifyImgurAPI self.validator = QIntValidator(1, 1000) self.filtTableTypeCol = 0 self.filtTablePropCol = 1 self.filtTableOperCol = 2 self.filtTableValCol = 3 self.filtTableConnectCol = 4 self.defaultUserListComboBox.activated.connect(self.chooseNewUserList) self.defaultSubredditListComboBox.activated.connect( self.chooseNewSubredditList) self.avoidDuplCheckBox.clicked.connect(lambda: self.changeCheckBox( self.avoidDuplCheckBox, 'avoidDuplicates')) self.getExternalContentCheckBox.clicked.connect( lambda: self.changeCheckBox(self.getExternalContentCheckBox, 'getExternalContent')) self.getCommentExternalContentCheckBox.clicked.connect( lambda: self.changeCheckBox(self.getCommentExternalContentCheckBox, 'getCommentExternalContent')) self.getSelftextExternalContentCheckBox.clicked.connect( lambda: self.changeCheckBox( self.getSelftextExternalContentCheckBox, 'getSelftextExternalContent')) self.getSubmissionContentCheckBox.clicked.connect( lambda: self.changeCheckBox(self.getSubmissionContentCheckBox, 'getSubmissionContent')) self.showImgurAPINotificationCheckBox.clicked.connect( lambda: self.changeCheckBox(self.showImgurAPINotificationCheckBox, 'showImgurAPINotification')) self.avoidVideosCheckBox.clicked.connect(lambda: self.changeCheckBox( self.avoidVideosCheckBox, 'avoidVideos')) self.getAuthorsCommentsOnlyCheckBox.clicked.connect( lambda: self.changeCheckBox(self.getAuthorsCommentsOnlyCheckBox, 'getAuthorsCommentsOnly')) self.resetClientIdCheckBox.clicked.connect(self.notifyImgurAPI) self.hotBtn.clicked.connect(lambda: self.changeSubSort("hot")) self.newBtn.clicked.connect(lambda: self.changeSubSort("new")) self.risingBtn.clicked.connect(lambda: self.changeSubSort("rising")) self.controversialBtn.clicked.connect( lambda: self.changeSubSort("controversial")) self.topBtn.clicked.connect(lambda: self.changeSubSort("top")) self.subLimitTextEdit.textChanged.connect(self.setSubLimit) self.subLimitTextEdit.setValidator(self.validator) self.subLimitTextEdit.setText( str(self.subLimit) if self.subLimit is not None else "1000") self.filterTable.cellPressed.connect(self.addFilter) self.constructFilterTable(rddtDataExtractor.submissionFilts, rddtDataExtractor.commentFilts, rddtDataExtractor.connector, rddtDataExtractor.operMap, rddtDataExtractor.connectMap) self.filterExternalContentCheckBox.clicked.connect( lambda: self.changeCheckBox(self.filterExternalContentCheckBox, 'filterExternalContent')) self.filterSubmissionContentCheckBox.clicked.connect( lambda: self.changeCheckBox(self.filterSubmissionContentCheckBox, 'filterSubmissionContent')) self.restrictDownloadsByCreationDateCheckBox.clicked.connect( lambda: self.changeCheckBox( self.restrictDownloadsByCreationDateCheckBox, 'restrictDownloadsByCreationDate')) self.initSettings()
class SettingsGUI(QDialog, Ui_SettingsDialog): def __init__(self, rddtDataExtractor, notifyImgurAPI): """ The Dialog that handles changing settings for how the program operates :type rddtDataExtractor: RedditDataExtractor.redditDataExtractor.RedditDataExtractor :type notifyImgurAPI: function """ QDialog.__init__(self) # Set up the user interface from Designer. self.setupUi(self) self.userLists = rddtDataExtractor.userLists self.subredditLists = rddtDataExtractor.subredditLists self.currentUserListName = rddtDataExtractor.defaultUserListName self.currentSubredditListName = rddtDataExtractor.defaultSubredditListName self.avoidDuplicates = rddtDataExtractor.avoidDuplicates self.getExternalContent = rddtDataExtractor.getExternalContent self.getCommentExternalContent = rddtDataExtractor.getCommentExternalContent self.getSelftextExternalContent = rddtDataExtractor.getSelftextExternalContent self.getSubmissionContent = rddtDataExtractor.getSubmissionContent self.subSort = rddtDataExtractor.subSort self.subLimit = rddtDataExtractor.subLimit self.operMap = rddtDataExtractor.operMap self.validOperForPropMap = rddtDataExtractor.validOperForPropMap self.connectMap = rddtDataExtractor.connectMap self.filterExternalContent = rddtDataExtractor.filterExternalContent self.filterSubmissionContent = rddtDataExtractor.filterSubmissionContent self.restrictDownloadsByCreationDate = rddtDataExtractor.restrictDownloadsByCreationDate self.showImgurAPINotification = rddtDataExtractor.showImgurAPINotification self.avoidVideos = rddtDataExtractor.avoidVideos self.getAuthorsCommentsOnly = rddtDataExtractor.getAuthorsCommentsOnly self.notifyImgurAPI = notifyImgurAPI self.validator = QIntValidator(1, 1000) self.filtTableTypeCol = 0 self.filtTablePropCol = 1 self.filtTableOperCol = 2 self.filtTableValCol = 3 self.filtTableConnectCol = 4 self.defaultUserListComboBox.activated.connect(self.chooseNewUserList) self.defaultSubredditListComboBox.activated.connect( self.chooseNewSubredditList) self.avoidDuplCheckBox.clicked.connect(lambda: self.changeCheckBox( self.avoidDuplCheckBox, 'avoidDuplicates')) self.getExternalContentCheckBox.clicked.connect( lambda: self.changeCheckBox(self.getExternalContentCheckBox, 'getExternalContent')) self.getCommentExternalContentCheckBox.clicked.connect( lambda: self.changeCheckBox(self.getCommentExternalContentCheckBox, 'getCommentExternalContent')) self.getSelftextExternalContentCheckBox.clicked.connect( lambda: self.changeCheckBox( self.getSelftextExternalContentCheckBox, 'getSelftextExternalContent')) self.getSubmissionContentCheckBox.clicked.connect( lambda: self.changeCheckBox(self.getSubmissionContentCheckBox, 'getSubmissionContent')) self.showImgurAPINotificationCheckBox.clicked.connect( lambda: self.changeCheckBox(self.showImgurAPINotificationCheckBox, 'showImgurAPINotification')) self.avoidVideosCheckBox.clicked.connect(lambda: self.changeCheckBox( self.avoidVideosCheckBox, 'avoidVideos')) self.getAuthorsCommentsOnlyCheckBox.clicked.connect( lambda: self.changeCheckBox(self.getAuthorsCommentsOnlyCheckBox, 'getAuthorsCommentsOnly')) self.resetClientIdCheckBox.clicked.connect(self.notifyImgurAPI) self.hotBtn.clicked.connect(lambda: self.changeSubSort("hot")) self.newBtn.clicked.connect(lambda: self.changeSubSort("new")) self.risingBtn.clicked.connect(lambda: self.changeSubSort("rising")) self.controversialBtn.clicked.connect( lambda: self.changeSubSort("controversial")) self.topBtn.clicked.connect(lambda: self.changeSubSort("top")) self.subLimitTextEdit.textChanged.connect(self.setSubLimit) self.subLimitTextEdit.setValidator(self.validator) self.subLimitTextEdit.setText( str(self.subLimit) if self.subLimit is not None else "1000") self.filterTable.cellPressed.connect(self.addFilter) self.constructFilterTable(rddtDataExtractor.submissionFilts, rddtDataExtractor.commentFilts, rddtDataExtractor.connector, rddtDataExtractor.operMap, rddtDataExtractor.connectMap) self.filterExternalContentCheckBox.clicked.connect( lambda: self.changeCheckBox(self.filterExternalContentCheckBox, 'filterExternalContent')) self.filterSubmissionContentCheckBox.clicked.connect( lambda: self.changeCheckBox(self.filterSubmissionContentCheckBox, 'filterSubmissionContent')) self.restrictDownloadsByCreationDateCheckBox.clicked.connect( lambda: self.changeCheckBox( self.restrictDownloadsByCreationDateCheckBox, 'restrictDownloadsByCreationDate')) self.initSettings() def initSettings(self): for userListKey in self.userLists: self.defaultUserListComboBox.addItem(userListKey) index = self.defaultUserListComboBox.findText(self.currentUserListName) self.defaultUserListComboBox.setCurrentIndex(index) for subredditListKey in self.subredditLists: self.defaultSubredditListComboBox.addItem(subredditListKey) index = self.defaultSubredditListComboBox.findText( self.currentSubredditListName) self.defaultSubredditListComboBox.setCurrentIndex(index) self.avoidDuplCheckBox.setChecked(self.avoidDuplicates) self.getExternalContentCheckBox.setChecked(self.getExternalContent) self.getCommentExternalContentCheckBox.setChecked( self.getCommentExternalContent) self.getSelftextExternalContentCheckBox.setChecked( self.getSelftextExternalContent) self.showImgurAPINotificationCheckBox.setChecked( self.showImgurAPINotification) self.avoidVideosCheckBox.setChecked(self.avoidVideos) self.getAuthorsCommentsOnlyCheckBox.setChecked( self.getAuthorsCommentsOnly) self.getSubmissionContentCheckBox.setChecked(self.getSubmissionContent) self.filterExternalContentCheckBox.setChecked( self.filterExternalContent) self.filterSubmissionContentCheckBox.setChecked( self.filterSubmissionContent) self.restrictDownloadsByCreationDateCheckBox.setChecked( self.restrictDownloadsByCreationDate) self.initSubSort() def initSubSort(self): if self.subSort == "hot": self.hotBtn.setChecked(True) elif self.subSort == "new": self.newBtn.setChecked(True) elif self.subSort == "rising": self.risingBtn.setChecked(True) elif self.subSort == "controversial": self.controversialBtn.setChecked(True) else: self.topBtn.setChecked(True) def constructFilterTableWidgets(self, type, prop, oper, val, operMap, row): """ Given the type, property, operation, value, operator map, and row, construct a row's filter table comboboxes and text edits :type type: str :type prop: str :type oper: str :type val: str :type operMap: dict :type row: int """ self.addFilter(row, self.filtTableTypeCol, type) propCombobox = self.filterTable.cellWidget(row, self.filtTablePropCol) propCombobox.setCurrentIndex(propCombobox.findText(prop)) operCombobox = self.filterTable.cellWidget(row, self.filtTableOperCol) operCombobox.setCurrentIndex( operCombobox.findText(findKey(operMap, oper))) valTextWidget = self.filterTable.cellWidget(row, self.filtTableValCol) valTextWidget.setPlainText(str(val)) def constructFilterTable(self, submissionFilts, commentFilts, connector, operMap, connectMap): """ Given the filters from a previous save, reconstruct the filter table :type submissionFilts: list :type commentFilts: list :type connector: str :type operMap: dict :type connectMap: dict """ numFilts = len(submissionFilts) + len(commentFilts) if numFilts > 0: for row in range(1, numFilts): # first row is already added self.filterTable.insertRow(row) row = 0 for prop, oper, val in submissionFilts: self.constructFilterTableWidgets("Submission", prop, oper, val, operMap, row) row += 1 for prop, oper, val in commentFilts: self.constructFilterTableWidgets("Comment", prop, oper, val, operMap, row) row += 1 connectorText = findKey(connectMap, connector) for row in range(self.filterTable.rowCount() - 1): ConnectCombobox.text = connectorText # Set this to whatever the connector is currently so on creation of new ones, it doesn't default to And connectCombobox = ConnectCombobox(row, self.filterTable, self.filtTableConnectCol, self.connectMap) connectCombobox.setCurrentIndex( connectCombobox.findText(connectorText)) self.filterTable.setCellWidget(row, self.filtTableConnectCol, connectCombobox) else: self.addFilter(0, self.filtTableTypeCol) def chooseNewUserList(self): self.currentUserListName = self.defaultUserListComboBox.currentText() def chooseNewSubredditList(self): self.currentSubredditListName = self.defaultSubredditListComboBox.currentText( ) def changeCheckBox(self, checkBox, setting): """ Given the name of the setting in the SettingsGUI object, and the corresponding checkbox, set it to whether the checkbox is checked or not :type checkBox: QCheckBox :type setting: str """ settingExists = self.__dict__.get(setting) if settingExists is not None: self.__dict__[setting] = checkBox.isChecked() def changeSubSort(self, subSort): """ Change the sorting method for subreddits :type subSort: str """ GenericListModelObj.subSort = subSort self.subSort = subSort def setSubLimit(self): text = self.subLimitTextEdit.text() validState = self.validator.validate( text, 0)[0] # validate() returns a tuple, the state is the 0 index if validState == QValidator.Acceptable: # set the limit to max (None in PRAW's documentation) if it is equal to 1000 # Note: the Reddit API actually only ever returns up to 1000 self.subLimit = None if int(text) == 1000 else int(text) def addFilter(self, row, col, type="Submission"): """ Add a whole row of filter comboboxes :type row: int :type col: int :type type: str """ if col == self.filtTableTypeCol: operCombobox = OperCombobox(row) propCombobox = PropCombobox(row, operCombobox, self.validOperForPropMap) typeCombobox = TypeCombobox(row, propCombobox) typeCombobox.setCurrentIndex(typeCombobox.findText(type)) textEdit = QPlainTextEdit() self.filterTable.setCellWidget(row, self.filtTableTypeCol, typeCombobox) self.filterTable.setCellWidget(row, self.filtTablePropCol, propCombobox) self.filterTable.setCellWidget(row, self.filtTableOperCol, operCombobox) self.filterTable.setCellWidget(row, self.filtTableValCol, textEdit) elif col == self.filtTableConnectCol: connectCombobox = ConnectCombobox(row, self.filterTable, self.filtTableConnectCol, self.connectMap) self.filterTable.setCellWidget(row, self.filtTableConnectCol, connectCombobox) self.filterTable.insertRow(row + 1) self.addFilter(row + 1, self.filtTableTypeCol, "Submission") def checkFilterTable(self): """ Make sure the user entered a value in the textedit field """ if self.filterExternalContentCheckBox.isChecked( ) or self.filterSubmissionContentCheckBox.isChecked(): for row in range(self.filterTable.rowCount()): if self.filterTable.cellWidget( row, self.filtTableValCol) is None or len( self.filterTable.cellWidget( row, self.filtTableValCol).toPlainText()) <= 0: QMessageBox.warning( QMessageBox(), "Data Extractor for reddit", "Please enter text in the value column or uncheck that you would like to filter content." ) return False return True def accept(self): if self.checkFilterTable(): super().accept()
def __init__(self, rddtDataExtractor, notifyImgurAPI): """ The Dialog that handles changing settings for how the program operates :type rddtDataExtractor: RedditDataExtractor.redditDataExtractor.RedditDataExtractor :type notifyImgurAPI: function """ QDialog.__init__(self) # Set up the user interface from Designer. self.setupUi(self) self.userLists = rddtDataExtractor.userLists self.subredditLists = rddtDataExtractor.subredditLists self.currentUserListName = rddtDataExtractor.defaultUserListName self.currentSubredditListName = rddtDataExtractor.defaultSubredditListName self.avoidDuplicates = rddtDataExtractor.avoidDuplicates self.getExternalContent = rddtDataExtractor.getExternalContent self.getCommentExternalContent = rddtDataExtractor.getCommentExternalContent self.getSelftextExternalContent = rddtDataExtractor.getSelftextExternalContent self.getSubmissionContent = rddtDataExtractor.getSubmissionContent self.subSort = rddtDataExtractor.subSort self.subLimit = rddtDataExtractor.subLimit self.operMap = rddtDataExtractor.operMap self.validOperForPropMap = rddtDataExtractor.validOperForPropMap self.connectMap = rddtDataExtractor.connectMap self.filterExternalContent = rddtDataExtractor.filterExternalContent self.filterSubmissionContent = rddtDataExtractor.filterSubmissionContent self.restrictDownloadsByCreationDate = rddtDataExtractor.restrictDownloadsByCreationDate self.showImgurAPINotification = rddtDataExtractor.showImgurAPINotification self.avoidVideos = rddtDataExtractor.avoidVideos self.getAuthorsCommentsOnly = rddtDataExtractor.getAuthorsCommentsOnly self.notifyImgurAPI = notifyImgurAPI self.validator = QIntValidator(1, 1000) self.filtTableTypeCol = 0 self.filtTablePropCol = 1 self.filtTableOperCol = 2 self.filtTableValCol = 3 self.filtTableConnectCol = 4 self.defaultUserListComboBox.activated.connect(self.chooseNewUserList) self.defaultSubredditListComboBox.activated.connect(self.chooseNewSubredditList) self.avoidDuplCheckBox.clicked.connect(lambda: self.changeCheckBox(self.avoidDuplCheckBox, "avoidDuplicates")) self.getExternalContentCheckBox.clicked.connect( lambda: self.changeCheckBox(self.getExternalContentCheckBox, "getExternalContent") ) self.getCommentExternalContentCheckBox.clicked.connect( lambda: self.changeCheckBox(self.getCommentExternalContentCheckBox, "getCommentExternalContent") ) self.getSelftextExternalContentCheckBox.clicked.connect( lambda: self.changeCheckBox(self.getSelftextExternalContentCheckBox, "getSelftextExternalContent") ) self.getSubmissionContentCheckBox.clicked.connect( lambda: self.changeCheckBox(self.getSubmissionContentCheckBox, "getSubmissionContent") ) self.showImgurAPINotificationCheckBox.clicked.connect( lambda: self.changeCheckBox(self.showImgurAPINotificationCheckBox, "showImgurAPINotification") ) self.avoidVideosCheckBox.clicked.connect(lambda: self.changeCheckBox(self.avoidVideosCheckBox, "avoidVideos")) self.getAuthorsCommentsOnlyCheckBox.clicked.connect( lambda: self.changeCheckBox(self.getAuthorsCommentsOnlyCheckBox, "getAuthorsCommentsOnly") ) self.resetClientIdCheckBox.clicked.connect(self.notifyImgurAPI) self.hotBtn.clicked.connect(lambda: self.changeSubSort("hot")) self.newBtn.clicked.connect(lambda: self.changeSubSort("new")) self.risingBtn.clicked.connect(lambda: self.changeSubSort("rising")) self.controversialBtn.clicked.connect(lambda: self.changeSubSort("controversial")) self.topBtn.clicked.connect(lambda: self.changeSubSort("top")) self.subLimitTextEdit.textChanged.connect(self.setSubLimit) self.subLimitTextEdit.setValidator(self.validator) self.subLimitTextEdit.setText(str(self.subLimit) if self.subLimit is not None else "1000") self.filterTable.cellPressed.connect(self.addFilter) self.constructFilterTable( rddtDataExtractor.submissionFilts, rddtDataExtractor.commentFilts, rddtDataExtractor.connector, rddtDataExtractor.operMap, rddtDataExtractor.connectMap, ) self.filterExternalContentCheckBox.clicked.connect( lambda: self.changeCheckBox(self.filterExternalContentCheckBox, "filterExternalContent") ) self.filterSubmissionContentCheckBox.clicked.connect( lambda: self.changeCheckBox(self.filterSubmissionContentCheckBox, "filterSubmissionContent") ) self.restrictDownloadsByCreationDateCheckBox.clicked.connect( lambda: self.changeCheckBox(self.restrictDownloadsByCreationDateCheckBox, "restrictDownloadsByCreationDate") ) self.initSettings()
class SettingsGUI(QDialog, Ui_SettingsDialog): def __init__(self, rddtDataExtractor, notifyImgurAPI): """ The Dialog that handles changing settings for how the program operates :type rddtDataExtractor: RedditDataExtractor.redditDataExtractor.RedditDataExtractor :type notifyImgurAPI: function """ QDialog.__init__(self) # Set up the user interface from Designer. self.setupUi(self) self.userLists = rddtDataExtractor.userLists self.subredditLists = rddtDataExtractor.subredditLists self.currentUserListName = rddtDataExtractor.defaultUserListName self.currentSubredditListName = rddtDataExtractor.defaultSubredditListName self.avoidDuplicates = rddtDataExtractor.avoidDuplicates self.getExternalContent = rddtDataExtractor.getExternalContent self.getCommentExternalContent = rddtDataExtractor.getCommentExternalContent self.getSelftextExternalContent = rddtDataExtractor.getSelftextExternalContent self.getSubmissionContent = rddtDataExtractor.getSubmissionContent self.subSort = rddtDataExtractor.subSort self.subLimit = rddtDataExtractor.subLimit self.operMap = rddtDataExtractor.operMap self.validOperForPropMap = rddtDataExtractor.validOperForPropMap self.connectMap = rddtDataExtractor.connectMap self.filterExternalContent = rddtDataExtractor.filterExternalContent self.filterSubmissionContent = rddtDataExtractor.filterSubmissionContent self.restrictDownloadsByCreationDate = rddtDataExtractor.restrictDownloadsByCreationDate self.showImgurAPINotification = rddtDataExtractor.showImgurAPINotification self.avoidVideos = rddtDataExtractor.avoidVideos self.getAuthorsCommentsOnly = rddtDataExtractor.getAuthorsCommentsOnly self.notifyImgurAPI = notifyImgurAPI self.validator = QIntValidator(1, 1000) self.filtTableTypeCol = 0 self.filtTablePropCol = 1 self.filtTableOperCol = 2 self.filtTableValCol = 3 self.filtTableConnectCol = 4 self.defaultUserListComboBox.activated.connect(self.chooseNewUserList) self.defaultSubredditListComboBox.activated.connect(self.chooseNewSubredditList) self.avoidDuplCheckBox.clicked.connect(lambda: self.changeCheckBox(self.avoidDuplCheckBox, "avoidDuplicates")) self.getExternalContentCheckBox.clicked.connect( lambda: self.changeCheckBox(self.getExternalContentCheckBox, "getExternalContent") ) self.getCommentExternalContentCheckBox.clicked.connect( lambda: self.changeCheckBox(self.getCommentExternalContentCheckBox, "getCommentExternalContent") ) self.getSelftextExternalContentCheckBox.clicked.connect( lambda: self.changeCheckBox(self.getSelftextExternalContentCheckBox, "getSelftextExternalContent") ) self.getSubmissionContentCheckBox.clicked.connect( lambda: self.changeCheckBox(self.getSubmissionContentCheckBox, "getSubmissionContent") ) self.showImgurAPINotificationCheckBox.clicked.connect( lambda: self.changeCheckBox(self.showImgurAPINotificationCheckBox, "showImgurAPINotification") ) self.avoidVideosCheckBox.clicked.connect(lambda: self.changeCheckBox(self.avoidVideosCheckBox, "avoidVideos")) self.getAuthorsCommentsOnlyCheckBox.clicked.connect( lambda: self.changeCheckBox(self.getAuthorsCommentsOnlyCheckBox, "getAuthorsCommentsOnly") ) self.resetClientIdCheckBox.clicked.connect(self.notifyImgurAPI) self.hotBtn.clicked.connect(lambda: self.changeSubSort("hot")) self.newBtn.clicked.connect(lambda: self.changeSubSort("new")) self.risingBtn.clicked.connect(lambda: self.changeSubSort("rising")) self.controversialBtn.clicked.connect(lambda: self.changeSubSort("controversial")) self.topBtn.clicked.connect(lambda: self.changeSubSort("top")) self.subLimitTextEdit.textChanged.connect(self.setSubLimit) self.subLimitTextEdit.setValidator(self.validator) self.subLimitTextEdit.setText(str(self.subLimit) if self.subLimit is not None else "1000") self.filterTable.cellPressed.connect(self.addFilter) self.constructFilterTable( rddtDataExtractor.submissionFilts, rddtDataExtractor.commentFilts, rddtDataExtractor.connector, rddtDataExtractor.operMap, rddtDataExtractor.connectMap, ) self.filterExternalContentCheckBox.clicked.connect( lambda: self.changeCheckBox(self.filterExternalContentCheckBox, "filterExternalContent") ) self.filterSubmissionContentCheckBox.clicked.connect( lambda: self.changeCheckBox(self.filterSubmissionContentCheckBox, "filterSubmissionContent") ) self.restrictDownloadsByCreationDateCheckBox.clicked.connect( lambda: self.changeCheckBox(self.restrictDownloadsByCreationDateCheckBox, "restrictDownloadsByCreationDate") ) self.initSettings() def initSettings(self): for userListKey in self.userLists: self.defaultUserListComboBox.addItem(userListKey) index = self.defaultUserListComboBox.findText(self.currentUserListName) self.defaultUserListComboBox.setCurrentIndex(index) for subredditListKey in self.subredditLists: self.defaultSubredditListComboBox.addItem(subredditListKey) index = self.defaultSubredditListComboBox.findText(self.currentSubredditListName) self.defaultSubredditListComboBox.setCurrentIndex(index) self.avoidDuplCheckBox.setChecked(self.avoidDuplicates) self.getExternalContentCheckBox.setChecked(self.getExternalContent) self.getCommentExternalContentCheckBox.setChecked(self.getCommentExternalContent) self.getSelftextExternalContentCheckBox.setChecked(self.getSelftextExternalContent) self.showImgurAPINotificationCheckBox.setChecked(self.showImgurAPINotification) self.avoidVideosCheckBox.setChecked(self.avoidVideos) self.getAuthorsCommentsOnlyCheckBox.setChecked(self.getAuthorsCommentsOnly) self.getSubmissionContentCheckBox.setChecked(self.getSubmissionContent) self.filterExternalContentCheckBox.setChecked(self.filterExternalContent) self.filterSubmissionContentCheckBox.setChecked(self.filterSubmissionContent) self.restrictDownloadsByCreationDateCheckBox.setChecked(self.restrictDownloadsByCreationDate) self.initSubSort() def initSubSort(self): if self.subSort == "hot": self.hotBtn.setChecked(True) elif self.subSort == "new": self.newBtn.setChecked(True) elif self.subSort == "rising": self.risingBtn.setChecked(True) elif self.subSort == "controversial": self.controversialBtn.setChecked(True) else: self.topBtn.setChecked(True) def constructFilterTableWidgets(self, type, prop, oper, val, operMap, row): """ Given the type, property, operation, value, operator map, and row, construct a row's filter table comboboxes and text edits :type type: str :type prop: str :type oper: str :type val: str :type operMap: dict :type row: int """ self.addFilter(row, self.filtTableTypeCol, type) propCombobox = self.filterTable.cellWidget(row, self.filtTablePropCol) propCombobox.setCurrentIndex(propCombobox.findText(prop)) operCombobox = self.filterTable.cellWidget(row, self.filtTableOperCol) operCombobox.setCurrentIndex(operCombobox.findText(findKey(operMap, oper))) valTextWidget = self.filterTable.cellWidget(row, self.filtTableValCol) valTextWidget.setPlainText(str(val)) def constructFilterTable(self, submissionFilts, commentFilts, connector, operMap, connectMap): """ Given the filters from a previous save, reconstruct the filter table :type submissionFilts: list :type commentFilts: list :type connector: str :type operMap: dict :type connectMap: dict """ numFilts = len(submissionFilts) + len(commentFilts) if numFilts > 0: for row in range(1, numFilts): # first row is already added self.filterTable.insertRow(row) row = 0 for prop, oper, val in submissionFilts: self.constructFilterTableWidgets("Submission", prop, oper, val, operMap, row) row += 1 for prop, oper, val in commentFilts: self.constructFilterTableWidgets("Comment", prop, oper, val, operMap, row) row += 1 connectorText = findKey(connectMap, connector) for row in range(self.filterTable.rowCount() - 1): ConnectCombobox.text = ( connectorText ) # Set this to whatever the connector is currently so on creation of new ones, it doesn't default to And connectCombobox = ConnectCombobox(row, self.filterTable, self.filtTableConnectCol, self.connectMap) connectCombobox.setCurrentIndex(connectCombobox.findText(connectorText)) self.filterTable.setCellWidget(row, self.filtTableConnectCol, connectCombobox) else: self.addFilter(0, self.filtTableTypeCol) def chooseNewUserList(self): self.currentUserListName = self.defaultUserListComboBox.currentText() def chooseNewSubredditList(self): self.currentSubredditListName = self.defaultSubredditListComboBox.currentText() def changeCheckBox(self, checkBox, setting): """ Given the name of the setting in the SettingsGUI object, and the corresponding checkbox, set it to whether the checkbox is checked or not :type checkBox: QCheckBox :type setting: str """ settingExists = self.__dict__.get(setting) if settingExists is not None: self.__dict__[setting] = checkBox.isChecked() def changeSubSort(self, subSort): """ Change the sorting method for subreddits :type subSort: str """ GenericListModelObj.subSort = subSort self.subSort = subSort def setSubLimit(self): text = self.subLimitTextEdit.text() validState = self.validator.validate(text, 0)[0] # validate() returns a tuple, the state is the 0 index if validState == QValidator.Acceptable: # set the limit to max (None in PRAW's documentation) if it is equal to 1000 # Note: the Reddit API actually only ever returns up to 1000 self.subLimit = None if int(text) == 1000 else int(text) def addFilter(self, row, col, type="Submission"): """ Add a whole row of filter comboboxes :type row: int :type col: int :type type: str """ if col == self.filtTableTypeCol: operCombobox = OperCombobox(row) propCombobox = PropCombobox(row, operCombobox, self.validOperForPropMap) typeCombobox = TypeCombobox(row, propCombobox) typeCombobox.setCurrentIndex(typeCombobox.findText(type)) textEdit = QPlainTextEdit() self.filterTable.setCellWidget(row, self.filtTableTypeCol, typeCombobox) self.filterTable.setCellWidget(row, self.filtTablePropCol, propCombobox) self.filterTable.setCellWidget(row, self.filtTableOperCol, operCombobox) self.filterTable.setCellWidget(row, self.filtTableValCol, textEdit) elif col == self.filtTableConnectCol: connectCombobox = ConnectCombobox(row, self.filterTable, self.filtTableConnectCol, self.connectMap) self.filterTable.setCellWidget(row, self.filtTableConnectCol, connectCombobox) self.filterTable.insertRow(row + 1) self.addFilter(row + 1, self.filtTableTypeCol, "Submission") def checkFilterTable(self): """ Make sure the user entered a value in the textedit field """ if self.filterExternalContentCheckBox.isChecked() or self.filterSubmissionContentCheckBox.isChecked(): for row in range(self.filterTable.rowCount()): if ( self.filterTable.cellWidget(row, self.filtTableValCol) is None or len(self.filterTable.cellWidget(row, self.filtTableValCol).toPlainText()) <= 0 ): QMessageBox.warning( QMessageBox(), "Data Extractor for reddit", "Please enter text in the value column or uncheck that you would like to filter content.", ) return False return True def accept(self): if self.checkFilterTable(): super().accept()