def saveBkg(self): if not self.bkg.isBackgroundSet: MsgBox("Set to Background inorder to save", 3) return if self.bkg.fileName == 'flat': self.saveBkgColor() else: file = os.path.basename(self.bkg.fileName) file = file[0:file.index('.')] file = file[:15] + "-bkg.jpg" ## if it's not already a bkg file and the new file doesn't exist if not self.bkg.fileName.lower().endswith("-bkg.jpg") and not \ path.exists(paths["bkgPath"]+ file): self.bkg.fileName = paths["bkgPath"] + file flopped = self.bkg.flopped pix = self.canvas.view.grab(QRect(QPoint(1, 1), QSize())) pix.save(paths["bkgPath"] + file, format='jpg', quality=100) MsgBox("Saved as " + file, 3) self.canvas.clear( ) ## replace current background with "-bkg.jpg" copy self.addBkg(self.bkg.fileName, flopped) else: MsgBox("Already saved as background jpg") self.dots.btnAddBkg.setEnabled(True) self.disableBkgBtns()
def savePath(self): if self.pathMaker.pts: Q = QFileDialog() if self.pathMaker.openPathFile == '': self.pathMaker.openPathFile = paths["paths"] + 'tmp.path' f = Q.getSaveFileName(self.pathMaker, paths["paths"], self.pathMaker.openPathFile) Q.accept() if not f[0]: return elif not f[0].lower().endswith('.path'): MsgBox("savePath: Wrong file extention - use '.path'") else: try: with open(f[0], 'w') as fp: for i in range(0, len(self.pathMaker.pts)): p = self.pathMaker.pts[i] x = str("{0:.2f}".format(p.x())) y = str("{0:.2f}".format(p.y())) fp.write(x + ", " + y + "\n") fp.close() except IOError: MsgBox("savePath: Error saving file") return else: MsgBox("savePath: Nothing saved")
def saveBkgColor(self): ## write to .bkg file Q = QFileDialog() f = Q.getSaveFileName(self.canvas, paths["bkgPath"], paths["bkgPath"] + 'tmp.bkg') if not f[0]: return if not f[0].lower().endswith('.bkg'): MsgBox("Save Background Color: Wrong file extention - use '.bkg'") return else: try: with open(f[0], 'w') as fp: fp.write(self.bkg.color.name()) except IOError: MsgBox("savePlay: Error saving file")
def savePlay(self): if self.canvas.pathMakerOn: ## using load in pathMaker self.pathMaker.sideWays.savePath() return elif len(self.scene.items()) == 0: return else: dlist = [] for pix in self.scene.items(): if pix.type in ("pix", "bkg"): # if 'frame' in pix.fileName and pix.scale > 2.0: # continue ## bad rec if pix.fileName != 'flat' and \ not path.exists(pix.fileName): ## note continue if pix.type == "pix": dlist.append(self.returnPixBkg(pix)) elif pix.type == "bkg": if pix.fileName != 'flat' and \ not path.exists(pix.fileName): ## note continue if pix.fileName != 'flat': dlist.append(self.returnPixBkg(pix)) else: dlist.append(self.returnFlat(pix)) if dlist: self.saveToJson(dlist) else: MsgBox("savePlay: Error saving file")
def spriteList(self): try: files = os.listdir(paths['spritePath']) except IOError: MsgBox("No Sprite Directory Found!", 5) return None filenames = [] for file in files: if file.lower().endswith('png'): filenames.append(paths['spritePath'] + file.lower()) if not filenames: MsgBox("No Sprites Found!", 5) return filenames ### ------------------- dotsScrollPanel --------------------
def settingBkgMsg(self): self.bkg.setZValue(common['bkgZ']) ## the one showing self.bkg.isBackgroundSet = True self.disableSetBkg() ## turn off setting it again if self.bkg.fileName != 'flat': txt = os.path.basename(self.bkg.fileName) MsgBox(txt + " " + "set to background")
def setBkg(self): if self.bkg.isBackgroundSet == False and self.bkg.key != 'lock': self.lockBkg() return else: self.disableBkgBtns() self.dots.btnAddBkg.setEnabled(True) MsgBox("Already set to background")
def saveToJson(self, dlist): Q = QFileDialog() if self.canvas.openPlayFile == '': self.canvas.openPlayFile = paths["playPath"] + 'tmp.play' f = Q.getSaveFileName(self.canvas, paths["playPath"], self.canvas.openPlayFile) if not f[0]: return if not f[0].lower().endswith('.play'): MsgBox("saveToJson: Wrong file extention - use '.play'") return else: try: with open(f[0], 'w') as fp: json.dump(dlist, fp) except IOError: MsgBox("saveToJson: Error saving file") return
def openPlay(self, file): dlist = [] try: with open(file, 'r') as fp: ## read a play file dlist = json.load(fp) except IOError: MsgBox("openPlay: Error loading file") return if dlist: self.mapper.clearMap() ## just clear it k, b = 0, 0 ## number of pixitems, test for bkg zval lnn = len(dlist) lnn = lnn + self.mapper.toFront(0) ## start at the top self.canvas.pixCount = self.mapper.toFront(0) for tmp in dlist: ## toss no shows if tmp['type'] == 'bkg' and tmp['fname'] != 'flat' and \ not path.exists(paths["bkgPath"] + tmp['fname']): continue elif tmp['type'] == 'pix' and \ not path.exists(paths["spritePath"] + tmp['fname']): continue ## load and go if tmp['type'] == 'pix': k += 1 ## counts pixitems self.canvas.pixCount += 1 ## id used by mapper pix = PixItem( paths["spritePath"] + tmp['fname'], self.canvas.pixCount, 0, 0, self.canvas ) ## passing self.canvas which references self.mapper tmp['z'] = lnn lnn -= 1 ## preserves front to back relationship # print(tmp['type'], tmp['z'], lnn) elif tmp['type'] == 'bkg': ## starts at -99.0 if b == 0: b = common['bkgZ'] else: b -= 1 ## could be another background or flat # print(tmp['type'], tmp['z'], b) tmp["z"] = b if tmp['fname'] == 'flat': self.canvas.initBkg.setBkgColor( QColor(tmp['tag']), tmp["z"]) continue else: pix = BkgItem(paths["bkgPath"] + tmp['fname'], self.canvas, tmp["z"]) pix.setFlag(QGraphicsPixmapItem.ItemIsMovable, False) ## update pix and bkg from tmp and add to scene self.addPixToScene(pix, tmp) self.canvas.openPlayFile = file self.canvas.initBkg.disableBkgBtns() self.dots.statusBar.showMessage( "Number of Pixitems: {}".format(k), 5000)
def initPathMaker(self): ## from docks button if self.scene.items() and not self.canvas.pathMakerOn: MsgBox("Clear Scene First to run PathMaker") return elif self.canvas.pathMakerOn: self.pathMakerOff() else: self.canvas.pathMakerOn = True self.scene.clear() self.initThis() if not self.sliders.pathMenuSet: self.sliders.toggleMenu() self.turnGreen()
def openFiles(self): if self.pathMaker.pts: MsgBox("openFiles: Clear Scene First") return Q = QFileDialog() file, _ = Q.getOpenFileName(self.pathMaker, "Choose a path file to open", paths["paths"], "Files(*.path)") Q.accept() if file: self.pathMaker.pts = getPts(file) ## read the file self.pathMaker.openPathFile = os.path.basename(file) self.pathMaker.addPath()
def dragEnterEvent(self, e): if self.canvas.pathMakerOn: ## added for pathmaker e.setAccepted(False) MsgBox("Can't add sprites to PathMaker") return ext = FileTypes if e.mimeData().hasUrls(): m = e.mimeData() imgFile = m.urls()[0].toLocalFile() if imgFile != 'star' and imgFile.lower().endswith(ext): e.setAccepted(True) self.dragOver = True else: e.setAccepted(False)
def snapShot(self): if self.hasBackGround() or self.scene.items(): self.canvas.unSelect() ## turn off any select borders if self.mapper.mapSet: self.mapper.removeMap() if self.canvas.openPlayFile == '': snap = "dots_" + snapTag() + ".jpg" else: snap = os.path.basename(self.canvas.openPlayFile) snap = snap[:-5] + ".jpg" if snap[:4] != "dots": ## always ask unless Q = QFileDialog() f = Q.getSaveFileName(self, paths["snapShot"], paths["snapShot"] + snap) if not f[0]: return elif not f[0].lower().endswith('.jpg'): MsgBox("Wrong file extention - use '.jpg'") return snap = os.path.basename(f[0]) pix = self.canvas.view.grab(QRect(QPoint(0, 0), QSize())) pix.save(paths["snapShot"] + snap, format='jpg', quality=100) MsgBox("Saved as " + snap, 3)
def pathLoader(anime): file = paths["paths"] + anime ## includes '.path' try: path = QPainterPath() with open(file, 'r') as fp: for line in fp: ln = line.rstrip() ln = list(map(float, ln.split(','))) if not path.elementCount(): path.moveTo(QPointF(ln[0], ln[1])) path.lineTo(QPointF(ln[0], ln[1])) path.closeSubpath() return path except IOError: MsgBox("pathLoader: Error loading path file") ### ---------------------- dotsSidePath --------------------
def openBkgFile(self, file): ## read from .bkg file try: with open(file, 'r') as fp: self.setBkgColor(QColor(fp.readline())) except IOError: MsgBox("openBkgFile: Error reading file")