def __init__(self): super().__init__() self.corpus = None self.nyt_api = None self.output_info = '' self.num_retrieved = 0 self.num_all = 0 # API key self.api_dlg = self.APICredentialsDialog(self) self.api_dlg.accept(silent=True) gui.button(self.controlArea, self, 'Article API Key', callback=self.api_dlg.exec_, focusPolicy=Qt.NoFocus) # Query query_box = gui.widgetBox(self.controlArea, 'Query', addSpace=True) self.query_box = QueryBox(query_box, self, self.recent_queries, callback=self.new_query_input) # Year box date_box = gui.hBox(query_box) DatePickerInterval(date_box, self, 'date_from', 'date_to', min_date=MIN_DATE, max_date=date.today(), margin=(0, 3, 0, 0)) # Text includes features self.controlArea.layout().addWidget( CheckListLayout('Text includes', self, 'text_includes', self.attributes, cols=2, callback=self.set_text_features)) # Output info_box = gui.hBox(self.controlArea, 'Output') gui.label(info_box, self, 'Articles: %(output_info)s') # Buttons self.button_box = gui.hBox(self.controlArea) self.search_button = gui.button(self.button_box, self, 'Search', self.start_stop, focusPolicy=Qt.NoFocus)
def _setup_ui_(self): self.table_model = ReportItemModel(0, len(Column.__members__)) self.table = ReportTable(self.controlArea) self.table.setModel(self.table_model) self.table.setShowGrid(False) self.table.setSelectionBehavior(QTableView.SelectRows) self.table.setSelectionMode(QTableView.SingleSelection) self.table.setWordWrap(False) self.table.setMouseTracking(True) self.table.verticalHeader().setSectionResizeMode(QHeaderView.Fixed) self.table.verticalHeader().setDefaultSectionSize(20) self.table.verticalHeader().setVisible(False) self.table.horizontalHeader().setVisible(False) self.table.setFixedWidth(250) self.table.setColumnWidth(Column.item, 200) self.table.setColumnWidth(Column.remove, 23) self.table.setColumnWidth(Column.scheme, 25) self.table.clicked.connect(self._table_clicked) self.table.selectionModel().selectionChanged.connect( self._table_selection_changed) self.controlArea.layout().addWidget(self.table) self.last_scheme = None self.scheme_button = gui.button(self.controlArea, self, "Back to Last Scheme", callback=self._show_last_scheme) box = gui.hBox(self.controlArea) box.setContentsMargins(-6, 0, -6, 0) self.save_button = gui.button(box, self, "Save", callback=self.save_report, disabled=True) self.print_button = gui.button(box, self, "Print", callback=self._print_report, disabled=True) class PyBridge(QObject): @pyqtSlot(str) def _select_item(myself, item_id): item = self.table_model.get_item_by_id(item_id) self.table.selectRow( self.table_model.indexFromItem(item).row()) self._change_selected_item(item) @pyqtSlot(str, str) def _add_comment(myself, item_id, value): item = self.table_model.get_item_by_id(item_id) item.comment = value self.report_changed = True if WebviewWidget is not None: self.report_view = WebviewWidget(self.mainArea, bridge=PyBridge(self)) self.mainArea.layout().addWidget(self.report_view) else: self.report_view = None
def _setup_control_area(self) -> None: box = gui.widgetBox(self.controlArea, "Word Scoring Methods") for value, (n, _, tt) in SCORING_METHODS.items(): b = gui.hBox(box, margin=0) gui.checkBox( b, self, value, label=n, callback=self.__setting_changed, tooltip=tt, ) if value in ADDITIONAL_OPTIONS: value, options = ADDITIONAL_OPTIONS[value] gui.comboBox( b, self, value, items=options, callback=self.__setting_changed, ) box = gui.widgetBox(self.controlArea, "Aggregation") gui.comboBox( box, self, "aggregation", items=[n for n in AGGREGATIONS], callback=self.__setting_changed, ) gui.rubber(self.controlArea) gui.auto_send(self.buttonsArea, self, "auto_commit")
def __add_row(self, form: QFormLayout, box_name: str, label: str, settings: SettingsType): box = gui.hBox(None, box=None) for parameter, (values, default_value) in settings.items(): key = (box_name, label, parameter) control = _add_control(default_value, values, box, key, self.setting_changed) self.__controls[key] = (control, default_value) form.addRow(f"{label}:", box)
def _setup_control_area(self) -> None: box = gui.widgetBox(self.controlArea, "Word Scoring Methods") for value, (n, _, tt) in SCORING_METHODS.items(): b = gui.hBox(box, margin=0) gui.checkBox( b, self, value, label=n, callback=self.__setting_changed, tooltip=tt, ) if value in ADDITIONAL_OPTIONS: value, options = ADDITIONAL_OPTIONS[value] gui.comboBox( b, self, value, items=options, callback=self.__setting_changed, ) box = gui.widgetBox(self.controlArea, "Aggregation") gui.comboBox( box, self, "aggregation", items=[n for n in AGGREGATIONS], callback=self.__setting_changed, ) gui.rubber(self.controlArea) # select words box box = gui.vBox(self.buttonsArea, "Select Documents") grid = QGridLayout() grid.setContentsMargins(0, 0, 0, 0) self._sel_method_buttons = QButtonGroup() for method, label in enumerate(SelectionMethods.ITEMS): button = QRadioButton(label) button.setChecked(method == self.sel_method) grid.addWidget(button, method, 0) self._sel_method_buttons.addButton(button, method) self._sel_method_buttons.buttonClicked[int].connect( self.__set_selection_method) spin = gui.spin( box, self, "n_selected", 1, 999, addToLayout=False, callback=lambda: self.__set_selection_method(SelectionMethods. N_BEST), ) grid.addWidget(spin, 3, 1) box.layout().addLayout(grid) # autocommit gui.auto_send(self.buttonsArea, self, "auto_commit")
def listBox(widget, master, value=None, labels=None, box=None, callback=None, selectionMode=QtWidgets.QListWidget.SingleSelection, enableDragDrop=False, dragDropCallback=None, dataValidityCallback=None, sizeHint=None, **misc): """ Insert a list box. The value with which the box's value synchronizes (`master.<value>`) is a list of indices of selected items. :param widget: the widget into which the box is inserted :type widget: QWidget or None :param master: master widget :type master: OWWidget or OWComponent :param value: the name of the master's attribute with which the value is synchronized (list of ints - indices of selected items) :type value: str :param labels: the name of the master's attribute with the list of items (as strings or tuples with icon and string) :type labels: str :param box: tells whether the widget has a border, and its label :type box: int or str or None :param callback: a function that is called when the selection state is changed :type callback: function :param selectionMode: selection mode - single, multiple etc :type selectionMode: QAbstractItemView.SelectionMode :param enableDragDrop: flag telling whether drag and drop is available :type enableDragDrop: bool :param dragDropCallback: callback function on drop event :type dragDropCallback: function :param dataValidityCallback: function that check the validity on enter and move event; it should return either `ev.accept()` or `ev.ignore()`. :type dataValidityCallback: function :param sizeHint: size hint :type sizeHint: QSize :rtype: OrangeListBox """ if box: bg = hBox(widget, box, addToLayout=False) else: bg = widget lb = OrangeListBox(master, enableDragDrop, dragDropCallback, dataValidityCallback, sizeHint, bg) lb.setSelectionMode(selectionMode) lb.ogValue = value lb.ogLabels = labels lb.ogMaster = master if labels is not None: setattr(master, labels, getdeepattr(master, labels)) master.connect_control(labels, CallFrontListBoxLabels(lb)) if value is not None: clist = getdeepattr(master, value) if not isinstance(clist, (int, ControlledList)): clist = ControlledList(clist, lb) master.__setattr__(value, clist) setattr(master, value, clist) connectControl(master, value, callback, lb.itemSelectionChanged, CallFrontListBox(lb), CallBackListBox(lb, master)) misc.setdefault('addSpace', True) miscellanea(lb, bg, widget, **misc) return lb