def __del__(self): import sip if not sip.isdeleted(self.__process): log.debug("X11CommandWidget: __del__ terminates x11...") self.terminate() else: log.debug("X11CommandWidget: __del__ does nothing...")
def createWidget(self, parent): try: w = self.getWidgetClass()(parent=parent) except Exception: log.error("Designer plugin error creating %s " \ "(see debug stream for details)", self.name()) log.debug("Details:", exc_info=1) w = None return w
def grabWidget(widget, fileName, period=None): """Grabs the given widget into the given image filename. If period is None (default) it grabs immediately once and returns. If period is given and >0 means grab the image every period (in seconds). .. warning:: this method **MUST** be called from the same thread which created the widget :param widget: the Qt widget to be grabbed :type widget: QtWidget :param fileName: the name of the image file :type fileName: str :param period: period (seconds) :type period: float """ if period is None: widgetName = widget.objectName() widgetTitle = widget.windowTitle() log.debug("Grabbing widget '%s' to '%s':", widgetName, fileName) try: pixmap = QtGui.QPixmap.grabWidget(widget) if fileName.endswith(".svg"): import qarbon.external.qt.QtSvg generator = qarbon.external.qt.QtSvg.QSvgGenerator() generator.setFileName(fileName) generator.setSize(pixmap.size()) if hasattr(generator, "setViewBox"): viewBox = QtCore.QRect(QtCore.QPoint(0, 0), pixmap.size()) generator.setViewBox(viewBox) title = "Qarbon widget" if widgetTitle: title += " - " + widgetTitle elif widgetName: title += " - " + widgetName desc = "An SVG created by the qarbon widget grabber" generator.setTitle(title) generator.setDescription(desc) painter = QtGui.QPainter() painter.begin(generator) try: painter.drawPixmap(0, 0, -1, -1, pixmap) finally: painter.end() else: pixmap.save(fileName, quality=100) except Exception: log.warning("Could not save file into '%s':", fileName) log.debug("Details:", exc_info=1) ret = __GrabberThread(widget, fileName, period) ret.start() return ret
def grabWidget(widget, fileName, period=None): """Grabs the given widget into the given image filename. If period is None (default) it grabs immediately once and returns. If period is given and >0 means grab the image every period (in seconds). .. warning:: this method **MUST** be called from the same thread which created the widget :param widget: the Qt widget to be grabbed :type widget: QtWidget :param fileName: the name of the image file :type fileName: str :param period: period (seconds) :type period: float """ if period is None: widgetName = widget.objectName() widgetTitle = widget.windowTitle() log.debug("Grabbing widget '%s' to '%s':", widgetName, fileName) try: pixmap = QtGui.QPixmap.grabWidget(widget) if fileName.endswith('.svg'): import qarbon.external.qt.QtSvg generator = qarbon.external.qt.QtSvg.QSvgGenerator() generator.setFileName(fileName) generator.setSize(pixmap.size()) if hasattr(generator, 'setViewBox'): viewBox = QtCore.QRect(QtCore.QPoint(0, 0), pixmap.size()) generator.setViewBox(viewBox) title = "Qarbon widget" if widgetTitle: title += " - " + widgetTitle elif widgetName: title += " - " + widgetName desc = "An SVG created by the qarbon widget grabber" generator.setTitle(title) generator.setDescription(desc) painter = QtGui.QPainter() painter.begin(generator) try: painter.drawPixmap(0, 0, -1, -1, pixmap) finally: painter.end() else: pixmap.save(fileName, quality=100) except Exception: log.warning("Could not save file into '%s':", fileName) log.debug("Details:", exc_info=1) ret = __GrabberThread(widget, fileName, period) ret.start() return ret
def __setPyQt4API(element, api_version=2): try: ver = sip.getapi(element) except ValueError: ver = -1 if ver < 0: try: sip.setapi(element, api_version) log.debug("%s API set to version %d", element, sip.getapi("QString")) except ValueError: log.warning("Error setting %s API to version %s", element, api_version, exc_info=1) return False elif ver < api_version: log.info("%s API set to version %s (advised: version >= %s)", element, ver, api_version) return True
def initialize(self, formEditor): """Overwrite if necessary. Don"t forget to call this method in case you want the generic extensions in your widget.""" if self.isInitialized(): return if self.isContainer(): log.debug("[start] registering container extension for %s...", self.name()) container_extension = self.getContainerExtensionClass() registerExtension(ExtensionType.ContainerExtension, self.getWidgetClass(), container_extension) manager = formEditor.extensionManager() self.__extension_factory = QarbonWidgetExtensionFactory(manager) manager.registerExtensions(self.__extension_factory, ExtensionType.ContainerExtension.value) log.debug("[ done] registering container extension for %s", self.name()) self.__initialized = True
def _getQObjectStr(qobject, representation): if qobject is None: return 'Null' if representation == QObjectRepresentation.ClassName: return qobject.__class__.__name__ try: objectName = qobject.objectName() except RuntimeError: log.error("error accessing object %s", qobject) log.debug("details: ", exc_info=1) if representation == QObjectRepresentation.ClassName: return qobject.__class__.__name__ else: return "> ERROR! <" if representation == QObjectRepresentation.ObjectName: return objectName elif representation == QObjectRepresentation.FullName: className = qobject.metaObject().className() return '{0}("{1}")'.format(className, objectName) return str(qobject)
# ---------------------------------------------------------------------------- # This file is part of qarbon (http://qarbon.rtfd.org/) # # Copyright (c) 2013 European Synchrotron Radiation Facility, Grenoble, France # # Distributed under the terms of the GNU Lesser General Public License, # either version 3 of the License, or (at your option) any later version. # See LICENSE.txt for more info. # ---------------------------------------------------------------------------- from qarbon import log log.initialize(log_level="debug") from qarbon.qt.gui.x11 import XTermWidget from qarbon.qt.gui.application import Application log.debug("first message")
def deleteLater(self): log.debug("X11CommandWidget: deleteLater...") self.terminate(wait=-1) return super(XCommandWidget, self).deleteLater()