def getpixel(self, x, y): _x = int((x + 0.5) * self.boxsize) _y = int((y + 0.5) * self.boxsize) qpx = QPixmap.grabWidget(self) image = QImage(qpx.toImage()) color = QColor(image.pixel(_x, _y)) return color
def mousePressEvent( self, event ): # handle an internal move # start a drag event if event.button() == Qt.LeftButton and self.dragDropRect().contains(event.pos()): # create the pixmap pixmap = QPixmap.grabWidget(self, self.rect()) # create the mimedata mimeData = QMimeData() mimeData.setText('ItemTitle::%s' % (self.title())) # create the drag drag = QDrag(self) drag.setMimeData(mimeData) drag.setPixmap(pixmap) drag.setHotSpot(event.pos()) if not drag.exec_(): self._accordianWidget.emitItemDragFailed(self) event.accept() # determine if the expand/collapse should occur elif event.button() == Qt.LeftButton and self.expandCollapseRect().contains(event.pos()): self._clicked = True event.accept() else: event.ignore()
def svgImage(svgfile, file=None): qs = QSvgWidget() qs.load(svgfile) qim = QPixmap.grabWidget(qs) bts = QByteArray() buffer = QBuffer(bts) buffer.open(QIODevice.WriteOnly) qim.save(buffer, "png") bts = buffer.data().data() buffer.close() if type(file) == str: assert os.path.splitext(file)[1].lower() == ".png" with open(file, "bw") as f: f.write(bts) elif hasattr(file, 'write'): file.write(bts) else: return bts
def grabWidget(w, x=0, y=0, width=-1, height=-1, **kwargs): """ @param w QWidget @param* x int @param* y int @param* width int @param* height int @param* path unicode @param* format str @param* clipboard bool whether save to clipboard @param* quality int @return bool """ if not w: return pm = QPixmap.grabWidget(w, x, y, width, height) return self.__d.savePixmap(pm, **kwargs)
def on_shot_button_clicked(self): self.image_label.setPixmap(QPixmap.grabWidget(self))
def do_copy(self): # Need this in case there's no navigation toolbar. pixmap = QPixmap.grabWidget(self.canvas) QApplication.clipboard().setPixmap(pixmap)
def do_copy(self): pixmap = QPixmap.grabWidget(self.canvas) QApplication.clipboard().setPixmap(pixmap)
def gen_sounding(self, *args): ''' Method for generating the SPC-like sounding using the SPCWindow class of SHARPpy. ''' self.log.info( 'Generating Skew-T diagram' ); # Log some information sndDataPNG = settings.skewT_fmt.format( self.date_str ); # Set the name for the skewT file using the settings.skew_T_fmt string self.sndDataPNG = os.path.join( self.dst_dirFull, sndDataPNG ); # Set the sndDataPNG attribute using the dst_dirFull attribute and sndDataFile variable save_msg = "Check that the image looks okay.\n " + \ "If ok, click save, else click cancel"; # Confirmation message for the save dialog for Skew-T; will update if cannot save Skew-T due to issue in SHARPpy sharppy_bug = False; # Flag for if sharppy bug encountered try: # Try to... decoder = SPCDecoder( self.sndDataFile ); # Decode the sounding file using the SPCDecoder profile = decoder.getProfiles(); # Get the profiles from the file stn_id = decoder.getStnId(); # Get the station id from the file except: # On exception criticalMessage( "There was an error loading the sounding data\n\n" ).exec_(); # Initialize and display critical error dialog return; # Return from method model = "Archive"; # Set model to 'Archive'; not sure why but was in the SHARPpy full_gui.py disp_name = stn_id; # Set the display name to the station ID from the sounding data file run = profile.getCurrentDate(); # Set the run to the current date from the sounding data profile.setMeta('model', model); # Set the model in the sounding data profile.setMeta('loc', disp_name); # Set the display name in the sounding data profile.setMeta('run', run); # Set the run in the sounding data if not profile.getMeta('observed'): # If it's not an observed profile profile.setAsync( AsyncThreads(2, debug) ); # Generate profile objects in background. Not sure why works but in SHARPpy full_gui.py self.log.debug('Generating SHARPpy window') if self.skew is None: # If there is no skew window setup; there should never be... self.skew = SPCWindow(cfg=self.config); # Initialize a new SPCWindow object self.skew.closed.connect(self.__skewAppClosed); # Connect the closed method to the __skewAppClosed private method self.skew.addProfileCollection(profile); # Add the profile data to the SPCWindow object try: self.skew.show(); # Show the window except: sharppy_bug = True; self.log.warning("SHARPpy didn't like that sounding very much!") save_msg = "Congradulations!\n\n" + \ "You just found a bug in SHARPpy.\n" + \ "There is nothing we can about this. No Skew-T can be created.\n" + \ "Just click 'Save' and continue with the uploading"; dial = saveMessage( save_msg ); # Set up save message pop-up dial.exec_(); # Display the save message pop-up if dial.check(): # If clicked save if not sharppy_bug: # If the SHARPpy bug did NOT occur self.ftpInfo['ucar']['files'].append( self.sndDataPNG ); # Append the SHARPpy image file name to the ftpInfo['ucar']['files'] list self.log.info('Saving the Skew-T to: {}'.format( self.sndDataPNG ) ); # Log some information pixmap = QPixmap.grabWidget( self.skew ); # Grab the image from the skew T window pixmap.save( self.sndDataPNG, 'PNG', 100); # Save the image self.config.set('paths', 'save_img', os.path.dirname(self.sndDataPNG)); # Add image path to the config object self.log.debug( 'Files to upload to UCAR: {}'.format( ', '.join(self.ftpInfo['ucar']['files']) ) ) self.genSucces.show(); # Show green light next to the 'Generate Sounding' button to indicate that step is complete self.uploadButton.setEnabled( True ); # Enable the upload button else: # Else self.log.critical('Skew-T save aborted! Not allowed to upload!'); # Log an error try: self.skew.close(); # Close the skew T window except: pass;
def screenshot_callback3(): window.show_presence_overview() screenshot = QPixmap.grabWidget(window) screenshot = QPixmap.grabWindow(QApplication.desktop().winId()) screenshot.save("screenshot-presence.png")
def screenshot_callback2(): window._qaction_triggered_FinancialKPIPanel() screenshot = QPixmap.grabWidget(window) screenshot.save("screenshot-financial.png")
def screenshot_callback(): screenshot = QPixmap.grabWidget(window) screenshot = QPixmap.grabWindow(QApplication.desktop().winId()) screenshot.save("screenshot-main.png")
def _get_image ( self ): return ImageResource( bitmap = QPixmap.grabWidget( self.control, 0, 0 ) )