def addTestImage(self, color_image): self.ocr_areas = OCRAreasFinder(color_image, self.settings["contrast"]) self.market_width = self.ocr_areas.market_width self.valid_market = self.ocr_areas.valid if self.settings['gray_preview']: img = cv2.imread( unicode(self.hiddentext).encode(sys.getfilesystemencoding()), 0) img = array2qimage(img) pix = QPixmap.fromImage(img) else: pix = QPixmap(self.hiddentext) width = pix.width() height = pix.height() if height > 0: aspect_ratio = float(width) / height if aspect_ratio > 1.78: new_w = int(1.77778 * height) rect = QRect((width - new_w) / 2, 0, new_w, height) pix = pix.copy(rect) if self.valid_market: points = self.ocr_areas.market_table self.market_offset = (points[0][0], points[0][1]) station = self.ocr_areas.station_name self.station_offset = (station[0][0], station[0][1]) rect = QRect(0, 0, points[1][0] + 20, points[1][1] + 20) cut = pix.copy(rect) return cut else: self.market_offset = (0, 0) self.station_offset = (0, 0) return pix
class StartSelectView(QGraphicsView): def __init__(self, *args): QGraphicsView.__init__(self, *args) self.move(2, 250) self.btnSize = 28 self.setMaximumHeight(self.btnSize * 2) self.setMaximumWidth(334) self.setMinimumHeight(self.btnSize * 2) self.setMinimumWidth(334) self.adjustSize() self.scene = QGraphicsScene(self) self.setStyleSheet('background-color:transparent; border-width: 0px; border: 0px;') self.psButtons = QPixmap(os.getcwd() + '/../icons/controller-sprite.png') self.select = self.psButtons.copy(696, 120, 45, 30) self.select = self.select.scaled(self.btnSize, self.btnSize, Qt.KeepAspectRatio) self.selectItem = QGraphicsPixmapItem(self.select) self.selectItem.setOffset(QPointF(0, 0)) self.scene.addItem(self.selectItem) self.start = self.psButtons.copy(754, 120, 45, 30) self.start = self.start.scaled(self.btnSize, self.btnSize, Qt.KeepAspectRatio) self.startItem = QGraphicsPixmapItem(self.start) self.startItem.setOffset(QPointF(86, 0)) self.scene.addItem(self.startItem) self.setScene(self.scene)
def addTestImage(self, color_image): self.ocr_areas = OCRAreasFinder(color_image, self.settings["contrast"]) self.market_width = self.ocr_areas.market_width self.valid_market = self.ocr_areas.valid if self.settings['gray_preview']: img = cv2.imread(unicode(self.hiddentext).encode(sys.getfilesystemencoding()), 0) img = array2qimage(img) pix = QPixmap.fromImage(img) else: pix = QPixmap(self.hiddentext) width = pix.width() height = pix.height() if height > 0: aspect_ratio = float(width)/height if aspect_ratio > 1.78: new_w = int(1.77778*height) rect = QRect((width-new_w)/2, 0, new_w, height) pix = pix.copy(rect) if self.valid_market: points = self.ocr_areas.market_table self.market_offset = (points[0][0], points[0][1]) station = self.ocr_areas.station_name self.station_offset = (station[0][0], station[0][1]) rect = QRect(0, 0, points[1][0] + 20, points[1][1] + 20) cut = pix.copy(rect) return cut else: self.market_offset = (0, 0) self.station_offset = (0, 0) return pix
def addTestImage(self, color_image): self.ocr_areas = OCRAreasFinder(color_image, self.settings["contrast"]) self.market_width = self.ocr_areas.market_width self.valid_market = self.ocr_areas.valid img = QPixmap(self.hiddentext) width = img.width() height = img.height() aspect_ratio = float(width)/height if aspect_ratio > 1.78: new_w = int(1.77778*height) rect = QRect((width-new_w)/2, 0, new_w, height) img = img.copy(rect) if self.valid_market: points = self.ocr_areas.market_table self.market_offset = (points[0][0], points[0][1]) station = self.ocr_areas.station_name self.station_offset = (station[0][0], station[0][1]) rect = QRect(0, 0, points[1][0] + 20, points[1][1] + 20) cut = img.copy(rect) return cut else: self.market_offset = (0, 0) self.station_offset = (0, 0) return img
class FaceButtonsView(QGraphicsView): def __init__(self, *args): QGraphicsView.__init__(self, *args) self.move(170, 90) self.btnSize = 40 self.padding = 5 self.setMaximumHeight(self.btnSize * 4) self.setMaximumWidth(self.btnSize * 4) self.setMinimumHeight(self.btnSize * 4) self.setMinimumWidth(self.btnSize * 4) self.adjustSize() self.setStyleSheet('background-color:transparent; border-width: 0px; border: 0px;') self.scene = QGraphicsScene(self) self.psButtons = QPixmap(os.getcwd() + '/../icons/PS3_Buttons.png') self.triangle = self.psButtons.copy(0, 0, 220, 225) self.triangle = self.triangle.scaled(self.btnSize, self.btnSize, Qt.KeepAspectRatio) self.square = self.psButtons.copy(220, 0, 220, 225) self.square = self.square.scaled(self.btnSize, self.btnSize, Qt.KeepAspectRatio) self.circle = self.psButtons.copy(440, 0, 220, 225) self.circle = self.circle.scaled(self.btnSize, self.btnSize, Qt.KeepAspectRatio) self.cross = self.psButtons.copy(660, 0, 220, 225) self.cross = self.cross.scaled(self.btnSize, self.btnSize, Qt.KeepAspectRatio) self.triangleItem = QGraphicsPixmapItem(self.triangle) self.triangleItem.setOffset(QPointF(self.btnSize + self.padding, 0)) self.scene.addItem(self.triangleItem) self.squareItem = QGraphicsPixmapItem(self.square) self.squareItem.setOffset(QPointF(0, self.btnSize + self.padding)) self.scene.addItem(self.squareItem) self.circleItem = QGraphicsPixmapItem(self.circle) self.circleItem.setOffset(QPointF(self.btnSize * 2 + self.padding * 2, self.btnSize + self.padding)) self.scene.addItem(self.circleItem) self.crossItem = QGraphicsPixmapItem(self.cross) self.crossItem.setOffset(QPointF(self.btnSize + self.padding, self.btnSize * 2 + self.padding * 2)) self.scene.addItem(self.crossItem) self.effect = QGraphicsDropShadowEffect() self.effect.setOffset(0, 0) self.effect.setBlurRadius(20) self.effect.setColor(Qt.green) self.triangleItem.setGraphicsEffect(self.effect) self.setScene(self.scene) self.tl2 = QTimeLine(10000) self.tl2.setFrameRange(0, 10000) self.t = QGraphicsItemAnimation() self.t.setItem(self.triangleItem) self.t.setTimeLine(self.tl2) self.tl2.connect(self.tl2, SIGNAL('frameChanged(int)'), self.updateEffect) self.effectd = 3 self.tl2.start() def updateEffect(self): if self.effect.blurRadius() > 50: self.effectd = -3 elif self.effect.blurRadius() < 5: self.effectd = 3 self.effect.setBlurRadius(self.effect.blurRadius() + self.effectd)
def __init_widgets__(self): """ Initialise the widgets of the window. """ # The Address/Attachment portion of the window self.attach_model = MessageAttachmentModel() attach_list = QListView() attach_list.setModel(self.attach_model) tab_bar_pxm = QPixmap('res/msg_tabbar_r.png') self.tab_bar = QTabWidget() self.tab_bar.setTabPosition(2) self.tab_bar.setIconSize(QSize(16, 16)) self.tab_bar.addTab(QWidget(), QIcon(tab_bar_pxm.copy(0, 0, 16, 16)), '') self.tab_bar.addTab(attach_list, QIcon(tab_bar_pxm.copy(0, 16, 16, 16)), '') # The Composition Properties portion of the window self.subject_line = QLineEdit() self.subject_line.setPlaceholderText('Subject') QObject.connect(self.subject_line, SIGNAL('textEdited(QString)'), self.update_title) priority_label = QLabel('Priority:') priority_dropdown = QComboBox(self) priority_dropdown.addItems( ['Highest', 'High', 'Normal', 'Low', 'Lowest']) subject_prio_layout = QHBoxLayout() subject_prio_layout.addWidget(self.subject_line) # subject_prio_layout.addStretch(1) subject_prio_layout.addWidget(priority_label) subject_prio_layout.addWidget(priority_dropdown) # The actual Composition portion of the window self.message = MessageTextEdit(self) # The bottom pane bottom_pane_layout = QVBoxLayout() bottom_pane_layout.addLayout(subject_prio_layout) bottom_pane_layout.addWidget(self.message) bottom_pane = QWidget() bottom_pane.setLayout(bottom_pane_layout) # Central widget is the splitter splitter = QSplitter() splitter.setOrientation(2) splitter.addWidget(self.tab_bar) splitter.addWidget(bottom_pane) self.setCentralWidget(splitter)
def __set_cover(self): pixmap = QPixmap(self._local_cover_path) pixmap = pixmap.scaled(self.ui.pushButtonCover.iconSize(), QtCore.Qt.KeepAspectRatioByExpanding, QtCore.Qt.SmoothTransformation) pixmap_size = self.ui.pushButtonCover.iconSize() pixmap = pixmap.copy(0,0,pixmap_size.width(), pixmap_size.height()) cover = QIcon(pixmap) self.ui.pushButtonCover.setIcon(cover)
def __init_actions__(self): """ Initialise the actions (menus/toolbar) of the window. """ menu_bar = self.menuBar() message_menu = menu_bar.addMenu('&Message') toolbar = self.addToolBar('Message actions') toolbar_pxm = QPixmap('res/msg_toolbar.png') send_action = QAction(QIcon(toolbar_pxm.copy(0, 0, 23, 20)), 'Send', self) send_action.setShortcut('Ctrl+Enter') send_action.setStatusTip('Send the message now') QObject.connect(send_action, SIGNAL('triggered()'), self.send_message) message_menu.addAction(send_action) toolbar.addAction(send_action) # defer_action = QAction('Send Later', self) # defer_action.setStatusTip('Queue the message for deferred delivery') # QObject.connect(defer_action, SIGNAL('triggered()'), self.send_deferred) # message_menu.addAction(defer_action) quote_action = QAction(QIcon(toolbar_pxm.copy(23, 0, 23, 20)), 'Quote', self) quote_action.setStatusTip( 'Paste the current clipboard text as a quoted snippet') QObject.connect(quote_action, SIGNAL('triggered()'), self.paste_quote) message_menu.addAction(quote_action) toolbar.addAction(quote_action) address_action = QAction(QIcon(toolbar_pxm.copy(46, 0, 23, 20)), 'Address', self) address_action.setEnabled(False) address_action.setStatusTip( 'Opens the Address Book to select recipients for the message') QObject.connect(address_action, SIGNAL('triggered()'), self.show_addresses) message_menu.addAction(address_action) toolbar.addAction(address_action) attach_action = QAction(QIcon('res/msg_attach.png'), 'Attach', self) attach_action.setStatusTip('Attach one or more files to the message') QObject.connect(attach_action, SIGNAL('triggered()'), self.show_attach_ui) message_menu.addAction(attach_action) toolbar.addAction(attach_action)
def __set_cover(self): pixmap = QPixmap(self._local_cover_path) pixmap = pixmap.scaled(self.ui.pushButtonCover.iconSize(), QtCore.Qt.KeepAspectRatioByExpanding, QtCore.Qt.SmoothTransformation) pixmap_size = self.ui.pushButtonCover.iconSize() pixmap = pixmap.copy(0, 0, pixmap_size.width(), pixmap_size.height()) cover = QIcon(pixmap) self.ui.pushButtonCover.setIcon(cover)
def __init__(self, *args): ControllerView.__init__(self, *args) self.setStyleSheet('background-color:transparent; border-width: 0px; border: 0px;') self.setMinimumHeight(500) self.setMaximumHeight(500) self.setMinimumWidth(400) self.setMaximumWidth(400) self.setContentsMargins(0, 0, 0, 0) self.adjustSize() bumpers = ButtonGroup(20,0,75,0,1) facebtns = ButtonGroup(160,70,35,0) dpad = ButtonGroup(0,60,25,0) midbtns = ButtonGroup(80,170,40,0) js = ButtonGroup(0,180,75,0) facesprite = QPixmap(os.path.dirname(__file__) + '/../buttons/PS3_Buttons.png') sprite = QPixmap(os.path.dirname(__file__) + '/../icons/controller-sprite.png') self.btns = Map({'l1' : Button('l1.png', group=bumpers, pos=Button.LEFT), 'r1' : Button('r1.png', group=bumpers, pos=Button.RIGHT), 'r2' : Meterbar(255, width=5, x=270), 'l2' : Meterbar(255, width=5), 'select' : Button(sprite.copy(696, 120, 45, 30), group=midbtns, pos=Button.LEFT, width=34), 'start' : Button(sprite.copy(754, 120, 45, 30), group=midbtns, pos=Button.RIGHT, width=34), 'ps' : Button('ps.png', group=midbtns, pos=Button.BOTTOM, width=35), 'up' : Button('up.png', group=dpad, pos=Button.TOP), 'right' : Button('right.png', group=dpad, pos=Button.RIGHT), 'down' : Button('down.png', group=dpad, pos=Button.BOTTOM), 'left' : Button('left.png', group=dpad, pos=Button.LEFT), 'tri' : Button(facesprite.copy(0, 0, 220, 225), group=facebtns, pos=Button.TOP, width=35), 'cir' : Button(facesprite.copy(440, 0, 220, 225), group=facebtns, pos=Button.RIGHT, width=35), 'squ' : Button(facesprite.copy(220, 0, 220, 225), group=facebtns, pos=Button.LEFT, width=35), 'cro' : Button(facesprite.copy(660, 0, 220, 225), group=facebtns, pos=Button.BOTTOM, width=35),}) self.joysticks = Map({'left': Joystick(125, 40, group=js, pos=Button.LEFT), 'right': Joystick(125, 40, group=js, pos=Button.RIGHT)}) self.scene = QGraphicsScene(self) for btn in self.btns.itervalues() : btn.setScene(self.scene) for joystick in self.joysticks.itervalues() : joystick.setScene(self.scene) self.setScene(self.scene) self.worker = QSixAxisThread(self) self.worker.input.connect(self.update) self.worker.start()
def __init__(self, image_path, sprite_width, sprite_height, label): pixmap = QPixmap(image_path) width, height = pixmap.width(), pixmap.height() self.pixmaps = [] for x in range(0, width, sprite_width): for y in range(0, height, sprite_height): self.pixmaps.append(pixmap.copy(x, y, sprite_width, sprite_height)) self._current_frame = 0 self.label = label
def __init__(self, data, encoding, x0, y0, x1, y1, xsize, ysize): p = QPixmap() p.loadFromData(data, encoding, Qt.AutoColor) w, h = p.width(), p.height() p = p.copy(x0, y0, min(w, x1-x0), min(h, y1-y0)) if p.width() != xsize or p.height() != ysize: p = p.scaled(xsize, ysize, Qt.IgnoreAspectRatio, Qt.SmoothTransformation) QGraphicsPixmapItem.__init__(self, p) self.height, self.width = ysize, xsize self.setTransformationMode(Qt.SmoothTransformation) self.setShapeMode(QGraphicsPixmapItem.BoundingRectShape)
def __init__(self, data, encoding, x0, y0, x1, y1, xsize, ysize): p = QPixmap() p.loadFromData(data, encoding, Qt.AutoColor) w, h = p.width(), p.height() p = p.copy(x0, y0, min(w, x1 - x0), min(h, y1 - y0)) if p.width() != xsize or p.height() != ysize: p = p.scaled(xsize, ysize, Qt.IgnoreAspectRatio, Qt.SmoothTransformation) QGraphicsPixmapItem.__init__(self, p) self.height, self.width = ysize, xsize self.setTransformationMode(Qt.SmoothTransformation) self.setShapeMode(QGraphicsPixmapItem.BoundingRectShape)
def paint_pixmap(self, widget): assert self.last_canvas_rect is not None x1, y1 = self.last_canvas_rect.left(), self.last_canvas_rect.top() x2, y2 = self.last_canvas_rect.right(), self.last_canvas_rect.bottom() NX = x2 - x1 NY = y2 - y1 pix = QPixmap(NX, NY) painter = QPainter(pix) painter.begin(widget) try: self.draw_border(painter, self.last_xmap, self.last_ymap, self.last_canvas_rect) self.draw_image(painter, self.last_canvas_rect, self.last_src_rect, self.last_dst_rect, self.last_xmap, self.last_xmap) # somehow guiqwt paints a distorted border at left/top, so we remove it: return pix.copy(2, 2, NX - 2, NY - 2) finally: painter.end()
def paint_pixmap(self, widget): assert self.last_canvas_rect is not None x1, y1 = self.last_canvas_rect.left(), self.last_canvas_rect.top() x2, y2 = self.last_canvas_rect.right(), self.last_canvas_rect.bottom() NX = x2 - x1 NY = y2 - y1 pix = QPixmap(NX, NY) painter = QPainter(pix) painter.begin(widget) try: self.draw_border(painter, self.last_xmap, self.last_ymap, self.last_canvas_rect) self.draw_image(painter, self.last_canvas_rect, self.last_src_rect, self.last_dst_rect, self.last_xmap, self.last_xmap) # somehow guiqwt paints a distorted border at left/top, so we remove it: return pix.copy(2, 2, NX - 2, NY - 2) finally: painter.end()
def _runCropStep(self): if self._debug: debug('Crop') self._step = Georeferencer.Crop self._args = [] self._command = '' pixmap = QPixmap(self._rawFile.absoluteFilePath()) if pixmap.isNull(): self._signalError('Loading of raw image failed.') return pixmap = pixmap.copy(0, 0, pixmap.width(), int(pixmap.height() * 0.84)) image = pixmap.toImage() if image.isNull(): self._signalError('Cropping of raw image failed.') return if not image.save(self._cropFile.absoluteFilePath(), 'PNG', 100): self._signalError('Saving of cropped image failed.') return self._signalStatus() self._runTranslateStep()
def crop_pixmaps(path, mask, pretend=False): """ crop all pixmaps in a dir according to a masks. This function does nothing in regards to validating modules. If the pixmaps exist and an entry exists in masks, the pixmaps get chopped. """ from PyQt4.QtGui import QPixmap for fname in os.listdir(path): if extension(fname) == 'png': fpath = os.path.join(path, fname) pixmap = QPixmap(fpath) x, y, w, h = mask[0], mask[1], mask[2], mask[3] if pixmap.isNull() is False and \ pixmap.width() > w and \ pixmap.height() > h: pixmap = pixmap.copy(x, y, w, h) if pretend: print 'PRETEND:', else: pixmap.save(fpath, 'PNG') print 'wrote %s x=%i y=%i w=%i h=%i' % (fpath, x, y, w, h)