def __init__(self, parent=None, flags=QtCore.Qt.WindowFlags(0), **kwargs): super(QtBlinker, self).__init__(parent, flags, **kwargs) #qstyle = QtWidgets.QApplication.style() #pixmap = qstyle.standardPixmap(QtWidgets.QStyle.SP_MediaStop) pixmap = QtGui.QPixmap( ':/trolltech/styles/commonstyle/images/standardbutton-no-32.png') self.setPixmap(pixmap)
def openfile(self): self.scene.clear() self.graphicsview.setTransform(QtGui.QTransform()) filename = QtWidgets.QFileDialog.getOpenFileName() if filename: pixmap = QtGui.QPixmap(filename) item = self.scene.addPixmap(pixmap) self.scene.setSceneRect(item.boundingRect())
def setWorldmapItem(self, resolution='low'): scene = self.graphicsview.scene() if self.worldmapitem is not None: scene.removeItem(self.worldmapitem) #~ imgfile = qt4support.geticonfile('world_2160x1080.jpg', __name__) imgfile = qtsupport.geticonfile('world_4320x2160.jpg', __name__) #~ imgfile = qt4support.geticonfile('world_5400x2700.jpg', __name__) worldmap = QtGui.QPixmap(imgfile) worldmapitem = scene.addPixmap(worldmap) worldmapitem.setTransformationMode(QtCore.Qt.SmoothTransformation) # @NOTE: reverse the y axis worldmapitem.setTransform( QtGui.QTransform(360. / worldmap.width(), 0, 0, -180. / worldmap.height(), -180, 90)) self.worldmapitem = worldmapitem
def main(): # @IMPORTANT: force numeric locale to 'C' in order to avoid problems # with GDAL and PPROJ4 # @SEEALSO: http://trac.osgeo.org/gdal/wiki/FAQMiscellaneous#DoesGDALworkindifferentinternationalnumericlocales import os os.environ['LC_NUMERIC'] = 'C' args = parse_args() if args.log_level != 'NOTSET': loglevel = logging.getLevelName(args.log_level) else: loglevel = logging.INFO logging.basicConfig( level=loglevel, #format='%(levelname)s: %(message)s') format='%(asctime)s %(name)s %(levelname)s: %(message)s') # set the logging level explicitly on gsdview logger #logging.getLogger().setLevel(loglevel) logging.getLogger('gsdview').setLevel(loglevel) # PyQt loggers logging.getLogger('PyQt5.uic').setLevel(logging.WARNING) log = logging.getLogger(__name__) log.debug('log level set to %s', logging.getLevelName(log.level)) # @TODO: # * config logging using options.configfile, USER_CFG, SYS_CFG # * if options.debug: set rootlogger.level = logging.DEBUG # * maybe set loglevelfor other loggers timer = Timer() # splash screen ######################################################### from qtsix import QtWidgets, QtGui log.debug('Qt import: %d.%06ds', *timer.update()) import sys from gsdview.info import name as NAME from gsdview.info import version as VERSION from gsdview.utils import getresource app = QtWidgets.QApplication(sys.argv) app.setApplicationName(NAME) app.setApplicationVersion(VERSION) pngfile = getresource(os.path.join('images', 'splash.png'), __name__) pixmap = QtGui.QPixmap(pngfile) splash = QtWidgets.QSplashScreen(pixmap) splash.show() app.processEvents() splash_loghandler = SplashLogHandler(splash, app) splash_loghandler.setFormatter(logging.Formatter('%(message)s')) log.addHandler(splash_loghandler) log.info('Splash screen setup completed') log.debug('splash screen setup: %d.%06ds', *timer.update()) # modules loading ####################################################### preload(MODULES, app) # GUI ################################################################### log.info('Build GUI ...') from gsdview.app import GSDView # @TODO: pass plugins_path?? mainwin = GSDView(loglevel=args.log_level) mainwin.show() log.info('GUI setup completed') log.debug('GUI setup: %d.%06ds', *timer.update()) # close splash and run app ############################################## log.removeHandler(splash_loghandler) splash.finish(mainwin) app.processEvents() log.info('Install the exception hook') sys.excepthook = mainwin.excepthook # @TODO: check log.info('Enter main event loop') # @COMPATIBILITY: this will raise the window on Mac OS X mainwin.raise_() sys.exit(app.exec_())
def imgexport(obj, parent=None): filters = [ obj.tr('All files (*)'), obj.tr('Simple Vector Graphics file (*.svg)'), obj.tr('PDF file (*.pdf)'), obj.tr('PostScript file (*.ps)'), ] filters.extend('%s file (*.%s)' % ( str(fmt).upper(), str(fmt)) for fmt in QtGui.QImageWriter.supportedImageFormats()) formats = set( str(fmt).lower() for fmt in QtGui.QImageWriter.supportedImageFormats()) formats.update(('svg', 'pdf', 'ps')) # @TODO: check if parent is None: try: parent = obj.window() except AttributeError: parent = None target = os.path.join(utils.default_workdir(), 'image.jpeg') filename, filter_ = QtWidgets.QFileDialog.getSaveFileName( parent, obj.tr('Save picture'), target, ';;'.join(filters)) ext = 'unknown' while filename and (ext not in formats): ext = os.path.splitext(filename)[1] if ext: ext = ext[1:].lower() if ext in formats: break else: QtWidgets.QMessageBox.information( parent, obj.tr('Unknown file format'), obj.tr('Unknown file format "%s".\nPlease retry.') % ext) filename, filter_ = QtWidgets.QFileDialog.getSaveFileName( parent, obj.tr('Save draw'), filename, ';;'.join(filters), filter_) else: ext = 'unknown' if filename: if hasattr(obj, 'viewport'): srcsize = obj.viewport().rect().size() elif hasattr(obj, 'sceneRect'): # QGraphicsViews alsa has a viewport method so they should be # trapped by the previous check srcsize = obj.sceneRect().toRect().size() else: srcsize = QtWidgets.QSize(800, 600) if ext in ('pdf', 'ps'): device = QtPrintSupport.QPrinter(QtPrintSupport.QPrinter.HighResolution) device.setOutputFileName(filename) if ext == 'pdf': device.setOutputFormat(QtPrintSupport.QPrinter.PdfFormat) else: # ext == 'ps' device.setOutputFormat(QtPrintSupport.QPrinter.PostScriptFormat) elif ext == 'svg': device = QtSvg.QSvgGenerator() device.setFileName(filename) device.setSize(srcsize) #device.setViewBox(obj.sceneRect().toRect()) #device.setTitle(obj.tr('Graphics Draw')) #device.setDescription(obj.tr('Qt SVG drawing.')) else: device = QtGui.QPixmap(srcsize) # @TODO: check device.fill(QtCore.Qt.white) painter = QtGui.QPainter() if painter.begin(device): #painter.setRenderHint(QtGui.QPainter.Antialiasing) obj.render(painter) painter.end() if hasattr(device, 'save'): device.save(filename) else: QtWidgets.QMessageBox.warning( parent, obj.tr('Warning'), obj.tr('Unable initialize painting device.'))
def setLogo(self, logofile): self.gsdviewLogoLabel.setPixmap(QtGui.QPixmap(logofile))