class GobstonesClothing(GobstonesBoardPainter): def __init__(self, clothing): self.parser = ParseXML() self.gobstonesStandard = GobstonesStandard() self.clothing = clothing self.images = self.getDictFromXML(self.clothing) def draw(self, painter, rect, cell): stones = cell.getAllStones() if self.isIn(stones, self.images): if os.path.exists(self.imageLocation): img = QtGui.QImage(self.imageLocation) painter.drawImage(rect, img) else: self.gobstonesStandard.draw(painter, rect, cell) else: self.gobstonesStandard.draw(painter, rect, cell) def getDictFromXML(self, clothing): d = self.parser.getDictFromXML(clothing) return d def isIn(self, tupleStones, dictImages): '''Return if isIn and set the image location in imageLocation attribute <-- Black Programming :'( ''' images_dir = os.path.join(os.path.dirname(self.clothing), 'Imagenes') for key in dictImages: if(self.containsSymbols(key)): resOfKey = [False,False,False,False] for i in range(0,4): if(self.isASymbol(key[i])): if (key[i] == '*') and (int(tupleStones[i]) >= 0): resOfKey[i] = True elif (key[i] == '+') and (int(tupleStones[i]) > 0): resOfKey[i] = True else: resOfKey[i] = tupleStones[i] == key[i] if resOfKey[0] and resOfKey[1] and resOfKey[2] and resOfKey[3]: self.imageLocation = os.path.join(images_dir, self.images[key]) return True else: if tupleStones in dictImages: self.imageLocation = os.path.join(images_dir, self.images[tupleStones]) return True return False def containsSymbols(self, tupleStones): res = False for i in range(0, 4): res = res or self.isASymbol(tupleStones[i]) return res def isASymbol(self, char): return (char == '*') or (char == '+')
def generate_example_for(filename, overwrite=True): global_variables.running_tests = False parser = ParseXML.ParseXML(filename) ob = dict() if global_variables.code_returned == \ global_variables.return_codes['success']: # catch a problem in the parsing try: ob = parser.parse_deviser_xml() except: global_variables.code_returned \ = global_variables.return_codes['parsing error'] if global_variables.code_returned == \ global_variables.return_codes['success']: name = ob['name'.lower()] try: if global_variables.is_package: generate_example_code(ob) except: global_variables.code_returned \ = global_variables.return_codes['unknown error - please report']
def generate_code_for(filename, overwrite=True): global_variables.running_tests = False parser = ParseXML.ParseXML(filename) ob = [] if global_variables.code_returned == \ global_variables.return_codes['success']: # catch a problem in the parsing try: ob = parser.parse_deviser_xml() except: global_variables.code_returned \ = global_variables.return_codes['parsing error'] if global_variables.code_returned == \ global_variables.return_codes['success']: name = ob['name'.lower()] language = global_variables.language # TO DO REMEMBER TO REMOVE # try: if global_variables.is_package: generate_package_code(name, language, overwrite, ob) else: generate_other_library_code(name, language, overwrite, ob)
def generate_cmake(filename, binding): parser = ParseXML.ParseXML(filename) ob = parser.parse_deviser_xml() for wc in ob['baseElements']: strFunctions.prefix_classes(wc) for working_class in ob['baseElements']: if working_class['name'] == global_variables.document_class: working_class['document'] = True os.chdir('./temp') if os.path.isdir(binding): os.chdir(binding) else: os.makedirs(binding) os.chdir(binding) this_dir = os.getcwd() test_functions.create_dir('src') os.chdir('src') test_functions.create_dir('bindings') test_functions.create_dir('{0}'.format(global_variables.language)) os.chdir(this_dir) bind = CMakeFiles.CMakeFiles(ob, this_dir, True) bind.write_other_library_files() os.chdir('../.') os.chdir('../.')
def __init__(self, clothing): self.parser = ParseXML() self.gobstonesStandard = GobstonesStandard() self.clothing = clothing self.images = self.getDictFromXML(self.clothing)