def mouseMoveEvent(self, event): super(GaugeWidgetVertical, self).mouseMoveEvent(event) y_start = self.height() - (self._minVal - self._lower) * self._step * self.scale y_end = self.height() - (self._maxVal - self._lower) * self._step * self.scale if y_start < event.y() or event.y() < y_end: self.setCursor(QCursor(QtCore.Qt.SizeVerCursor)) else: self.setCursor(QCursor(QtCore.Qt.ArrowCursor)) if event.buttons() == QtCore.Qt.LeftButton: if self._lastMouseY != None: diff = self._lastMouseY - event.y() if diff != 0: if self._moving: new_min = self._minVal * self.scale + diff * 1 / self._step new_max = self._maxVal * self.scale + diff * 1 / self._step if new_min < new_max: self._minVal = new_min / self.scale self._maxVal = new_max / self.scale elif self._resizingTop: new_max = self._maxVal * self.scale + diff * 1 / self._step if self._minVal < (new_max / self.scale): self._maxVal = new_max / self.scale elif self._resizingBottom: new_min = self._minVal * self.scale + diff * 1 / self._step if (new_min / self.scale) < self._maxVal: self._minVal = new_min / self.scale self.repaint() self.changed_event() self._lastMouseY = event.y()
def mouseMoveEvent(self, event): super(GaugeWidgetVertical, self).mouseMoveEvent(event) x_start = (self._minVal - self._lower) * self._step * self.scale x_end = (self._maxVal - self._lower) * self._step * self.scale # set the cursors if x_start >= event.x() or event.x() >= x_end: self.setCursor(QCursor(QtCore.Qt.SizeHorCursor)) else: self.setCursor(QCursor(QtCore.Qt.ArrowCursor)) if event.buttons() == QtCore.Qt.LeftButton: if self._lastMouseY != None: diff = self._lastMouseY - event.x() if diff != 0: if self._moving: new_min = self._minVal * self.scale - diff * 1 / self._step new_max = self._maxVal * self.scale - diff * 1 / self._step if new_min < new_max: self._minVal = new_min / self.scale self._maxVal = new_max / self.scale elif self._resizingLeft: new_max = self._maxVal * self.scale - diff * 1 / self._step if self._minVal < (new_max / self.scale): self._maxVal = new_max / self.scale elif self._resizingRight: new_min = self._minVal * self.scale - diff * 1 / self._step if (new_min / self.scale) < self._maxVal: self._minVal = new_min / self.scale self.repaint() self.changed_event() self._lastMouseY = event.x()
def mouseMoveEvent(self, event): super(TimelineWidget, self).mouseMoveEvent(event) self.parent_control.mouse_moveover_timeline_event(event) self._mouse_current_pos = event.x(), event.y() # Do nothing if no event bar is selected if self._selected is None: return # Set cursors if self._selected.canSlideBegin( event.x(), event.y()) or self._selected.canSlideEnd( event.x(), event.y()): self.setCursor(QCursor(QtCore.Qt.SizeHorCursor)) elif self._selected.collide(event.x(), event.y()): self.setCursor(QCursor(QtCore.Qt.SizeAllCursor)) else: self.setCursor(QCursor(QtCore.Qt.ArrowCursor)) if self._selected is None: return if event.buttons() == QtCore.Qt.LeftButton: if self._lastMouseY is not None: diff = event.x() - self._lastMouseY if diff != 0: if self._moving: self._selected.move(diff, event.y()) elif self._resizingBegin: self._selected.moveBegin(diff) elif self._resizingEnd: self._selected.moveEnd(diff) self.repaint() self._lastMouseY = event.x()
def _repaint(self, index): row, column = index.row(), index.column() if column in (Column.remove, Column.scheme): self.setCursor(QCursor(Qt.PointingHandCursor)) else: self.setCursor(QCursor(Qt.ArrowCursor)) if row >= 0: self.model().item(row, Column.remove).setIcon(self._icon_remove) self.model().item(row, Column.scheme).setIcon(self._icon_scheme)
def mouseMoveEvent(self, event): """ Event called when the mouse is moved :param event: Mouse move event. """ super(TimelineWidget, self).mouseMoveEvent(event) self.control.mouse_moveover_timeline_event(event) xcoord, ycoord = event.x(), event.y() self._mouse_current_pos = xcoord, ycoord # Do nothing if no event bar is selected if self._selected is None: return # set cursors if self._selected.can_slide_begin(xcoord, ycoord) or \ self._selected.can_slide_end(xcoord, ycoord): # resize cursor. self.setCursor(QCursor(QtCore.Qt.SizeHorCursor)) elif self._selected.collide(xcoord, ycoord): # move cursor self.setCursor(QCursor(QtCore.Qt.SizeAllCursor)) else: # normal cursor self.setCursor(QCursor(QtCore.Qt.ArrowCursor)) if event.buttons() == QtCore.Qt.LeftButton: # move the period if self._last_mousex is not None: diff = xcoord - self._last_mousex if diff != 0: if self._moving: # move the selected period self._selected.move(diff, ycoord) elif self._resizing_began: # resize the beginning of the period self._selected.move_begin(diff) elif self._resizing_ended: # resize the end of the period self._selected.move_end(diff) self.repaint() self._last_mousex = xcoord
def setCursor(self, cursor): if self._cursor != cursor: self._cursor = QCursor(cursor) self.cursorChanged.emit()
def cursor(self): return QCursor(self._cursor)
def get_table(self): if self.tablecombo.currentIndex() <= 0: if self.database_desc: self.database_desc["Table"] = "(None)" self.data_desc_table = None return if self.tablecombo.currentIndex() < self.tablecombo.count() - 1: self.table = self.tablemodel[self.tablecombo.currentIndex()] self.database_desc["Table"] = self.table if "Query" in self.database_desc: del self.database_desc["Query"] else: self.sql = self.table = self.sqltext.toPlainText() if self.materialize: import psycopg2 if not self.materialize_table_name: self.Error.connection( "Specify a table name to materialize the query") return try: with self.backend.execute_sql_query( "DROP TABLE IF EXISTS " + self.materialize_table_name): pass with self.backend.execute_sql_query( "CREATE TABLE " + self.materialize_table_name + " AS " + self.table): pass with self.backend.execute_sql_query( "ANALYZE " + self.materialize_table_name): pass self.table = self.materialize_table_name except (psycopg2.ProgrammingError, BackendError) as ex: self.Error.connection(str(ex)) return try: table = SqlTable(dict(host=self.host, port=self.port, database=self.database, user=self.username, password=self.password), self.table, backend=type(self.backend), inspect_values=False) except BackendError as ex: self.Error.connection(str(ex)) return self.Error.connection.clear() sample = False if table.approx_len() > LARGE_TABLE and self.guess_values: confirm = QMessageBox(self) confirm.setIcon(QMessageBox.Warning) confirm.setText("Attribute discovery might take " "a long time on large tables.\n" "Do you want to auto discover attributes?") confirm.addButton("Yes", QMessageBox.YesRole) no_button = confirm.addButton("No", QMessageBox.NoRole) sample_button = confirm.addButton("Yes, on a sample", QMessageBox.YesRole) confirm.exec() if confirm.clickedButton() == no_button: self.guess_values = False elif confirm.clickedButton() == sample_button: sample = True self.Information.clear() if self.guess_values: QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) if sample: s = table.sample_time(1) domain = s.get_domain(inspect_values=True) self.Information.data_sampled() else: domain = table.get_domain(inspect_values=True) QApplication.restoreOverrideCursor() table.domain = domain if self.download: if table.approx_len() > MAX_DL_LIMIT: QMessageBox.warning( self, 'Warning', "Data is too big to download.\n" "Consider using the Data Sampler widget to download " "a sample instead.") self.download = False elif table.approx_len() > AUTO_DL_LIMIT: confirm = QMessageBox.question( self, 'Question', "Data appears to be big. Do you really " "want to download it to local memory?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if confirm == QMessageBox.No: self.download = False if self.download: table.download_data(MAX_DL_LIMIT) table = Table(table) return table
def __init__(self, graph, enable_menu=False): self.mousestate = 0 self.point_i = None self.cursor = QCursor() super().__init__(graph, enable_menu)