def paintGL(self): if self.doReset: # and not (self.size().width() == 100 and self.size().width() == 30): debug(showFunc=True) self.reset() # debug(self.size(), name='paper size', color=3) # Reset the background color # glClear(GL_COLOR_BUFFER_BIT) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # debug(self.lines, showFile=True) # debug(self.focusLoc, self.lines, self.dots) self.drawBackground() self.drawDots() self.drawBounds() self.drawLines() self.drawCurrentLine() self.drawFocus() # glColor(*clampColor(self.boundsColor)) # self.drawCircle(self.centerPoint.asGL(), self.focusRadius) #* Resets the current matrix # glLoadIdentity() glFlush()
def eventFilter(self, target, event): if event.type() == QEvent.KeyPress and event.key() == Qt.Key_Return and target is self: debug() event.accept() self.returnPressed.emit() return True else: return super().eventFilter(target, event)
def getFile(*_): got = typeFunc(*params) debug(got) if not len(got) or not len(got[0]): return else: self.file = got if len(got[0]) == 1 else got[0] self.setText(self.file)
def setBackground(selector): debug(selector) if selector == "Color": self.paper.background = self.optionsMenu.backgroundColor.getColor( ) elif selector == "Pattern": todo('figure out how to select a pattern/gradient') self.paper.background = self.optionsMenu.backgroundColor.getColor( ) elif selector == "Image": self.paper.background = self.optionsMenu.backgroundPath.file elif selector == "Map Image": todo('get an image from the map') self.paper.background = (255, 160, 100, 255) else: raise UserWarning( "Something has gone horribly, horribly wrong.")
def meme(): url = QtCore.QUrl.fromLocalFile( '/home/marvin/Downloads/Rick-Astley-Never-Gonna-Give-You-Up.mp3') content = QtMultimedia.QMediaContent(url) player = QtMultimedia.QMediaPlayer() player.setMedia(content) player.play() meme = uic.loadUi(join(DATA, 'meme.ui')) debug(meme) pixmap = QPixmap( "/home/marvin/hello/python/GeoDoodle/Qt_Version/GeoDoodle/paulblart.png" ) scene = QGraphicsScene(meme) item = QGraphicsPixmapItem(pixmap) scene.addItem(item) meme.graphicsView.setScene(scene) meme.show()
def eventFilter(self, target, event): #* For some reason, this is the first point after initialization that the width/height are correct if self.doReset and self.size().width() != 100 and self.size().height( ) != 30: debug(showFunc=True) self.reset() if target == self: if event.type() in (QEvent.MouseMove, QEvent.DragMove, QEvent.HoverMove): self.updateMouse(event) self.dragButtons[int(event.buttons())] = True self.update() if event.type() == QEvent.MouseButtonPress: if int(event.buttons()) == Qt.LeftButton: self.createLine() elif int(event.buttons()) == Qt.RightButton: self.createLine(True) elif int(event.buttons()) == Qt.MiddleButton: self.deleteLine() debug(self.mouseLoc, color=2) if event.type() == QEvent.MouseButtonRelease: if self.dragButtons[int(event.button())]: self.dragButtons[int(event.button())] = False if event.button() & (Qt.RightButton | Qt.LeftButton): self.createLine( linkAnother=int(event.button()) == Qt.RightButton) if event.type() == QEvent.MouseButtonDblClick: if int(event.buttons()) == Qt.LeftButton: self.createLine(True) elif int(event.buttons()) == Qt.RightButton: self.createLine(True) return super().eventFilter(target, event)
def _repeatMenu(self): class PatternMenu(QDialog): def __init__(self, *args, pattern=None, **kwargs): super().__init__(*args, **kwargs) assert pattern uic.loadUi(join(UI, "repeat.ui"), self) self.pattern = pattern self.setWindowTitle('Repeat Pattern') self.setModal(True) #* Set the minimum values for the sliders self.xOffset.setMinimum(-self.pattern.size[0] + 1) self.yOffset.setMinimum(-self.pattern.size[1] + 1) #* If you want to by default set the new color to black self.paper.currentDrawColor = (0, 0, 0) #* Connect the sliders manually, since they have nessicary parameters self.xOffset.sliderMoved.connect( lambda pos: self.update(xpos=pos)) self.yOffset.sliderMoved.connect( lambda pos: self.update(ypos=pos)) #* Fill the flip drop down menus self.flipRowOrientation.addItems( ('None', 'Vertically', 'Horizontally')) self.flipColumnOrientation.addItems( ('None', 'Vertically', 'Horizontally')) #*// Connect the drop down menus #* Connect the restore defaults button self.restoreDefaults.clicked.connect(self.setDefaults) #* I SHOULDN'T HAVE TO DO THIS. self.paper.width = 402 self.paper.height = 318 self.paper.setGeometry(0, 0, 402, 318) #* Connect the ok button self.okCancel.accepted.connect(self.update) # self.paper.currentLine = Line(0, GLPoint(-1, -1, *self.paper.s), color=(0, 0, 0)) # self.paper.currentLine.finish(GLPoint(-1, -1, *self.paper.s), *self.paper.s, self.paper.lineVbo, self.paper.lines) # self.paper.reset() self.paper.doReset = True self.update() self.show() @pyqtSlot() def update(self, xpos=None, ypos=None): # super().update() if xpos is None: xpos = self.xOffset.value() if ypos is None: ypos = self.yOffset.value() # debug(self.paper.lines, self.paper.width, self.paper.height) # debug(self.paper.size(), color=2) self.paper.reset() # self.paper.resetLineVbo() #* Update all of the pattern options in paper self.paper.overlap = (xpos, ypos) self.paper.includeHalfsies = self.includeHalfsies.isChecked() self.paper.rowSkip = self.rowSkip.value() self.paper.rowSkipAmount = self.rowSkipAmount.value() self.paper.columnSkip = self.columnSkip.value() self.paper.columnSkipAmount = self.columnSkipAmount.value() self.paper.flipRow = self.flipRow.value() self.paper.flipRowOrientation = self.flipRowOrientation.currentText( ) self.paper.flipColumn = self.flipColumn.value() self.paper.flipColumnOrientation = self.flipColumnOrientation.currentText( ) self.paper.update() self.paper.repeatPattern(self.pattern) return super().update() @pyqtSlot() def setDefaults(self): self.paper.reset() self.paper.overlap = (0, 0) self.paper.includeHalfsies = True self.paper.rowSkip = 1 self.paper.rowSkipAmount = 0 self.paper.columnSkip = 1 self.paper.columnSkipAmount = 0 self.paper.flipRow = 1 self.paper.flipRowOrientation = 'None' self.paper.flipColumn = 1 self.paper.flipColumnOrientation = 'None' self.xOffset.setSliderPosition(0) self.yOffset.setSliderPosition(0) self.includeHalfsies.setChecked(True) self.rowSkip.setValue(1) self.rowSkipAmount.setValue(0) self.columnSkip.setValue(1) self.columnSkipAmount.setValue(0) if len(self.paper.bounds) > 1: try: pattern = self.paper.getPattern() except UserWarning as err: debug(err, color=-1) return def transferSettings(): self.paper.overlap = self.patternMenu.paper.overlap self.paper.includeHalfsies = self.patternMenu.paper.includeHalfsies self.paper.rowSkip = self.patternMenu.paper.rowSkip self.paper.rowSkipAmount = self.patternMenu.paper.rowSkipAmount self.paper.columnSkip = self.patternMenu.paper.columnSkip self.paper.columnSkipAmount = self.patternMenu.paper.columnSkipAmount self.paper.flipRow = self.patternMenu.paper.flipRow self.paper.flipRowOrientation = self.patternMenu.paper.flipRowOrientation self.paper.flipColumn = self.patternMenu.paper.flipColumn self.paper.flipColumnOrientation = self.patternMenu.paper.flipColumnOrientation self.patternMenu = PatternMenu(self, pattern=pattern) self.patternMenu.okCancel.accepted.connect(transferSettings) self.patternMenu.okCancel.accepted.connect( lambda: self.paper.repeatPattern(self.patternMenu.pattern))
def randomPointi(minX=0, maxX=100, minY=0, maxY=100): return Pointi(randint(minX, maxX), randint(minY, maxY)) def isAdj(p1, p2): return math.isclose(p1.x, p2.x, abs_tol=1) and math.isclose( p1.y, p2.y, abs_tol=1) def dist(p1, p2): return math.hypot(p2.x - p1.x, p2.y - p1.y) ''' from Cope import debug w=100 h=100 cd=TLPoint(50, 50, w, h) ds=10 assert cd.x % ds == 0 assert cd.y % ds == 0 tlp = TLPoint(20, 30, w, h) glp = GLPoint(-.2, .6, w, h) ifp = InfPoint(-3, 5, cd, ds) assert tlp.x == 20
def finish(self, loc, width, height, vbo, colorVbo, lines, color=None): if not self.color: self.color = color self.end = loc # vbo.bind() # tell OpenGL that the VBO contains an array of vertices # glEnableClientState(GL_VERTEX_ARRAY) # these vertices contain 2 single precision coordinates # glVertexPointer(2, GL_FLOAT, 0, vbo) # draw "count" points from the VBO # glDrawArrays(GL_POINTS, 0, len(self.dots)) # glBufferSubData(GL_ARRAY_BUFFER, self.index, self.vboSize * 32, self.data(width, height)) # vbo.write(self.index, self.data(width, height), self.vboSize) # // bind then map the VBO # glBindBuffer(GL_ARRAY_BUFFER, vboId) # vbo.bind() # data = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY) # assert data # # // if the pointer is valid(mapped), update VBO # data. # updateMyVBO(ptr, ...) # glUnmapBuffer(GL_ARRAY_BUFFER) lineData = () colorData = () for i in lines: lineData += i.data(width, height) colorData += clampColor(i.color) debug(colorData, minItems=10) vbo.bind() # glEnableClientState(GL_VERTEX_ARRAY) #* BufferSubData # glBufferSubData(GL_ARRAY_BUFFER, 12, 8 * 32, newData) #* MapBuffer # data = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE) # debug(pointer(data)) # debug(data) #* BufferData glBufferData( GL_ARRAY_BUFFER, np.asarray(lineData + self.data(width, height), np.float32), GL_DYNAMIC_DRAW) glDisableClientState(GL_VERTEX_ARRAY) vbo.unbind() colorVbo.bind() # glEnableClientState(GL_COLOR_ARRAY) glBufferData(GL_ARRAY_BUFFER, np.asarray(colorData + clampColor(self.color)), GL_DYNAMIC_DRAW)