def initGui(self) -> None: # Create action that will start plugin self.action = QAction(QIcon(":/plugins/"), "About Server GetLegendGraphicTitle", self.iface.mainWindow()) # Add toolbar button and menu item self.iface.addPluginToMenu("Server GetLegendGraphicTitle", self.action) # connect the action to the run method QObject.connect(self.action, SIGNAL("activated()"), self.about)
def start_polling(self): if not self.is_logged_in: try: self.login() except HANDLED_EXCEPTIONS as exc: self._handle_exception(exc) if not self.is_logged_in: return self.refresh_calc_list() self.timer = QTimer() QObject.connect( self.timer, SIGNAL('timeout()'), self.refresh_calc_list) self.timer.start(5000) # refresh calc list time in milliseconds
def __init__(self, driver_dialog, calc_id): QDialog.__init__(self) # Set up the user interface from Designer. self.setupUi(self) self.driver_dialog = driver_dialog self.calc_id = calc_id # when re-opening the dialog for a calculation, display the log from # the beginning self.driver_dialog.calc_log_line[calc_id] = 0 self.timer = QTimer() QObject.connect( self.timer, SIGNAL('timeout()'), self.refresh_calc_log) self.timer.start(1000) # refresh time in milliseconds # show the log before the first iteration of the timer self.refresh_calc_log()
def connect_button_to_action(self, button, action, output, outtype): if action in ('Load as layer', 'Show', 'Aggregate'): style = 'background-color: blue; color: white;' if action == 'Load as layer': button.setText("Load layer") elif action == 'Aggregate': button.setText("Aggregate") else: button.setText("Show") else: style = 'background-color: #3cb3c5; color: white;' button.setText("%s %s" % (action, outtype)) button.setStyleSheet(style) QObject.connect( button, SIGNAL("clicked()"), lambda output=output, action=action, outtype=outtype: ( self.on_output_action_btn_clicked(output, action, outtype)) )
def refresh_calc_list(self): # returns True if the list is correctly retrieved calc_list_url = "%s/v1/calc/list?relevant=true" % self.hostname with WaitCursorManager(): try: # FIXME: enable the user to set verify=True resp = self.session.get( calc_list_url, timeout=10, verify=False, allow_redirects=False) if resp.status_code == 302: raise RedirectionError( "Error %s loading %s: please check the url" % ( resp.status_code, resp.url)) if not resp.ok: raise ServerError( "Error %s loading %s: %s" % ( resp.status_code, resp.url, resp.reason)) except HANDLED_EXCEPTIONS as exc: self._handle_exception(exc) return False calc_list = json.loads(resp.text) selected_keys = [ 'description', 'id', 'calculation_mode', 'owner', 'status'] col_names = [ 'Description', 'Job ID', 'Calculation Mode', 'Owner', 'Status'] col_widths = [340, 60, 135, 70, 80] if not calc_list: if self.calc_list_tbl.rowCount() > 0: self.calc_list_tbl.clearContents() self.calc_list_tbl.setRowCount(0) else: self.calc_list_tbl.setRowCount(0) self.calc_list_tbl.setColumnCount(len(col_names)) self.calc_list_tbl.setHorizontalHeaderLabels(col_names) self.calc_list_tbl.horizontalHeader().setStyleSheet( "font-weight: bold;") self.set_calc_list_widths(col_widths) return False actions = [ {'label': 'Console', 'bg_color': '#3cb3c5', 'txt_color': 'white'}, {'label': 'Remove', 'bg_color': '#d9534f', 'txt_color': 'white'}, {'label': 'Outputs', 'bg_color': '#3cb3c5', 'txt_color': 'white'}, {'label': 'Continue', 'bg_color': 'white', 'txt_color': 'black'} ] self.calc_list_tbl.clearContents() self.calc_list_tbl.setRowCount(len(calc_list)) self.calc_list_tbl.setColumnCount(len(selected_keys) + len(actions)) for row, calc in enumerate(calc_list): for col, key in enumerate(selected_keys): item = QTableWidgetItem() try: value = calc_list[row][key] except KeyError: # from engine2.5 to engine2.6, job_type was changed into # calculation_mode. This check prevents the plugin to break # wnen using an old version of the engine. if key == 'calculation_mode': value = 'unknown' else: # if any other unexpected keys are used, it is safer to # raise a KeyError raise item.setData(Qt.DisplayRole, value) # set default colors row_bg_color = Qt.white row_txt_color = Qt.black if calc['status'] == 'failed': row_bg_color = QColor('#f2dede') elif calc['status'] == 'complete': row_bg_color = QColor('#dff0d8') item.setBackgroundColor(row_bg_color) item.setTextColor(row_txt_color) self.calc_list_tbl.setItem(row, col, item) for col, action in enumerate(actions, len(selected_keys)): # display the Continue and Output buttons only if the # computation is completed if (calc['status'] != 'complete' and action['label'] in ('Continue', 'Outputs')): continue button = QPushButton() button.setText(action['label']) style = 'background-color: %s; color: %s' % ( action['bg_color'], action['txt_color']) button.setStyleSheet(style) QObject.connect( button, SIGNAL("clicked()"), lambda calc_id=calc['id'], action=action['label']: ( self.on_calc_action_btn_clicked(calc_id, action))) self.calc_list_tbl.setCellWidget(row, col, button) self.calc_list_tbl.setColumnWidth(col, BUTTON_WIDTH) empty_col_names = [''] * len(actions) headers = col_names + empty_col_names self.calc_list_tbl.setHorizontalHeaderLabels(headers) self.calc_list_tbl.horizontalHeader().setStyleSheet( "font-weight: bold;") self.set_calc_list_widths(col_widths) if self.pointed_calc_id: self.highlight_and_scroll_to_calc_id(self.pointed_calc_id) # if a running calculation is selected, the corresponding outputs will # be displayed (once) automatically at completion if (self.pointed_calc_id and self.output_list_tbl.rowCount() == 0): self.update_output_list(self.pointed_calc_id) return True