def capture(self): screenshot = QScreen.grabWindow(app.primaryScreen(), widget.winId(), 0, 0, 800, 1080) msg = QMessageBox() msg.setWindowFlag(Qt.WindowStaysOnTopHint) msg.setIconPixmap(QPixmap(screenshot)) msg.setText('저장 하시겠습니까?') msg.setStandardButtons(QMessageBox.No | QMessageBox.Yes) x = msg.exec_() if x == QMessageBox.Yes: name = self.name.text() captured_img = path + name + ext screenshot.save(captured_img) _, _, col, error_col = access_db() with open(captured_img, "rb") as data: photo = data.read() try: id = fr.face_encodings(fr.load_image_file(captured_img), model='large')[0] data = {'name': name, 'id': id.tolist(), 'photo': photo} col.insert_one(data) print('저장 완료!! : ', name) except IndexError: error_col.insert_one({'name': name}) os.remove(captured_img) print('warning! face not detected! : ', name) # client.close() else: pass
def grab_new_img(self): self.loadImg = QScreen.grabWindow(QApplication.primaryScreen(), QApplication.desktop().winId()) self.capturedImg = QPixmap() self.screenWidth = self.loadImg.width() self.screenHeight = self.loadImg.height() self.isMousePressed = False self.beginPoint = QPoint(0, 0) self.endPoint = QPoint(0, 0)
def configure_to_dpi(self, screen: QtGui.QScreen): """Set an appropriately sized font size depending on the screen DPI. If we end up needing to generalize this more here there are resources listed in the script in ``snippets/qt_screen_info.py``. """ # take the max since scaling can make things ugly in some cases pdpi = screen.physicalDotsPerInch() ldpi = screen.logicalDotsPerInch() dpi = max(pdpi, ldpi) font_size = math.floor(self._iwl * dpi) log.info(f"\nscreen:{screen.name()} with DPI: {dpi}" f"\nbest font size is {font_size}\n") self._set_qfont_px_size(font_size) self._physical_dpi = dpi self._screen = screen
def __init__(self): super().__init__() self.screen_width = QScreen.size(QApplication.primaryScreen()).width() self.screen_height = QScreen.size( QApplication.primaryScreen()).height() self.setFixedSize(self.screen_width, self.screen_height) #set scale based on relation to 1080p self.scale = self.screen_width / 1080 self.showFullScreen() self.active_world = None self.pressed_keys = set() self.mouse_keys = set() self.mouse_released = set() self.mouse_up_instant = set() self.run_thread = self.RunThread(self) self.run_thread.start()
def shot_board(app) -> str: screen = QScreen.grabWindow(app.primaryScreen(), QApplication.desktop().winId()) board_rect = QRect(QPoint(*config.BOARD_POINT), QSize(config.BOARD_SIZE, config.BOARD_SIZE)) board = screen.copy(board_rect) filename = '{}.png'.format(next(tempfile._get_candidate_names())) filepath = os.path.join(tempfile._get_default_tempdir(), filename) board.save(filepath) return filepath
def mouseMoveEvent(self, e): """This method is executed while the click button is held""" if self.last_x is None: self.last_x = e.x() self.last_y = e.y() return painter = QPainter(self.label.pixmap()) painter.drawLine(self.last_x, self.last_y, e.x(), e.y()) painter.end() self.update() # Updating the origin for next time self.last_x = e.x() self.last_y = e.y() # Saving the screenshot and compressing it to a 28x28 image QScreen.grabWindow(self.App.primaryScreen(), self.winId()).save( "hd_recognition/tmp/screenshot.png", 'png') resize_img = Image.open("hd_recognition/tmp/screenshot.png") resize_img = resize_img.resize((28, 28)) resize_img.save("hd_recognition/tmp/screenshot.png", 'png') # Converting from standard png to greyscale img_array = np.array(Image.open("hd_recognition/tmp/screenshot.png")) img_array = np.array([[pixel[0] for pixel in line] for line in img_array]) image_array = 1 - (img_array.reshape(784, 1) / 255) # Predicting the number model_activations = self.tkinter_root.model_file.feedforward( image_array) # Prediction plot frame prediction_frame = tk.LabelFrame(self.tkinter_root) prediction_frame.grid(row=2, column=2) # Plotting the model activations self.tkinter_root.plot_model_activation(model_activations, prediction_frame)
def screenshot(app): screen = QScreen.grabWindow(app.primaryScreen(), QApplication.desktop().winId()) board_rect = QRect(QPoint(*config.BOARD_POINT), QSize(config.BOARD_SIZE, config.BOARD_SIZE)) size = config.CELL_SIZE board = screen.copy(board_rect) # int x, int y, int width, int height for i in range(8): for j in range(8): r = QRect(i * size, j * size, size, size) c = board.copy(r) c.save(f'./pieces/{i}{j}.png')
def _grab_screen(screen_idx, screen): screen_geom = QDesktopWidget().screenGeometry(screen_idx) return ( screen_geom, QScreen.grabWindow( screen, QApplication.desktop().winId(), screen_geom.x(), screen_geom.y(), screen.size().width(), screen.size().height() ) )
def shoot(rect): imgname = randomString() app = QApplication(sys.argv) img = QScreen.grabWindow(app.primaryScreen(), QApplication.desktop().winId()) imgCrop = img.copy(rect).save(imgname + '.png', 'png') path = '/home/webserver/webroot/img/' + imgname + '.png' localpath = imgname + '.png' print(imgname) filename = randomString() with pysftp.Connection("serwm.com", username="******", password="") as sftp: sftp.put(localpath, path) toClipBoard(imgname) quit()
def screenShot(self, filename, filetype): """ Takes a screenshot of the whole gui window, saves png and ps images to file :param filename: (str) Directory string of where to save the file :param filetype: (str) String of the filetype to save :return: """ s = str(filename) + "." + str(filetype) p = QScreen.grabWindow(self.Form.winId()) p.save(s, 'png') # im = Image.open(s) # im.save(s[:-4]+".ps") p = p.scaled(465, 400) # save again a small image to use for the logbook thumbnail p.save(str(s[:-4]) + "_sm.png", 'png')
#!/usr/bin/python3 # -*- coding: utf-8 -*- import sys from PyQt5.QtWidgets import QApplication, QMainWindow from PyQt5.QtCore import QUrl from PyQt5.QtQuick import QQuickView from PyQt5.QtQml import QQmlApplicationEngine from PyQt5.QtGui import QScreen if __name__ == "__main__": app = QApplication(sys.argv) engine = QQmlApplicationEngine() engine.load('basic.qml') view = engine.rootObjects()[0] # view.setSource(QUrl('basic.qml')) view.show() print(QScreen().physicalDotsPerInch()) sys.exit(app.exec_())
import sys from PyQt5.QtGui import QPixmap, QColor, QScreen from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget app = QApplication(sys.argv) w = QWidget() # img is QImage type img = QScreen.grabWindow( w.winId(), x=00, y=100, width=20, height=20, ).toImage() for x in range(0, 20): for y in range(0, 20): c = img.pixel(x, y) colors = QColor(c).getRgbF() print("(%s,%s) = %s" % (x, y, colors))