def printVal(filePath, x, y, **kwargs): try: img = loadImage(filePath) except IOError as e: pprint('Error: ', color=COLOR.RED, endLine=False) pprint('[I/O] ({0}): {1}'.format(e.errno, e.strerror)) exit(1) except Exception: pprint('Error: ', color=COLOR.RED, endLine=False) pprint('Unsupported image format') exit(1) start = (img.width * y + x) * img.bytesPerPixel pprint(pUtils.formatHex(img.data[start:start + img.bytesPerPixel]))
def genConfig(dirPath, configManager, **kwargs): pUtils.createDirectory(os.path.abspath(dirPath)) filePath = os.path.join(dirPath, 'config1.json') if configManager.saveFullConfig(filePath) != 0: pprint('Error: ', color=COLOR.RED, endLine=False) pprint('File: %s already exists' % filePath) exit(1) filePath = os.path.join(dirPath, 'configMenu.json') if configManager.genMenuConfigFile(filePath, configName='config1', configPath='config1.json'): pprint('Error: ', color=COLOR.RED, endLine=False) pprint('File: %s already exists' % filePath) exit(1) pprint('DONE', color=COLOR.TEAL)
def genCanvas(outFilePath, red, green, blue, width, height, alpha, **kwargs): if os.path.exists(outFilePath): pprint('Error: ', color=COLOR.RED, endLine=False) pprint('File:') pprint(' %s' % outFilePath, color=COLOR.TEAL) pprint('Already exists') exit(1) if alpha is None: img = Rgb888Image(bytearray([red, green, blue] * width * height), width, height) else: img = Rgba8888Image( bytearray([red, green, blue, alpha] * width * height), width, height) img.save(outFilePath) pprint('DONE', color=COLOR.TEAL)
def load(self): if self.configFilePath is None: return 1 try: self.configData = pUtils.quickFileRead(self.configFilePath, 'json') except Exception: pprint('Error: ', color=COLOR.RED, endLine=False) pprint('Unable to load json file:') pprint(' ' + self.configFilePath, color=COLOR.TEAL) exit(1) return 0
def info(filePath, **kwargs): try: img = loadImage(filePath) except IOError as e: pprint('Error: ', color=COLOR.RED, endLine=False) pprint('[I/O] ({0}): {1}'.format(e.errno, e.strerror)) exit(1) except Exception: pprint('Error: ', color=COLOR.RED, endLine=False) pprint('Unsupported image format') exit(1) pprint('-----------------------------------') pprint('srcFileName: ' + os.path.basename(img.srcFilePath)) pprint('mode: ' + img.mode) pprint('size: ' + str(img.width) + 'x' + str(img.height)) pprint('srcFileFormat: ' + img.srcFileFormat) pprint('-----------------------------------')
def version(**kwargs): pprint('Version: ', color=COLOR.TEAL, endLine=False) pprint(VERSION)
def determineConfigFilePath(self, configFilePath, configName): """ ConfigManager determines what config file to use in the following way: 1) If configFilePath is not None uses that and returns. 2) If configStart.txt exists: 2.1) If configName is not None then: - ConfigManager loads 'configStart.txt' from the same directory as this file. 'configStart.txt' points to a config menu file - ConfigManager loads the config menu file The config menu file is a dictionary of 'configName: path' pairs - ConfigManager uses configName with the dictionary and gets the path 2.2) if configName is None, is then the same as in #2.1 except that defaultConfigName (from the config menu file) is used as configName. 3) Otherwise no configFile would be load """ if configFilePath is not None: self.configFilePath = configFilePath if not os.path.isabs(self.configFilePath): self.configFilePath = os.path.join( os.path.dirname(self.configStartPath), self.configFilePath) return try: self.configMenuPath = pUtils.quickFileRead(self.configStartPath, 'txt')[0] except Exception: if self.verbose: pprint('---------------------------------') pprint('Info: ', color=COLOR.TEAL, endLine=False) pprint('Unable to load:') pprint(' %s' % self.configStartPath, color=COLOR.TEAL) pprint('Internal defaults will be used') pprint('---------------------------------') return if not os.path.isabs(self.configMenuPath): self.configMenuPath = os.path.join( os.path.dirname(self.configStartPath), self.configMenuPath) try: configMenuData = pUtils.quickFileRead(self.configMenuPath, 'json') except Exception: pprint('Error: ', color=COLOR.RED, endLine=False) pprint('Unable to load json file:') pprint(' ' + self.configMenuPath, color=COLOR.TEAL) exit(1) if configName is None: try: defaultConfigName = configMenuData['defaultConfigName'] except Exception: pprint('Error: ', color=COLOR.RED, endLine=False) pprint('On file:') pprint(' ' + self.configMenuPath, color=COLOR.TEAL) pprint('Key: "', endLine=False) pprint('defaultConfigName', endLine=False, color=COLOR.TEAL) pprint('" not found') exit(1) configName = defaultConfigName try: self.configFilePathFromMenu = configMenuData['configFilePathDict'][ configName] except Exception: pprint('Error: ', color=COLOR.RED, endLine=False) pprint('On file:') pprint(' ' + self.configMenuPath, color=COLOR.TEAL) pprint('Key sequence: "', endLine=False) pprint('configFilePathDict ' + configName, endLine=False, color=COLOR.TEAL) pprint('" not found') exit(1) self.configFilePath = self.configFilePathFromMenu if not os.path.isabs(self.configFilePath): self.configFilePath = os.path.join( os.path.dirname(self.configMenuPath), self.configFilePath)
def clearConfigStart(self): if not os.path.exists(self.configStartPath): pprint('Info: ', color=COLOR.TEAL, endLine=False) pprint('Already clear') return 1 pprint('Warning: ', color=COLOR.RED, endLine=False) pprint('File:') pprint(' ' + self.configStartPath, color=COLOR.TEAL) pprint('Will be deleted.') promptString = 'Proceed (y/n)? ' if input(promptString) != 'y': pprint('Aborted action') return 2 try: os.remove(self.configStartPath) except Exception: pprint('Error: ', color=COLOR.RED, endLine=False) pprint('Unable to clear configStart') return 3 pprint('DONE', color=COLOR.TEAL) return 0
def setConfigStart(self, filePath): if not os.path.exists(filePath): pprint('Error: ', color=COLOR.RED, endLine=False) pprint('File:') pprint(' ' + filePath, color=COLOR.TEAL) pprint('Does not exists.') return 1 if os.path.exists(self.configStartPath): pprint('Warning: ', color=COLOR.RED, endLine=False) pprint('File:') pprint(' ' + self.configStartPath, color=COLOR.TEAL) pprint('Will be overwritten.') promptString = 'Proceed (y/n)? ' if input(promptString) != 'y': pprint('Aborted action') return 2 pUtils.quickFileWrite(self.configStartPath, os.path.abspath(os.path.realpath(filePath))) pprint('DONE', color=COLOR.TEAL) return 0