def data(self, index): if index in [Qt.WhatsThisRole, Qt.AccessibleTextRole]: return self.__class__.__name__ elif index == Qt.AccessibleDescriptionRole: designation = self.abstractPart.name.strip() if designation.startswith("~Move"): # after split, the result is in example: ['~Moved', 'to', '30027a'] # get absolute path to part plain text file partname = designation.split(" ")[2] filepath = LDrawFile.getPartFilePath(partname + ".dat") designation = "" if filepath: # read and parse first line in file or pass silently f = open(filepath,"r") try: designation = f.readline().strip().replace('0 ','').replace(' ',' ') except (IOError, OSError): pass f.close() else: LicHelpers.writeLogEntry("Can not find %s in LDraw library" % partname) return designation else: if self._dataString: return self._dataString colorName = self.color.name if self.color else "Unnamed" if CSITreeManager.showPartGroupings: x, y, z = LicHelpers.GLMatrixToXYZ(self.matrix) self._dataString = "%s - (%.1f, %.1f, %.1f)" % (colorName, x, y, z) else: self._dataString = "%s - %s" % (self.abstractPart.name, colorName) return self._dataString
def __runCommand(d): POVRayApp = os.path.join(config.POVRayPath, 'pvengine.exe').replace("\\", "/") if not os.path.isfile(POVRayApp): error_message = "Error: Could not find Pov-Ray in %s - aborting image generation" % os.path.dirname( POVRayApp) LicHelpers.writeLogEntry(error_message) print error_message return args = ['"' + POVRayApp + '"'] for key, value in d.items(): command = povCommands[key] if command: args.append(command[0] + command[1](value)) else: if key == 'inFile': args.insert( 1, value ) # Ensure input file is first command (after pvengine.exe itself) else: args.append(value) if config.writePOVRayActivity: LicHelpers.writeLogAccess(" ".join(args)) os.spawnv(os.P_WAIT, POVRayApp, args)
def __runCommand(d): LogFile = open(os.path.join(config.appDataPath(), "activity.log"), "a") POVRayApp = config.POVRayPath if not os.path.isfile(POVRayApp): error_message = "Error: Could not find Pov-Ray in %s - aborting image generation" % os.path.dirname( POVRayApp) LicHelpers.writeLogEntry(error_message) print error_message return args = ['"' + POVRayApp + '"'] for key, value in d.items(): command = povCommands[key] if command: args.append(command[0] + command[1](value)) else: if key == 'inFile': args.insert( 1, value ) # Ensure input file is first command (after pvengine.exe itself) else: args.append(value) if config.writePOVRayActivity: LogFile.write(" ".join(args) + "\n") LogFile.close() os.spawnv(os.P_WAIT, POVRayApp, args)
def __runCommand(d): l3pApp = os.path.join(config.L3PPath, 'l3p.exe').replace("\\", "/") if not os.path.isfile(l3pApp): error_message = "Error: Could not find L3P.exe in %s - aborting image generation" % os.path.dirname( l3pApp) LicHelpers.writeLogEntry(error_message) print error_message return args = [l3pApp] mode = os.P_WAIT for key, value in d.items(): command = l3pCommands[key] if command: args.append(command[0] + command[1](value)) else: if key == 'inFile': args.insert( 1, value ) # Ensure input file is first command (after l3p.exe itself) else: args.append(value) if config.writeL3PActivity: LicHelpers.writeLogAccess(" ".join(args)) if sys.platform == 'win32': mode = os.P_DETACH os.spawnv(mode, l3pApp, args)
def __runCommand(d): LogFile= open(os.path.join(config.appDataPath(),"activity.log"),"a") POVRayApp = os.path.join(config.POVRayPath, 'pvengine.exe').replace("\\", "/") if not os.path.isfile(POVRayApp): error_message = "Error: Could not find Pov-Ray in %s - aborting image generation" % os.path.dirname(POVRayApp) LicHelpers.writeLogEntry(error_message) print error_message return args = ['"' + POVRayApp + '"'] for key, value in d.items(): command = povCommands[key] if command: args.append(command[0] + command[1](value)) else: if key == 'inFile': args.insert(1, value) # Ensure input file is first command (after pvengine.exe itself) else: args.append(value) if config.writePOVRayActivity: LogFile.write(" ".join(args)+"\n") LogFile.close() os.spawnv(os.P_WAIT, POVRayApp, args)
def __runCommand(d): LogFile = open(os.path.join(config.appDataPath(), "activity.log"), "a") l3pApp = config.L3PPath LibDir = '-ldd%s' % config.LDrawPath if not os.path.isfile(l3pApp): error_message = "Error: Could not find L3P in %s - aborting image generation" % os.path.dirname( l3pApp) LicHelpers.writeLogEntry(error_message) print error_message return args = [l3pApp, LibDir] for key, value in d.items(): command = l3pCommands[key] if command: args.append(command[0] + command[1](value)) else: if key == 'inFile': args.insert( 1, value ) # Ensure input file is first command (after l3p.exe itself) else: args.append(value) if config.writeL3PActivity: LogFile.write(" ".join(args) + "\n") LogFile.close() os.spawnv(os.P_WAIT, l3pApp, args)
def data(self, index): if index in [Qt.WhatsThisRole, Qt.AccessibleTextRole]: return self.__class__.__name__ elif index == Qt.AccessibleDescriptionRole: designation = self.abstractPart.name.strip() if designation.startswith("~Move"): # after split, the result is in example: ['~Moved', 'to', '30027a'] # get absolute path to part plain text file partname = designation.split(" ")[2] filepath = LDrawFile.getPartFilePath(partname + ".dat") designation = "" if filepath: # read and parse first line in file or pass silently f = open(filepath,"r") try: designation = f.readline().strip().replace('0 ','').replace(' ',' ') except (IOError, OSError): pass f.close() else: LicHelpers.writeLogEntry("Can not find %s in LDraw library" % partname) return designation else: if self._dataString: return self._dataString colorName = self.color.name if self.color else "Unnamed" if CSITreeManager.showPartGroupings: x, y, z = LicHelpers.GLMatrixToXYZ(self.matrix) self._dataString = "%s - (%.1f, %.1f, %.1f)" % (colorName, x, y, z) else: self._dataString = "%s - %s" % (self.abstractPart.name, colorName) return self._dataString
def __runCommand(d): l3pApp = os.path.join(config.L3PPath ,'l3p.exe').replace("\\", "/") if not os.path.isfile(l3pApp): error_message = "Error: Could not find L3P.exe in %s - aborting image generation" % os.path.dirname(l3pApp) LicHelpers.writeLogEntry(error_message) print error_message return args = [l3pApp] mode = os.P_WAIT for key, value in d.items(): command = l3pCommands[key] if command: args.append(command[0] + command[1](value)) else: if key == 'inFile': args.insert(1, value) # Ensure input file is first command (after l3p.exe itself) else: args.append(value) if config.writeL3PActivity: LicHelpers.writeLogAccess(" ".join(args)) if sys.platform == 'win32': mode = os.P_DETACH os.spawnv(mode, l3pApp, args)
def __runCommand(d): LogFile= open(os.path.join(config.appDataPath(),"activity.log"),"a") l3pApp = os.path.join(config.L3PPath , 'l3p.exe').replace("\\", "/") LibDir = '-ldd%s' % config.LDrawPath if not os.path.isfile(l3pApp): error_message = "Error: Could not find L3P.exe in %s - aborting image generation" % os.path.dirname(l3pApp) LicHelpers.writeLogEntry(error_message) print error_message return args = [l3pApp,LibDir] for key, value in d.items(): command = l3pCommands[key] if command: args.append(command[0] + command[1](value)) else: if key == 'inFile': args.insert(1, value) # Ensure input file is first command (after l3p.exe itself) else: args.append(value) if config.writeL3PActivity: LogFile.write(" ".join(args)+"\n") LogFile.close() os.spawnv(os.P_WAIT, l3pApp, args)
def convertToRGBA(LDrawColorCode): if LDrawColorCode == CurrentColor: return None if LDrawColorCode == ComplimentColor: return None # TODO: Handle compliment colors if LDrawColorCode not in colors: print "Could not find LDraw Color: %d - Using Black." % LDrawColorCode return LicHelpers.LicColor(*colors[0]) return LicHelpers.LicColor(*colors[LDrawColorCode])
def getColorName(LDrawColorCode): if LDrawColorCode == CurrentColor: return None if LDrawColorCode == ComplimentColor: return None #TODO: Handle compliment colors if LDrawColorCode not in colors: color_error = "Could not find LDraw Color: %d - Using Black" % LDrawColorCode LicHelpers.writeLogEntry(color_error, "getColorName") print color_error return colors[LDrawColorCode][-1]
def job_2(self): destfile = "" if self.hasConnection: for srcfile in self.fileToDownload: try: destfile = self.download_file(self.host + srcfile) except Exception, ex: LicHelpers.writeLogEntry(ex.message, self.__class__.__name__) else: self.setText("Downloaded %s" % os.path.basename(destfile))
def getColorName(LDrawColorCode): if LDrawColorCode == CurrentColor: return None if LDrawColorCode == ComplimentColor: return None #TODO: Handle compliment colors if LDrawColorCode not in colors: color_error = "Could not find LDraw Color: %d - Using Black" % LDrawColorCode LicHelpers.writeLogEntry(color_error ,"getColorName") print color_error return colors[LDrawColorCode][-1]
def convertToRGBA(LDrawColorCode): if LDrawColorCode == CurrentColor: return None if LDrawColorCode == ComplimentColor: return None #TODO: Handle compliment colors if LDrawColorCode not in colors: color_error = "Could not find LDraw Color: %d - Using Black" % LDrawColorCode LicHelpers.writeLogEntry(color_error , "convertToRGBA") print color_error return LicHelpers.LicColor(*colors[0]) return LicHelpers.LicColor(*colors[LDrawColorCode])
def job_2(self): destfile = "" if self.hasConnection: for srcfile in self.fileToDownload: try: destfile = self.download_file(self.host + srcfile) except Exception, ex: LicHelpers.writeLogEntry(ex.message, self.__class__.__name__) else: self.setText("Downloaded %s" % os.path.basename(destfile))
def convertToRGBA(LDrawColorCode): if LDrawColorCode == CurrentColor: return None if LDrawColorCode == ComplimentColor: return None #TODO: Handle compliment colors if LDrawColorCode not in colors: color_error = "Could not find LDraw Color: %d - Using Black" % LDrawColorCode LicHelpers.writeLogEntry(color_error, "convertToRGBA") print color_error return LicHelpers.LicColor(*colors[0]) return LicHelpers.LicColor(*colors[LDrawColorCode])
def updatePersistentIndices(self): for index in self.persistentIndexList(): item = index.internalPointer() if item is None: continue # Happens whenever we delete a persistent index (below) newIndex = QModelIndex() try: if item.parent(): newIndex = self.createIndex(item.row(), 0, item) except Exception, ex: LicHelpers.writeLogEntry("updatePersistentIndices: %s" % ex.message, item.__class__.__name__) pass self.changePersistentIndex(index, newIndex)
def acceptValue(self): vals = self.nTextField.text() stack = self.scene.undoStack state = int(self._vertical) nums = [] if vals and self.scene.pages: regexp = re.compile(r'^\d{1,}(-\d{1,}|)$') nums = LicHelpers.rangeify(regexp, vals) if nums: stack.beginMacro("change layout%s" % ("s" if nums.__len__() > 1 else "")) for page in self.scene.pages: try: c = nums.index(page.number) except: c = -1 else: if c > -1: lstate = state if page.steps and page.steps.__len__( ) > 1 else AutoLayout stack.push( LayoutItemCommand(page, page.getCurrentLayout(), lstate)) stack.endMacro() self.close()
def __init__(self, parent, displacement, direction): QDialog.__init__(self, parent, Qt.CustomizeWindowHint | Qt.WindowTitleHint) self.setAttribute(Qt.WA_DeleteOnClose) self.setWindowTitle(self.tr("Change Displacement")) self.originalDisplacement, self.direction = displacement, direction distance = LicHelpers.displacementToDistance(displacement, direction) sizeLabel, self.sizeSpinBox = self.makeLabelSpinBox(self.tr("&Distance:"), distance, -5000, 5000, self.sizeChanged) self.arrowCheckBox = QCheckBox(self.tr("&Adjust Arrow Length")) self.arrowCheckBox.setChecked(True) self.xyzWidget = XYZWidget(self.displacementChanged, -5000, 5000, *displacement) self.moreButton = QPushButton(self.tr("X - Y - Z")) self.moreButton.setCheckable(True) self.moreButton.setAutoDefault(False) self.connect(self.moreButton, SIGNAL("toggled(bool)"), self.xyzWidget, SLOT("setVisible(bool)")) buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal) self.connect(buttonBox, SIGNAL("accepted()"), self, SLOT("accept()")) self.connect(buttonBox, SIGNAL("rejected()"), self, SLOT("reject()")) mainLayout = QGridLayout(self) mainLayout.setSizeConstraint(QLayout.SetFixedSize) mainLayout.addWidgetRow(0, (sizeLabel, self.sizeSpinBox)) mainLayout.addWidget(self.arrowCheckBox, 1, 0, 1, 2) mainLayout.addWidget(self.moreButton, 2, 0, 1, 2) mainLayout.addWidget(self.xyzWidget, 3, 0, 1, 2) mainLayout.addWidget(buttonBox, 4, 0, 1, 2) self.xyzWidget.hide() self.sizeSpinBox.selectAll()
def __readLicColor(stream): if stream.licFileVersion >= 13: if stream.readBool(): r, g, b, a = stream.readFloat(), stream.readFloat(), stream.readFloat(), stream.readFloat() name = str(stream.readQString()) return LicHelpers.LicColor(r, g, b, a, name) return None return colorDict[stream.readInt32()]
def __init__(self, parent, arrow): QDialog.__init__(self, parent, Qt.CustomizeWindowHint | Qt.WindowTitleHint) self.setAttribute(Qt.WA_DeleteOnClose) self.setWindowTitle(self.tr("Change Arrow")) self.arrow = arrow self.originalDisplacement, self.originalLength, self.originalRotation = arrow.displacement, arrow.getLength( ), arrow.axisRotation displacement = arrow.displacement distance = LicHelpers.displacementToDistance(displacement, arrow.displaceDirection) sizeLabel, self.sizeSpinBox = self.makeLabelSpinBox( self.tr("&Distance:"), distance, -5000, 5000, self.sizeChanged) lengthLabel, self.lengthSpinBox = self.makeLabelSpinBox( self.tr("&Length:"), arrow.getLength(), -5000, 5000, self.lengthChanged) rotationLabel, self.rotationSpinBox = self.makeLabelSpinBox( self.tr("&Rotation:"), arrow.axisRotation, -360, 360, self.rotationChanged) buttonBox = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal) self.connect(buttonBox, SIGNAL("accepted()"), self, SLOT("accept()")) self.connect(buttonBox, SIGNAL("rejected()"), self, SLOT("reject()")) self.tipXYZWidget = XYZWidget(self.displacementChanged, -5000, 5000, *displacement) self.endXYZWidget = XYZWidget(self.displacementChanged, -5000, 5000, *displacement) self.tipXYZWidget.setLabels("tip X:", "tip Y:", "tip Z:") self.endXYZWidget.setLabels("end X (NYI):", "end Y (NYI):", "end Z (NYI):") extension = QWidget() box = QBoxLayout(QBoxLayout.TopToBottom, extension) box.addWidget(self.tipXYZWidget) #box.addWidget(self.endXYZWidget) #TODO: Either implement arbitrary arrow end point positions or remove this self.moreButton = QPushButton(self.tr("X - Y - Z")) self.moreButton.setCheckable(True) self.moreButton.setAutoDefault(False) self.connect(self.moreButton, SIGNAL("toggled(bool)"), extension, SLOT("setVisible(bool)")) mainLayout = QGridLayout(self) mainLayout.setSizeConstraint(QLayout.SetFixedSize) mainLayout.addWidgetRow(0, (sizeLabel, self.sizeSpinBox)) mainLayout.addWidgetRow(1, (lengthLabel, self.lengthSpinBox)) mainLayout.addWidgetRow(2, (rotationLabel, self.rotationSpinBox)) mainLayout.addWidget(self.moreButton, 3, 0, 1, 2) mainLayout.addWidget(extension, 4, 0, 1, 2) mainLayout.addWidget(buttonBox, 5, 0, 1, 2) extension.hide() self.sizeSpinBox.selectAll()
def predefinedComboChange(self, index): ''' We load data in the reverse order, because we first need to set the unit of measure, that we will use. This property determines the rest. Then the resolution. In the end, what matters most - width and height. ''' data = self.predefinedFormatComboBox.itemData(index) aList = LicHelpers.VariantToFloatList(data) if aList: self.aspectRatioCheckBox.setChecked(False) self.docFormatComboBox.setCurrentIndex(aList[3]) self.resSpinBox.setValue(aList[2]) self.docWidthSpinBox.setValue(aList[0]) self.docHeightSpinBox.setValue(aList[1]) self.setWidth(aList[0], True) self.setHeight(aList[1], True)
def __init__(self, parent, arrow): QDialog.__init__(self, parent, Qt.CustomizeWindowHint | Qt.WindowTitleHint) self.setAttribute(Qt.WA_DeleteOnClose) self.setWindowTitle(self.tr("Change Arrow")) self.arrow = arrow self.originalDisplacement, self.originalLength, self.originalRotation = arrow.displacement, arrow.getLength(), arrow.axisRotation displacement = arrow.displacement distance = LicHelpers.displacementToDistance(displacement, arrow.displaceDirection) sizeLabel, self.sizeSpinBox = self.makeLabelSpinBox(self.tr("&Distance:"), distance, -5000, 5000, self.sizeChanged) lengthLabel, self.lengthSpinBox = self.makeLabelSpinBox(self.tr("&Length:"), arrow.getLength(), -5000, 5000, self.lengthChanged) rotationLabel, self.rotationSpinBox = self.makeLabelSpinBox(self.tr("&Rotation:"), arrow.axisRotation, -360, 360, self.rotationChanged) buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal) self.connect(buttonBox, SIGNAL("accepted()"), self, SLOT("accept()")) self.connect(buttonBox, SIGNAL("rejected()"), self, SLOT("reject()")) self.tipXYZWidget = XYZWidget(self.displacementChanged, -5000, 5000, *displacement) self.endXYZWidget = XYZWidget(self.displacementChanged, -5000, 5000, *displacement) self.tipXYZWidget.setLabels("tip X:", "tip Y:", "tip Z:") self.endXYZWidget.setLabels("end X (NYI):", "end Y (NYI):", "end Z (NYI):") extension = QWidget() box = QBoxLayout(QBoxLayout.TopToBottom, extension) box.addWidget(self.tipXYZWidget) #box.addWidget(self.endXYZWidget) #TODO: Either implement arbitrary arrow end point positions or remove this self.moreButton = QPushButton(self.tr("X - Y - Z")) self.moreButton.setCheckable(True) self.moreButton.setAutoDefault(False) self.connect(self.moreButton, SIGNAL("toggled(bool)"), extension, SLOT("setVisible(bool)")) mainLayout = QGridLayout(self) mainLayout.setSizeConstraint(QLayout.SetFixedSize) mainLayout.addWidgetRow(0, (sizeLabel, self.sizeSpinBox)) mainLayout.addWidgetRow(1, (lengthLabel, self.lengthSpinBox)) mainLayout.addWidgetRow(2, (rotationLabel, self.rotationSpinBox)) mainLayout.addWidget(self.moreButton, 3, 0, 1, 2) mainLayout.addWidget(extension, 4, 0, 1, 2) mainLayout.addWidget(buttonBox, 5, 0, 1, 2) extension.hide() self.sizeSpinBox.selectAll()
def acceptValue(self): vals = self.nTextField.text() stack = self.scene.undoStack state = int(self._vertical) nums = [] if vals and self.scene.pages: regexp = re.compile(r"^\d{1,}(-\d{1,}|)$") nums = LicHelpers.rangeify(regexp, vals) if nums: stack.beginMacro("change layout%s" % ("s" if nums.__len__() > 1 else "")) for page in self.scene.pages: try: c = nums.index(page.number) except: c = -1 else: if c > -1: lstate = state if page.steps and page.steps.__len__() > 1 else AutoLayout stack.push(LayoutItemCommand(page, page.getCurrentLayout(), lstate)) stack.endMacro() self.close()
def __init__(self, parent, displacement, direction): QDialog.__init__(self, parent, Qt.CustomizeWindowHint | Qt.WindowTitleHint) self.setAttribute(Qt.WA_DeleteOnClose) self.setWindowTitle(self.tr("Change Displacement")) self.originalDisplacement, self.direction = displacement, direction distance = LicHelpers.displacementToDistance(displacement, direction) sizeLabel, self.sizeSpinBox = self.makeLabelSpinBox( self.tr("&Distance:"), distance, -5000, 5000, self.sizeChanged) self.arrowCheckBox = QCheckBox(self.tr("&Adjust Arrow Length")) self.arrowCheckBox.setChecked(True) self.xyzWidget = XYZWidget(self.displacementChanged, -5000, 5000, *displacement) self.moreButton = QPushButton(self.tr("X - Y - Z")) self.moreButton.setCheckable(True) self.moreButton.setAutoDefault(False) self.connect(self.moreButton, SIGNAL("toggled(bool)"), self.xyzWidget, SLOT("setVisible(bool)")) buttonBox = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal) self.connect(buttonBox, SIGNAL("accepted()"), self, SLOT("accept()")) self.connect(buttonBox, SIGNAL("rejected()"), self, SLOT("reject()")) mainLayout = QGridLayout(self) mainLayout.setSizeConstraint(QLayout.SetFixedSize) mainLayout.addWidgetRow(0, (sizeLabel, self.sizeSpinBox)) mainLayout.addWidget(self.arrowCheckBox, 1, 0, 1, 2) mainLayout.addWidget(self.moreButton, 2, 0, 1, 2) mainLayout.addWidget(self.xyzWidget, 3, 0, 1, 2) mainLayout.addWidget(buttonBox, 4, 0, 1, 2) self.xyzWidget.hide() self.sizeSpinBox.selectAll()
def sizeChanged(self): newSize = self.sizeSpinBox.value() displacement = LicHelpers.distanceToDisplacement(newSize, self.arrow.displaceDirection) self.emit(SIGNAL("changeDisplacement"), displacement)
def sizeChanged(self): newSize = self.sizeSpinBox.value() displacement = LicHelpers.distanceToDisplacement( newSize, self.arrow.displaceDirection) self.emit(SIGNAL("changeDisplacement"), displacement)