def closeEvent(self, event): self.tick_timer.stop() self.tick_timer.timeout.disconnect() self.canvasWidget.shoutDown() # save editor config settings = QtCore.QSettings(SETTINGS_PATH, QtCore.QSettings.IniFormat, self) # clear file each time to capture opened dock tools settings.clear() settings.sync() settings.beginGroup('Editor') settings.setValue("geometry", self.saveGeometry()) settings.setValue("state", self.saveState()) settings.endGroup() # save tools state settings.beginGroup('Tools') for tool in self._tools: if isinstance(tool, ShelfTool): settings.beginGroup("ShelfTools") settings.beginGroup(tool.name()) tool.saveState(settings) settings.endGroup() settings.endGroup() if isinstance(tool, DockTool): settings.beginGroup("DockTools") settings.beginGroup(tool.uniqueName()) tool.saveState(settings) settings.endGroup() settings.endGroup() tool.onDestroy() settings.endGroup() settings.sync() QMainWindow.closeEvent(self, event)
def __init__(self, widget, title, icon=None, uid=None, parent=None): super(BootStrapWidget, self).__init__(parent=parent) self._preferred_size = self.PREFERRED_SIZE # This cannot be an empty string, otherwise Maya will get crazy uid = uid or title or 'BootstrapWidget' global BOOTSTRAP_WIDGETS BOOTSTRAP_WIDGETS[uid] = self # This was causing the dock widge to disappear after creation # Not sure why, maybe because the id had - characters, or because maybe there was a widget with the same # objectName, for now no setting an objectName seems to work fine # self.setObjectName(uid) self.setWindowTitle(title) if icon: self.setWindowIcon(icon) self._docking_frame = QMainWindow(self) self._docking_frame.layout().setContentsMargins(0, 0, 0, 0) self._docking_frame.setWindowFlags(Qt.Widget) self._docking_frame.setDockOptions(QMainWindow.AnimatedDocks) self.central_widget = widget self._docking_frame.setCentralWidget(self.central_widget) bootstrap_layout = layouts.VerticalLayout(spacing=0, margins=(0, 0, 0, 0)) bootstrap_layout.addWidget(self._docking_frame, 0) self.setLayout(bootstrap_layout) widget.setProperty('bootstrapWidget', self)
def paintEvent(self, event): QMainWindow.paintEvent(self, event) if not self.line.isNull(): painter = QPainter(self) pen = QPen(Qt.red, 3) painter.setPen(pen) painter.drawLine(self.line)
def __init__(self): QMainWindow.__init__(self) self.setMinimumSize(QSize(300, 300)) pybutton = QPushButton('button', self) pybutton.clicked.connect(self.draw_line) pybutton.resize(100, 100) pybutton.move(100, 100) self.line = QLine()
def closeEvent(self, event): self.tick_timer.stop() self.tick_timer.timeout.disconnect() self.G.shoutDown() # save editor config settings = QtCore.QSettings(SETTINGS_PATH, QtCore.QSettings.IniFormat, self) settings.beginGroup('Editor') settings.setValue("geometry", self.saveGeometry()) settings.setValue("windowState", self.saveState()) settings.endGroup() QMainWindow.closeEvent(self, event)
def main(): import sys app = QApplication(sys.argv) acmeSeries = QBoxPlotSeries() acmeSeries.setName("Acme Ltd") boxWhiskSeries = QBoxPlotSeries() boxWhiskSeries.setName("BoxWhisk Inc") acmeData = QFile(":acme") if not acmeData.open(QIODevice.ReadOnly | QIODevice.Text): sys.exit(1) dataReader = BoxDataReader(acmeData) while not dataReader.atEnd(): _set = dataReader.readBox() if _set is not None: acmeSeries.append(_set) boxwhiskData = QFile(":boxwhisk") if not boxwhiskData.open(QIODevice.ReadOnly | QIODevice.Text): sys.exit(1) dataReader.readFile(boxwhiskData) while not dataReader.atEnd(): _set = dataReader.readBox() if _set is not None: boxWhiskSeries.append(_set) chart = QChart() chart.addSeries(acmeSeries) chart.addSeries(boxWhiskSeries) chart.setTitle("Acme Ltd and BoxWhisk Inc share deviation in 2012") chart.setAnimationOptions(QChart.SeriesAnimations) chart.createDefaultAxes() chart.axes(Qt.Vertical)[0].setMin(15.0) chart.axes(Qt.Vertical)[0].setMax(34.0) chart.legend().setVisible(True) chart.legend().setAlignment(Qt.AlignBottom) chartView = QChartView(chart) chartView.setRenderHint(QPainter.Antialiasing) window = QMainWindow() window.setCentralWidget(chartView) window.resize(800, 600) window.show() sys.exit(app.exec_())
def main(): import sys app = QApplication(sys.argv) set0 = QBarSet("Jane") set1 = QBarSet("John") set2 = QBarSet("Axel") set3 = QBarSet("Mary") set4 = QBarSet("Samantha") set0 << 1 << 2 << 3 << 4 << 5 << 6 set1 << 5 << 0 << 0 << 4 << 0 << 7 set2 << 3 << 5 << 8 << 13 << 8 << 5 set3 << 5 << 6 << 7 << 3 << 4 << 5 set4 << 9 << 7 << 5 << 3 << 1 << 2 series = QBarSeries() series.append(set0) series.append(set1) series.append(set2) series.append(set3) series.append(set4) chart = QChart() chart.addSeries(series) chart.setTitle("Simple barchart example") chart.setAnimationOptions(QChart.SeriesAnimations) categories = ("Jan", "Feb", "Mar", "Apr", "May", "Jun") axisX = QBarCategoryAxis() axisX.append(categories) chart.addAxis(axisX, Qt.AlignBottom) series.attachAxis(axisX) axisY = QValueAxis() axisY.setRange(0, 15) chart.addAxis(axisY, Qt.AlignLeft) series.attachAxis(axisY) chart.legend().setVisible(True) chart.legend().setAlignment(Qt.AlignBottom) chartView = QChartView(chart) chartView.setRenderHint(QPainter.Antialiasing) window = QMainWindow() window.setCentralWidget(chartView) window.resize(420, 300) window.show() sys.exit(app.exec_())
def get_dpi(value=1): """ Returns current DPI used by DCC :param value: float :return: float """ qt_dpi = QApplication.devicePixelRatio() if is_batch() else QMainWindow( ).devicePixelRatio() return qt_dpi * value
def main(): import sys a = QApplication(sys.argv) acmeSeries = QCandlestickSeries() acmeSeries.setName("Acme Ltd") acmeSeries.setIncreasingColor(QColor(Qt.green)) acmeSeries.setDecreasingColor(QColor(Qt.red)) acmeData = QFile(":acme") if not acmeData.open(QIODevice.ReadOnly | QIODevice.Text): sys.exit(1) categories = [] dataReader = CandlestickDataReader(acmeData) while not dataReader.atEnd(): _set = dataReader.readCandlestickSet() if _set is not None: acmeSeries.append(_set) categories.append( QDateTime.fromMSecsSinceEpoch(int( _set.timestamp())).toString("dd")) chart = QChart() chart.addSeries(acmeSeries) chart.setTitle("Acme Ltd Historical Data (July 2015)") chart.setAnimationOptions(QChart.SeriesAnimations) chart.createDefaultAxes() axisX = chart.axes(Qt.Horizontal)[0] axisX.setCategories(categories) axisY = chart.axes(Qt.Vertical)[0] axisY.setMax(axisY.max() * 1.01) axisY.setMin(axisY.min() * 0.99) chart.legend().setVisible(True) chart.legend().setAlignment(Qt.AlignBottom) chartView = QChartView(chart) chartView.setRenderHint(QPainter.Antialiasing) window = QMainWindow() window.setCentralWidget(chartView) window.resize(800, 600) window.show() sys.exit(a.exec_())
def main(): import sys app = QApplication(sys.argv) series0 = QLineSeries() series1 = QLineSeries() series0 << QPointF(1, 5) << QPointF(3, 7) << QPointF(7, 6) << QPointF( 9, 7) << QPointF(12, 6) << QPointF(16, 7) << QPointF(18, 5) series1 << QPointF(1, 3) << QPointF(3, 4) << QPointF(7, 3) << QPointF( 8, 2) << QPointF(12, 3) << QPointF(16, 4) << QPointF(18, 3) series = QAreaSeries(series0, series1) series.setName("Batman") pen = QPen(0x059605) pen.setWidth(3) series.setPen(pen) gradient = QLinearGradient(QPointF(0, 0), QPointF(0, 1)) gradient.setColorAt(0.0, QColor(0x3CC63C)) gradient.setColorAt(1.0, QColor(0x26F626)) gradient.setCoordinateMode(QGradient.ObjectBoundingMode) series.setBrush(gradient) chart = QChart() chart.addSeries(series) chart.setTitle("Simple areachart example") chart.createDefaultAxes() chart.axes(Qt.Horizontal)[0].setRange(0, 20) chart.axes(Qt.Vertical)[0].setRange(0, 10) chartView = QChartView(chart) chartView.setRenderHint(QPainter.Antialiasing) window = QMainWindow() window.setCentralWidget(chartView) window.resize(400, 300) window.show() sys.exit(app.exec_())
def __init__(self, parent=None): QMainWindow.__init__(self, parent) self.data = ParticleData() toolbar = self.addToolBar("Test") openButton = QPushButton("") openButton.setFlat(True) openButton.setIconSize(QSize(32, 32)) openButton.setIcon(QIcon("/jobs2/soft/icons/dlight/open.png")) openButton.setToolTip("Open File") toolbar.addWidget(openButton) openButton.clicked.connect(self.openSlot) QShortcut(QKeySequence(Qt.CTRL + Qt.Key_O), self, self.openSlot) saveButton = QPushButton("") saveButton.setFlat(True) saveButton.setIconSize(QSize(32, 32)) saveButton.setIcon(QIcon("/jobs2/soft/icons/dlight/file_save.png")) saveButton.setToolTip("Save File") toolbar.addWidget(saveButton) saveButton.clicked.connect(self.saveSlot) QShortcut(QKeySequence(Qt.CTRL + Qt.Key_S), self, self.saveSlot) saveDeltaButton = QPushButton("") saveDeltaButton.setFlat(True) saveDeltaButton.setIconSize(QSize(32, 32)) saveDeltaButton.setIcon( QIcon("/jobs2/soft/icons/dlight/file_save_as.png")) saveDeltaButton.setToolTip("Save File As Delta") toolbar.addWidget(saveDeltaButton) saveDeltaButton.clicked.connect(self.saveDeltaSlot) QShortcut(QKeySequence(Qt.CTRL + Qt.SHIFT + Qt.Key_S), self, self.saveDeltaSlot) addParticleButton = QPushButton("Particle") addParticleButton.setFlat(True) addParticleButton.setIconSize(QSize(32, 32)) addParticleButton.setIcon(QIcon("/jobs2/soft/icons/shared/plus.png")) addParticleButton.setToolTip("Add Particle") toolbar.addWidget(addParticleButton) addParticleButton.clicked.connect(self.addParticleSlot) addAttributeButton = QPushButton("Attribute") addAttributeButton.setFlat(True) addAttributeButton.setIconSize(QSize(32, 32)) addAttributeButton.setIcon(QIcon("/jobs2/soft/icons/shared/plus.png")) addAttributeButton.setToolTip("Add Attribute") toolbar.addWidget(addAttributeButton) addAttributeButton.clicked.connect(self.addAttributeSlot) splitter = QSplitter(self) self.setCentralWidget(splitter) particleTable = ParticleTableWidget(self.data, self) splitter.addWidget(particleTable) right = QWidget(self) splitter.addWidget(right) vbox = QVBoxLayout(right) right.setLayout(vbox) fixedAttrWidget = FixedAttributesWidget(self.data, self) vbox.addWidget(fixedAttrWidget) indexedStrings = IndexedStringsWidget(self.data, self) vbox.addWidget(indexedStrings) vbox.addStretch() # TODD: SCROLLABLE AREAS FOR EVERYTHING self.data.dirtied.connect(self.dataDirtiedSlot) # Configure ctrl-w to close the window QShortcut(QKeySequence(Qt.CTRL + Qt.Key_W), self, self.close)
class BootStrapWidget(maya.app.general.mayaMixin.MayaQWidgetDockableMixin, QWidget): width = maya.cmds.optionVar(query='workspacesWidePanelInitialWidth') * 0.75 INITIAL_SIZE = QSize(width, 600) PREFERRED_SIZE = QSize(width, 420) MINIMUM_SIZE = QSize((width * 0.95), 220) def __init__(self, widget, title, icon=None, uid=None, parent=None): super(BootStrapWidget, self).__init__(parent=parent) self._preferred_size = self.PREFERRED_SIZE # This cannot be an empty string, otherwise Maya will get crazy uid = uid or title or 'BootstrapWidget' global BOOTSTRAP_WIDGETS BOOTSTRAP_WIDGETS[uid] = self # This was causing the dock widge to disappear after creation # Not sure why, maybe because the id had - characters, or because maybe there was a widget with the same # objectName, for now no setting an objectName seems to work fine # self.setObjectName(uid) self.setWindowTitle(title) if icon: self.setWindowIcon(icon) self._docking_frame = QMainWindow(self) self._docking_frame.layout().setContentsMargins(0, 0, 0, 0) self._docking_frame.setWindowFlags(Qt.Widget) self._docking_frame.setDockOptions(QMainWindow.AnimatedDocks) self.central_widget = widget self._docking_frame.setCentralWidget(self.central_widget) bootstrap_layout = layouts.VerticalLayout(spacing=0, margins=(0, 0, 0, 0)) bootstrap_layout.addWidget(self._docking_frame, 0) self.setLayout(bootstrap_layout) widget.setProperty('bootstrapWidget', self) def __del__(self, *args, **kwargs): """ Overriding to do nothing to avoid C++ object already deleted error since they try to destroy the workspace after its QObject has already been deleted """ pass def setSizeHint(self, size): self._preferred_size = size def close(self, *args, **kwargs): """ Overridden to call the bootstrap user widget.close() """ self.central_widget.close() super(BootStrapWidget, self).close(*args, **kwargs) def show(self, **kwargs): name = self.objectName() name = name + "WorkspaceControl" if maya.cmds.workspaceControl(name, query=True, exists=True): maya.cmds.deleteUI(name) maya.cmds.workspaceControlState(name, remove=True) kwargs["retain"] = False kwargs["uiScript"] = 'try: from tpDcc.dccs.maya.ui import window;window.rebuild("{}")\n' \ 'except ImportError: pass'.format(self.objectName()) kwargs["closeCallback"] = 'try: from tpDcc.dccs.maya.ui import window;window.bootstrap_destroy_window("{}")\n' \ 'except ImportError: pass'.format(self.objectName()) super(BootStrapWidget, self).show(**kwargs)
def __init__(self, parent=None): QMainWindow.__init__(self, parent) self.data = ParticleData() toolbar = self.addToolBar("Test") openButton = QPushButton("") openButton.setFlat(True) openButton.setIconSize( QSize(32, 32) ) openButton.setIcon(QIcon("/jobs2/soft/icons/dlight/open.png")) openButton.setToolTip( "Open File" ) toolbar.addWidget(openButton) openButton.clicked.connect(self.openSlot) QShortcut( QKeySequence(Qt.CTRL + Qt.Key_O), self, self.openSlot ) saveButton = QPushButton("") saveButton.setFlat(True) saveButton.setIconSize( QSize(32, 32) ) saveButton.setIcon(QIcon("/jobs2/soft/icons/dlight/file_save.png")) saveButton.setToolTip( "Save File" ) toolbar.addWidget(saveButton) saveButton.clicked.connect(self.saveSlot) QShortcut( QKeySequence(Qt.CTRL + Qt.Key_S), self, self.saveSlot ) saveDeltaButton = QPushButton("") saveDeltaButton.setFlat(True) saveDeltaButton.setIconSize( QSize(32, 32) ) saveDeltaButton.setIcon(QIcon("/jobs2/soft/icons/dlight/file_save_as.png")) saveDeltaButton.setToolTip( "Save File As Delta" ) toolbar.addWidget(saveDeltaButton) saveDeltaButton.clicked.connect(self.saveDeltaSlot) QShortcut( QKeySequence(Qt.CTRL + Qt.SHIFT + Qt.Key_S), self, self.saveDeltaSlot ) addParticleButton = QPushButton("Particle") addParticleButton.setFlat(True) addParticleButton.setIconSize( QSize(32, 32) ) addParticleButton.setIcon(QIcon("/jobs2/soft/icons/shared/plus.png")) addParticleButton.setToolTip( "Add Particle" ) toolbar.addWidget(addParticleButton) addParticleButton.clicked.connect(self.addParticleSlot) addAttributeButton = QPushButton("Attribute") addAttributeButton.setFlat(True) addAttributeButton.setIconSize( QSize(32, 32) ) addAttributeButton.setIcon(QIcon("/jobs2/soft/icons/shared/plus.png")) addAttributeButton.setToolTip( "Add Attribute" ) toolbar.addWidget(addAttributeButton) addAttributeButton.clicked.connect(self.addAttributeSlot) splitter = QSplitter(self) self.setCentralWidget(splitter) particleTable = ParticleTableWidget(self.data, self) splitter.addWidget(particleTable) right = QWidget(self) splitter.addWidget(right) vbox = QVBoxLayout(right) right.setLayout(vbox) fixedAttrWidget = FixedAttributesWidget(self.data, self) vbox.addWidget(fixedAttrWidget) indexedStrings = IndexedStringsWidget(self.data, self) vbox.addWidget(indexedStrings) vbox.addStretch() # TODD: SCROLLABLE AREAS FOR EVERYTHING self.data.dirtied.connect(self.dataDirtiedSlot) # Configure ctrl-w to close the window QShortcut( QKeySequence(Qt.CTRL + Qt.Key_W), self, self.close )