Commit 294a34f7 authored by hejulian's avatar hejulian

add molo

parent 63db8e05
import sys
from PyQt5.QtGui import QApplication, QWidget, QToolButton, QLabel, QVBoxLayout, QHBoxLayout
class Widget(QWidget):
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.button_layout = QHBoxLayout()
self.widget_layout = QVBoxLayout()
for button_number in xrange(1, 11):
button = QToolButton()
button.setText(str(button_number))
button.setObjectName('Button%d' % button_number)
button.released.connect(self.button_released)
self.button_layout.addWidget(button)
self.status_label = QLabel('No button clicked')
self.widget_layout.addItem(self.button_layout)
self.widget_layout.addWidget(self.status_label)
self.setLayout(self.widget_layout)
def button_released(self):
sending_button = self.sender()
self.status_label.setText('%s Clicked!' % str(sending_button.objectName()))
if __name__ == '__main__':
app = QApplication(sys.argv)
widget = Widget()
image.png

1.69 KB | W: | H:

image.png

1.18 KB | W: | H:

image.png
image.png
image.png
image.png
  • 2-up
  • Swipe
  • Onion skin
mask.png

5.43 KB

import pygame, random
screen = pygame.display.set_mode((800,600))
draw_on = False
last_pos = (0, 0)
color = (255, 128, 0)
radius = 10
def roundline(srf, color, start, end, radius=1):
dx = end[0]-start[0]
dy = end[1]-start[1]
distance = max(abs(dx), abs(dy))
for i in range(distance):
x = int( start[0]+float(i)/distance*dx)
y = int( start[1]+float(i)/distance*dy)
pygame.draw.circle(srf, color, (x, y), radius)
try:
while True:
e = pygame.event.wait()
if e.type == pygame.QUIT:
raise StopIteration
if e.type == pygame.MOUSEBUTTONDOWN:
color = (random.randrange(256), random.randrange(256), random.randrange(256))
pygame.draw.circle(screen, color, e.pos, radius)
draw_on = True
if e.type == pygame.MOUSEBUTTONUP:
draw_on = False
if e.type == pygame.MOUSEMOTION:
if draw_on:
pygame.draw.circle(screen, color, e.pos, radius)
roundline(screen, color, e.pos, last_pos, radius)
last_pos = e.pos
pygame.display.flip()
except StopIteration:
pass
pygame.quit()
import sys
from PyQt5 import QtCore, QtGui, QtWidgets, uic
from PyQt5.QtCore import Qt
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap, QPainter, QPainterPath
from PyQt5.QtWidgets import QLabel, QWidget, QHBoxLayout, QApplication
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
class Canvas(QtWidgets.QLabel):
def __init__(self):
super().__init__()
def __init__(self, *args, antialiasing=True, **kwargs):
super(Canvas, self).__init__(*args, **kwargs)
self.radius = 25
self.width = 200
self.height = 200
pixmap = QtGui.QPixmap(self.width, self.height)
# pixmap = pixmap.scaled(self.width*5, self.height*5)
self.setPixmap(pixmap)
self.clear_screen()
self.target = QPixmap(self.width, self.height)
self.target.fill(Qt.GlobalColor.transparent)
p = QPixmap("mask.png")
painter = QPainter(self.target)
path = QPainterPath()
path.addRect(0, 0, self.width, self.height)
painter.setClipPath(path)
painter.drawPixmap(0, 0, p)
self.setPixmap(self.target)
#
# self.width = 200
# self.height = 200
# pixmap = QtGui.QPixmap(self.width, self.height)
# # pixmap = pixmap.scaled(self.width*5, self.height*5)
# self.setPixmap(pixmap)
# self.clear_screen()
self.last_x, self.last_y = None, None
self.pen_color = QtGui.QColor('#a42f3b')
def set_pen_color(self, c):
print(c)
self.pen_color = QtGui.QColor(c)
......@@ -25,8 +55,20 @@ class Canvas(QtWidgets.QLabel):
def clear_screen(self):
empty = np.zeros((self.width, self.height))
self.pixmap().fill(Qt.GlobalColor.transparent)
p = QPixmap("mask.png")
painter = QPainter(self.target)
path = QPainterPath()
path.addRect(0, 0, self.width, self.height)
painter.setClipPath(path)
painter.drawPixmap(0, 0, p)
self.setPixmap(self.target)
self.update()
# self.report_pixels()
self.report_pixels()
def report_pixels(self):
......@@ -49,13 +91,14 @@ class Canvas(QtWidgets.QLabel):
return # Ignore the first time.
painter = QtGui.QPainter(self.pixmap())
painter.setCompositionMode(QtGui.QPainter.CompositionMode_DestinationOver)
p = painter.pen()
p.setWidth(5)
p.setWidth(10)
p.setColor(self.pen_color)
painter.setPen(p)
painter.drawLine(self.last_x, self.last_y, e.x(), e.y())
# self.report_pixels()
self.report_pixels()
painter.end()
self.update()
......
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap, QPainter, QPainterPath
from PyQt5.QtWidgets import QLabel, QWidget, QHBoxLayout, QApplication
class Label(QLabel):
def __init__(self, *args, antialiasing=True, **kwargs):
super(Label, self).__init__(*args, **kwargs)
self.Antialiasing = antialiasing
self.setMaximumSize(50, 50)
self.setMinimumSize(50, 50)
self.radius = 25
self.target = QPixmap(self.size())
self.target.fill(Qt.transparent)
p = QPixmap("mask.png").scaled(
50, 50, Qt.KeepAspectRatioByExpanding, Qt.SmoothTransformation)
painter = QPainter(self.target)
if self.Antialiasing:
painter.setRenderHint(QPainter.Antialiasing, True)
painter.setRenderHint(QPainter.HighQualityAntialiasing, True)
painter.setRenderHint(QPainter.SmoothPixmapTransform, True)
path = QPainterPath()
path.addRoundedRect(
0, 0, self.width(), self.height(), self.radius, self.radius)
painter.setClipPath(path)
painter.drawPixmap(0, 0, p)
self.setPixmap(self.target)
class Window(QWidget):
def __init__(self, *args, **kwargs):
super(Window, self).__init__(*args, **kwargs)
layout = QHBoxLayout(self)
layout.addWidget(Label(self))
layout.addWidget(Label(self, antialiasing=False))
self.setStyleSheet("background: blue;")
if __name__ == "__main__":
app = QApplication(sys.argv)
w = Window()
w.show()
sys.exit(app.exec_())
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment