def execute(self, eviroment): dataSelect = Response() nodoSelect = Select_Expresion("SENTENCIA_SELECT",self.fila,self.columna,self.valor) nodoSelect.hijos = self.hijos # Solamente viene una lista de expresiones. if len(self.hijos) == 1 : lista_Exp = self.hijos[0] l = [] for exp in lista_Exp.hijos : value = exp.execute(None) if exp.tipo.data_type == Data_Type.error : print("Error: ") else : if exp.nombreNodo == 'ALIAS': dataSelect.encabezados.append(exp.alias) else : dataSelect.encabezados.append('?column?') l.append(value) dataSelect.data.append(l) return dataSelect else : #SENTENCIA_SELECT_DISTINCT functionSelect = Select() result = functionSelect.execute(nodoSelect) responseSelect = Response() if self.nombreNodo == "SENTENCIA_SELECT_DISTINCT": resultDistinct = {} for r in result: resultDistinct[' '.join(map(str, r))] = r result = [] for res in resultDistinct: result.append(resultDistinct[res]) encabezados = [] tipos = [] for encabezado in functionSelect.encabezadoRetorno: encabezados.append(encabezado.nombre) tipos.append(encabezado.tipo) responseSelect.encabezados = encabezados responseSelect.data = result.data responseSelect.tipos = tipos return responseSelect
def update(self): self.__update__() w = HeaderCustomize("Themes Options") w.slider = self.slider w._atras = self._atras w._screen = self._screen self.add(w) r = RadioButtonList("Page Layout") r.descripcion = """ When the two-column layout is assigned, the page title is in one column and content is in the other. """ self.add(r) w = RadioButton("One Column") r.add(w) w = RadioButton("Two Column") r.add(w) w = Select("From Page Section 1 Content") w.descripcion = """ Select pages to feature in each area from the dropdowns. Add an image to a section by setting a featured image in the page editor. Empty sections will not be displayed. """ w.opciones = [ "--Elegir--", "Pagina de ejemplo", "Inicio", "Acerca de", "Contacto", "Blog", ] self.add(w) w = EnlaceButtonInput("+Añadir nueva página") self.add(w) w = Select("From Page Section 2 Content") self.add(w) w = EnlaceButtonInput("+Añadir nueva página") self.add(w) w = Select("From Page Section 3 Content") self.add(w) w = EnlaceButtonInput("+Añadir nueva página") self.add(w) w = Select("From Page Section 4 Content") self.add(w) w = EnlaceButtonInput("+Añadir nueva página") self.add(w)
def number_of_images(self, root_dir, per_subset=None): """ Returns the count of all images Parameters ---------- root_dir : str Root directory containing csv files and new folder per_subset : bool Whether to give stats per subset or for the whole dataset, by default the whole dataset Returns ------- int Count of all images """ per_subset = False if per_subset is None else per_subset counts = {} for subset in ["train", "validation", "test"]: counts[subset] = 0 print("Loading CSVs for {}".format(subset)) image_ids_file = self.common.get_image_ids_file(subset) image_ids_path = os.path.join(root_dir, image_ids_file) counts[subset] += len(Select.get_image_names(image_ids_path)) if not per_subset: counts = sum(counts.values()) return counts
def __init__(self, llwl='Brown', llNL=2, percen=80, NE = True, Col = True, Gram = True, Chu = True): ''' @param llwl:LogLikleyHood Corpa name ('Brown','AmE06','BE06') @param llNL:LogLikleyHood @param percen: Presision of output default = 20, 20% returned @param NE: Uses NE default True @param Col: Uses Collocation default True @param Gram: Uses N-Grams default True @param Chu: Uses Chunking default True ''' self.NEs = NE self.Col = Col self.Gram = Gram self.Chu = Chu self.p = percen print 'Starting to build ', llwl self.LL = LogLikelihood(wordlist=llwl, NLength=llNL) print 'LL Loaded' self.POS = POS() print 'POS Loaded' self.GD = GetData() print 'GD Loaded' self.Cu = Chunker(self.POS) print 'Cu Loaded' self.FL = Filter() print 'FL Loaded' self.CC = Collocation(self.POS) print 'CC Loaded' self.Ng = NGram() print 'Ng Loaded' self.S = Select(percentil=self.p) print 'S Loaded' self.To = Tokenize(self.FL) print 'To Loaded'
def update(self): self.__update__() w = HeaderCustomize(self.titulo) w.slider = self.slider w._atras = self._atras w._screen = self._screen w.descripcion = """ Tu tema permite una página estatica como portada """ self.add(w) w = RadioButtonList("Pagina frontal muestra") self.add(w) w.addOptions(["Tus ultimas entradas", "Una pagina estatica"], 1) w = Select("Portada") w.opciones = [ "Pagina de ejemplo", "Inicio", "Acerca de", "Contacto", "Blog", ] self.add(w) w = EnlaceButton("+Añadir nueva pagina") self.add(w) w = Select("Página de entradaa") w.opciones = [ "Pagina de ejemplo", "Inicio", "Acerca de", "Contacto", "Blog", ] self.add(w) w = EnlaceButton("+Añadir nueva pagina") self.add(w) self.css({ "padding-left": "20px", "padding-right": "20px" }, None, ">div:nth-child(n+2)")
def __init__(self, llwl='Brown', llNL=2, percen=80, NE=True, Col=True, Gram=True, Chu=True): ''' @param llwl:LogLikleyHood Corpa name ('Brown','AmE06','BE06') @param llNL:LogLikleyHood @param percen: Presision of output default = 20, 20% returned @param NE: Uses NE default True @param Col: Uses Collocation default True @param Gram: Uses N-Grams default True @param Chu: Uses Chunking default True ''' self.NEs = NE self.Col = Col self.Gram = Gram self.Chu = Chu self.p = percen print 'Starting to build ', llwl self.LL = LogLikelihood(wordlist=llwl, NLength=llNL) print 'LL Loaded' self.POS = POS() print 'POS Loaded' self.GD = GetData() print 'GD Loaded' self.Cu = Chunker(self.POS) print 'Cu Loaded' self.FL = Filter() print 'FL Loaded' self.CC = Collocation(self.POS) print 'CC Loaded' self.Ng = NGram() print 'Ng Loaded' self.S = Select(percentil=self.p) print 'S Loaded' self.To = Tokenize(self.FL) print 'To Loaded'
def create_world(): global boy,castle,select,boy2,boy3,bom,can pX2=None pY2=None pX3=None pY3=None boy=[] boy2=[] boy3=[] castle=Castle() select=Select() bom=bomb() can=cannon()
def openFile(self, fname): if fname == '': # nothing opened pass else: try: slt = Select(fname) if slt.count == 0: QtWidgets.QMessageBox.warning(self, '提示', '该文件不包含 Mos Device.') else: if slt.count == 1: dv_name = slt.dvc_list[0] self.model = slt.extract(dv_name) ok = True else: items = slt.dvc_list dv_name, ok = QtWidgets.QInputDialog.getItem( self, "选择", "请选择 Device :", items, 0, False) self.model = slt.extract(dv_name) if ok == False: pass elif ok == True: self.mode = 1 self.label_fileNow.setText( os.path.split(fname)[1] + ' 当前 Device : ' + dv_name) self.Edit_Search.setText('') self.hunter = Hunter(self.model) self.GeoDic = self.hunter.geometry() self.binType_temp = '0' self.binType = '1' self.scanPar(self.model) except: QtWidgets.QMessageBox.critical(self, "Error", "解析数据失败,请检查文件格式。")
def create_world(): global boy,castle,select,boy2,boy3,Ecastle global daepo global User global backimage boy=[] boy2=[] boy3=[] castle=Castle() Ecastle=ECastle() select=Select() daepo=cannon() User=user() backimage=background()
def build_images_csv(self, image_labels_file, image_ids_file, new_folder, root_dir, classes, boxes_file=None): """ Given an image labels file and image ids file, builds a new one containing only the specified classes in the new specified folder Parameters ---------- image_labels_file : str Name of csv files with image labels, typically "XXX-annotations-human-imagelabels.csv" image_ids_file : str Name of csv files with image information, typically "XXX-images-with-labels-with-rotation.csv" boxes_file : str Optional (for use with bounding boxes), name of csv files with bounding boxes information, typically "XXX-annotations-bbox.csv" new_folder : str New folder to place new CSV's root_dir : str Root directory contianing csv files and new folder classes : set of str Set of classes to be kept """ image_labels_path = os.path.join(root_dir, image_labels_file) print("Selecting images to keep") images_to_keep = Select.select_images_with_class(image_labels_path, classes) to_process = [image_labels_file, image_ids_file] if boxes_file: to_process.append(boxes_file) for csv_file_name in to_process: print("Saving rows for {}".format(csv_file_name)) old_path = os.path.join(root_dir, csv_file_name) new_path = os.path.join(root_dir, new_folder, csv_file_name) old_c = self.common.load_csv_as_dict(old_path) new_c = self.common.new_csv_as_dict(new_path, old_c.fieldnames) rows = [] for row in tqdm(old_c): if row['ImageID'] in images_to_keep and ( row.get('LabelName') is None or row.get('LabelName') in classes): rows.append(row) new_c.writeheader() new_c.writerows(rows)
def get_class_counts(self, root_dir, human_readable=None): """ Returns the counts of each class for the training, validation, and test sets Parameters ---------- root_dir : str Root directory containing csv files and new folder human_readable : bool Whether the dictionary should use the class labels as keys or human descriptions, default is True Returns ------- dict of str -> dict of str -> int Top level dictionary is keyed by labels or human descriptions, second level is train, validation, or test, the value of the second level dictionary is the counts for that labels subset """ human_readable = True if human_readable is None else human_readable class_counts = {} for subset in ["train", "validation", "test"]: print("Loading CSVs for {}".format(subset)) image_labels_file = self.common.get_image_labels_file(subset) image_labels_path = os.path.join(root_dir, image_labels_file) c = Common.load_csv_as_dict(image_labels_path) for row in tqdm(c): label_name = row["LabelName"] if not class_counts.get(label_name): class_counts[label_name] = {} if not class_counts[label_name].get(subset): class_counts[label_name][subset] = 0 class_counts[label_name][subset] += 1 if human_readable: label_to_human_label = Select.class_names_to_human_names( os.path.join(root_dir, self.common.get_classes_description_file())) for label in label_to_human_label.keys(): class_counts[label_to_human_label[label]] = class_counts[label] del class_counts[label] return class_counts
def random_classes_subset(self, new_folder, root_dir, n, seed=None): """ Samples n random classes and builds a new dataset in new_folder where only the specified classes are present Parameters ---------- new_folder : str New folder to place new CSV's root_dir : str Root directory contianing csv files and new folder n : int Number of classes to select seed : int Seed for random number generator """ classes_file = 'classes-trainable.txt' classes_path = os.path.join(root_dir, classes_file) print("Selecting random sample of {} classes".format(n)) classes = Select.select_random_classes(classes_path, n, seed=seed) self.classes_subset(classes, new_folder, root_dir) new_classes_path = os.path.join(root_dir, new_folder, classes_file) Common.new_text_file(new_classes_path, classes)
class Scene(QGraphicsScene): def __init__(self, parent=None): QGraphicsScene.__init__(self, parent) # hold the set of keys we're pressing self.keys_pressed = set() # use a timer to get 60Hz refresh (hopefully) 1000 / 16 == 62.5 self.timer = QBasicTimer() self.timer.start(FRAME_TIME_MS, self) # bg = QGraphicsRectItem() # bg.setRect(-1,-1,SCREEN_WIDTH+2,SCREEN_HEIGHT+2) # bg.setBrush(QBrush(Qt.black)) self.screen = "InitialScreen" self.previousScreen = {"FoodScreen": "InitialScreen", "CustomizeScreen": "InitialScreen", "AllFood": "FoodScreen"} for categoryKey, value in WholeFood.wholeFoodDic.items(): self.previousScreen[categoryKey] = "FoodScreen" for foodKey in value.keys(): self.previousScreen[foodKey] = categoryKey self.foodImagePath = "" self.isAllFood = False self.isInitialized = False self.initUI = False self.customizeDic = {} self.url = "" # Enemies # self.enemies = [Enemy()] # self.enemies[0].setPos(SCREEN_WIDTH, 0) # self.addItem(self.enemies[0]) # self.idx = [0] self.customize = CustomizeScreen(self) self.view = QGraphicsView(self) self.view.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.view.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.view.setWindowTitle("Help_Choose") self.view.setWindowIcon(QIcon("C:/Users/dudtj/iCloudDrive/vscode_workspace/Python_workspace/Github/AD_Project/Youngseo/PNG/UI/AirPods.png")) # self.view.setWindowFlags(Qt.CustomizeWindowHint) self.view.show() self.view.setFixedSize(SCREEN_WIDTH,SCREEN_HEIGHT) self.setSceneRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT) self.ask = AskClose(self) def keyPressEvent(self, event): self.keys_pressed.add(event.key()) if event.key() == Qt.Key_Escape: self.ask.show() def keyReleaseEvent(self, event): self.keys_pressed.remove(event.key()) def timerEvent(self, event): self.game_update() self.update() def game_update(self): if self.screen == "InitialScreen": if not self.isInitialized: # BackGround self.bg = BackGround("Black") self.addItem(self.bg) # Player self.player = Player() self.player.setPos((SCREEN_WIDTH-self.player.pixmap().width())/2, 500) self.addItem(self.player) # Bullets self.bullets = [Bullet(PLAYER_BULLET_X_OFFSETS[0],PLAYER_BULLET_Y), Bullet(PLAYER_BULLET_X_OFFSETS[1],PLAYER_BULLET_Y - 30), Bullet(PLAYER_BULLET_X_OFFSETS[2],PLAYER_BULLET_Y)] for b in self.bullets: b.setPos(SCREEN_WIDTH, SCREEN_HEIGHT) self.addItem(b) # Select self.foodSelect = Select("PNG/Initial_Screen/fork.png", "FoodScreen", self) self.foodSelect.setPos(100, 100) self.addItem(self.foodSelect) self.customizeSelect = Select("PNG/Initial_Screen/customize.png", "CustomizeScreen", self) self.customizeSelect.setPos(700 - self.customizeSelect.pixmap().width(), 100) self.addItem(self.customizeSelect) self.isInitialized = True else: self.player.game_update(self.keys_pressed) for b in self.bullets: b.game_update(self.keys_pressed, self.player) if self.foodSelect.game_update(self.bullets): return elif self.customizeSelect.game_update(self.bullets): return elif self.screen == "FoodScreen": if not self.isInitialized: # BackGround self.bg = BackGround('Blue') self.bg.setPos(0, 0) self.addItem(self.bg) # Player self.player = Player() self.player.setPos((SCREEN_WIDTH-self.player.pixmap().width())/2, 500) self.addItem(self.player) # Bullets self.bullets = [Bullet(PLAYER_BULLET_X_OFFSETS[0],PLAYER_BULLET_Y), Bullet(PLAYER_BULLET_X_OFFSETS[1],PLAYER_BULLET_Y - 30), Bullet(PLAYER_BULLET_X_OFFSETS[2],PLAYER_BULLET_Y)] for b in self.bullets: b.setPos(SCREEN_WIDTH, SCREEN_HEIGHT) self.addItem(b) # FoodCategory interval = 33.333333333 imageWidth = 100 self.koreanFood = FoodCategory("PNG/Category/KoreanFood.png", "KoreanFood", self) self.koreanFood.setPos(100+interval, interval) self.addItem(self.koreanFood) self.chineseFood = FoodCategory("PNG/Category/ChineseFood.png", "ChineseFood", self) self.chineseFood.setPos(100+interval*2 + imageWidth, interval) self.addItem(self.chineseFood) self.japaneseFood = FoodCategory("PNG/Category/JapaneseFood.png", "JapaneseFood", self) self.japaneseFood.setPos(100+interval*3 + imageWidth*2, interval) self.addItem(self.japaneseFood) self.westernFood = FoodCategory("PNG/Category/WesternFood.png", "WesternFood", self) self.westernFood.setPos(100+interval*4 + imageWidth*3, interval) self.addItem(self.westernFood) self.allFood = FoodCategory("PNG/Category/AllFood.png", "AllFood", self) self.allFood.setPos(100+interval*5 + imageWidth*4, interval) self.addItem(self.allFood) interval = None imageWidth = None # BackButton self.backButton = BackButton(self) self.backButton.setPos(10, 20) self.addItem(self.backButton) self.isInitialized = True else: self.player.game_update(self.keys_pressed) for b in self.bullets: b.game_update(self.keys_pressed, self.player) if self.koreanFood.game_update(self.bullets): return elif self.chineseFood.game_update(self.bullets): return elif self.japaneseFood.game_update(self.bullets): return elif self.westernFood.game_update(self.bullets): return elif self.allFood.game_update(self.bullets): return elif self.backButton.game_update(self.bullets): return elif self.screen == "KoreanFood": if not self.isInitialized: # BackGround self.bg = BackGround("DarkBlue") self.addItem(self.bg) # Player self.player = Player() self.player.setPos((SCREEN_WIDTH-self.player.pixmap().width())/2, 500) self.addItem(self.player) # Bullets self.bullets = [Bullet(PLAYER_BULLET_X_OFFSETS[0],PLAYER_BULLET_Y), Bullet(PLAYER_BULLET_X_OFFSETS[1],PLAYER_BULLET_Y - 30), Bullet(PLAYER_BULLET_X_OFFSETS[2],PLAYER_BULLET_Y)] for b in self.bullets: b.setPos(SCREEN_WIDTH, SCREEN_HEIGHT) self.addItem(b) self.foodList = [] # wholeFoodDic = {'koreanFoodDic': koreanFoodDic} # koreanFoodDic = {'bibimbab': bibimbab} # bibimbab = {'image': , :, :} # each == bibimbab for key, value in WholeFood.wholeFoodDic[self.screen].items(): food = FoodChoose(value['image'], key, value['URL'], self) self.foodList.append(food) food = None length = 0 for food in self.foodList: x, y = FoodChoose.foodLocation[length][0], FoodChoose.foodLocation[length][1] food.setPos(x, y) food.pos = length self.addItem(food) length += len(FoodChoose.foodLocation) // len(self.foodList) # BackButton self.backButton = BackButton(self) self.backButton.setPos(10, 20) self.addItem(self.backButton) self.isInitialized = True else: self.player.game_update(self.keys_pressed) for b in self.bullets: b.game_update(self.keys_pressed, self.player) if self.backButton.game_update(self.bullets): return for i in range(len(self.foodList)): if self.foodList[i].game_update(self.bullets): break elif self.screen == "ChineseFood": if not self.isInitialized: # BackGround self.bg = BackGround("DarkBlue") self.addItem(self.bg) # Player self.player = Player() self.player.setPos((SCREEN_WIDTH-self.player.pixmap().width())/2, 500) self.addItem(self.player) # Bullets self.bullets = [Bullet(PLAYER_BULLET_X_OFFSETS[0],PLAYER_BULLET_Y), Bullet(PLAYER_BULLET_X_OFFSETS[1],PLAYER_BULLET_Y - 30), Bullet(PLAYER_BULLET_X_OFFSETS[2],PLAYER_BULLET_Y)] for b in self.bullets: b.setPos(SCREEN_WIDTH, SCREEN_HEIGHT) self.addItem(b) self.foodList = [] # wholeFoodDic = {'koreanFoodDic': koreanFoodDic} # koreanFoodDic = {'bibimbab': bibimbab} # bibimbab = {'image': , :, :} # each == bibimbab for key, value in WholeFood.wholeFoodDic[self.screen].items(): food = FoodChoose(value['image'], key, value['URL'], self) self.foodList.append(food) food = None length = 0 for food in self.foodList: x, y = FoodChoose.foodLocation[length][0], FoodChoose.foodLocation[length][1] food.setPos(x, y) food.pos = length self.addItem(food) length += len(FoodChoose.foodLocation) // len(self.foodList) # BackButton self.backButton = BackButton(self) self.backButton.setPos(10, 20) self.addItem(self.backButton) self.isInitialized = True else: self.player.game_update(self.keys_pressed) for b in self.bullets: b.game_update(self.keys_pressed, self.player) if self.backButton.game_update(self.bullets): return for i in range(len(self.foodList)): if self.foodList[i].game_update(self.bullets): break elif self.screen == "JapaneseFood": if not self.isInitialized: # BackGround self.bg = BackGround("DarkBlue") self.addItem(self.bg) # Player self.player = Player() self.player.setPos((SCREEN_WIDTH-self.player.pixmap().width())/2, 500) self.addItem(self.player) # Bullets self.bullets = [Bullet(PLAYER_BULLET_X_OFFSETS[0],PLAYER_BULLET_Y), Bullet(PLAYER_BULLET_X_OFFSETS[1],PLAYER_BULLET_Y - 30), Bullet(PLAYER_BULLET_X_OFFSETS[2],PLAYER_BULLET_Y)] for b in self.bullets: b.setPos(SCREEN_WIDTH, SCREEN_HEIGHT) self.addItem(b) self.foodList = [] # wholeFoodDic = {'koreanFoodDic': koreanFoodDic} # koreanFoodDic = {'bibimbab': bibimbab} # bibimbab = {'image': , :, :} # each == bibimbab for key, value in WholeFood.wholeFoodDic[self.screen].items(): food = FoodChoose(value['image'], key, value['URL'], self) self.foodList.append(food) food = None length = 0 for food in self.foodList: x, y = FoodChoose.foodLocation[length][0], FoodChoose.foodLocation[length][1] food.setPos(x, y) food.pos = length self.addItem(food) length += len(FoodChoose.foodLocation) // len(self.foodList) # BackButton self.backButton = BackButton(self) self.backButton.setPos(10, 20) self.addItem(self.backButton) self.isInitialized = True else: self.player.game_update(self.keys_pressed) for b in self.bullets: b.game_update(self.keys_pressed, self.player) if self.backButton.game_update(self.bullets): return for i in range(len(self.foodList)): if self.foodList[i].game_update(self.bullets): break elif self.screen == "WesternFood": if not self.isInitialized: # BackGround self.bg = BackGround("DarkBlue") self.addItem(self.bg) # Player self.player = Player() self.player.setPos((SCREEN_WIDTH-self.player.pixmap().width())/2, 500) self.addItem(self.player) # Bullets self.bullets = [Bullet(PLAYER_BULLET_X_OFFSETS[0],PLAYER_BULLET_Y), Bullet(PLAYER_BULLET_X_OFFSETS[1],PLAYER_BULLET_Y - 30), Bullet(PLAYER_BULLET_X_OFFSETS[2],PLAYER_BULLET_Y)] for b in self.bullets: b.setPos(SCREEN_WIDTH, SCREEN_HEIGHT) self.addItem(b) self.foodList = [] # wholeFoodDic = {'koreanFoodDic': koreanFoodDic} # koreanFoodDic = {'bibimbab': bibimbab} # bibimbab = {'image': , :, :} # each == bibimbab for key, value in WholeFood.wholeFoodDic[self.screen].items(): food = FoodChoose(value['image'], key, value['URL'], self) self.foodList.append(food) food = None length = 0 for food in self.foodList: x, y = FoodChoose.foodLocation[length][0], FoodChoose.foodLocation[length][1] food.setPos(x, y) food.pos = length self.addItem(food) length += len(FoodChoose.foodLocation) // len(self.foodList) # BackButton self.backButton = BackButton(self) self.backButton.setPos(10, 20) self.addItem(self.backButton) self.isInitialized = True else: self.player.game_update(self.keys_pressed) for b in self.bullets: b.game_update(self.keys_pressed, self.player) if self.backButton.game_update(self.bullets): return for i in range(len(self.foodList)): if self.foodList[i].game_update(self.bullets): break elif self.screen == "AllFood": if not self.isInitialized: # BackGround self.bg = BackGround("DarkBlue") self.addItem(self.bg) # Player self.player = Player() self.player.setPos((SCREEN_WIDTH-self.player.pixmap().width())/2, 500) self.addItem(self.player) # Bullets self.bullets = [Bullet(PLAYER_BULLET_X_OFFSETS[0],PLAYER_BULLET_Y), Bullet(PLAYER_BULLET_X_OFFSETS[1],PLAYER_BULLET_Y - 30), Bullet(PLAYER_BULLET_X_OFFSETS[2],PLAYER_BULLET_Y)] for b in self.bullets: b.setPos(SCREEN_WIDTH, SCREEN_HEIGHT) self.addItem(b) self.foodList = [] # wholeFoodDic = {'koreanFoodDic': koreanFoodDic} # koreanFoodDic = {'bibimbab': bibimbab} # bibimbab = {'image': , :, :} # each == bibimbab for each in WholeFood.wholeFoodDic.values(): for key, value in each.items(): food = FoodChoose(value['image'], key, value['URL'], self) self.foodList.append(food) food = None length = 0 for food in self.foodList: x, y = FoodChoose.foodLocation[length][0], FoodChoose.foodLocation[length][1] food.setPos(x, y) food.pos = length self.addItem(food) length += len(FoodChoose.foodLocation) // len(self.foodList) # BackButton self.backButton = BackButton(self) self.backButton.setPos(10, 20) self.addItem(self.backButton) self.isAllFood = True self.isInitialized = True else: self.player.game_update(self.keys_pressed) for b in self.bullets: b.game_update(self.keys_pressed, self.player) if self.backButton.game_update(self.bullets): return for i in range(len(self.foodList)): if self.foodList[i].game_update(self.bullets): break elif self.screen in WholeFood.wholeFoodList: if not self.isInitialized: # BackGround self.bg = BackGround("Purple") self.addItem(self.bg) # Player self.player = Player() self.player.setPos((SCREEN_WIDTH-self.player.pixmap().width())/2, 500) self.addItem(self.player) # Bullets self.bullets = [Bullet(PLAYER_BULLET_X_OFFSETS[0],PLAYER_BULLET_Y), Bullet(PLAYER_BULLET_X_OFFSETS[1],PLAYER_BULLET_Y - 30), Bullet(PLAYER_BULLET_X_OFFSETS[2],PLAYER_BULLET_Y)] for b in self.bullets: b.setPos(SCREEN_WIDTH, SCREEN_HEIGHT) self.addItem(b) font = QFont() font.setPixelSize(25) font.setBold(True) for value in WholeFood.wholeFoodDic.values(): if self.screen in value: self.addText(value[self.screen]['foodInfo'], font).setPos(300, 105) break self.foodImage = FoodInfo(self.foodImagePath, self) self.foodImage.setPos(100, 100) self.addItem(self.foodImage) self.homeButton = Home(self) self.homeButton.setPos(200-self.homeButton.pixmap().width()//2, 300) self.addItem(self.homeButton) self.retryButton = Retry(self) self.retryButton.setPos(400-self.retryButton.pixmap().width()//2, 300) self.addItem(self.retryButton) self.openUrlButton = OpenURL(self) self.openUrlButton.setPos(600-self.openUrlButton.pixmap().width()//2, 300) self.addItem(self.openUrlButton) self.isInitialized = True else: self.player.game_update(self.keys_pressed) for b in self.bullets: b.game_update(self.keys_pressed, self.player) if self.homeButton.game_update(self.bullets): return elif self.retryButton.game_update(self.bullets): return elif self.openUrlButton.game_update(self.bullets): return elif self.screen == "CustomizeScreen": if not self.isInitialized: if not self.initUI: bg = BackGround("DarkBlue") self.addItem(bg) font = QFont() font.setPixelSize(60) font.setBold(True) self.addText("Selecting...", font).setPos(250, 250) self.customize.cancel = False self.customize.initUI() self.initUI = True else: if len(self.customizeDic) != 0: self.clear() self.bg = BackGround("DarkBlue") self.addItem(self.bg) # Player self.player = Player() self.player.setPos((SCREEN_WIDTH - self.player.pixmap().width()) / 2, 500) self.addItem(self.player) # Bullets self.bullets = [Bullet(PLAYER_BULLET_X_OFFSETS[0], PLAYER_BULLET_Y), Bullet(PLAYER_BULLET_X_OFFSETS[1], PLAYER_BULLET_Y - 30), Bullet(PLAYER_BULLET_X_OFFSETS[2], PLAYER_BULLET_Y)] for b in self.bullets: b.setPos(SCREEN_WIDTH, SCREEN_HEIGHT) self.addItem(b) self.selectList = [] for value in self.customizeDic.values(): select = Customize(value['image'], value['text'], self) self.selectList.append(select) select = None length = 0 for select in self.selectList: x, y = Customize.selectLocation[length][0], Customize.selectLocation[length][1] select.setPos(x, y) select.pos = length self.addItem(select) length += len(Customize.selectLocation) // len(self.selectList) # BackButton self.backButton = BackButton(self) self.backButton.setPos(10, 20) self.addItem(self.backButton) self.isInitialized = True else: if self.customize.cancel: self.screen = 'InitialScreen' self.isInitialized = False self.clear() else: self.player.game_update(self.keys_pressed) for b in self.bullets: b.game_update(self.keys_pressed, self.player) if self.backButton.game_update(self.bullets): return for i in range(len(self.selectList)): if self.selectList[i].game_update(self.bullets): return elif self.screen in self.customize.starImgList: if not self.isInitialized: # BackGround self.bg = BackGround("Purple") self.addItem(self.bg) # Player self.player = Player() self.player.setPos((SCREEN_WIDTH - self.player.pixmap().width()) / 2, 500) self.addItem(self.player) # Bulletsdc self.bullets = [Bullet(PLAYER_BULLET_X_OFFSETS[0], PLAYER_BULLET_Y), Bullet(PLAYER_BULLET_X_OFFSETS[1], PLAYER_BULLET_Y - 30), Bullet(PLAYER_BULLET_X_OFFSETS[2], PLAYER_BULLET_Y)] for b in self.bullets: b.setPos(SCREEN_WIDTH, SCREEN_HEIGHT) self.addItem(b) self.selectImage = CustomizeResult(self.screen, self) self.selectImage.setPos(100, 100) self.addItem(self.selectImage) font = QFont() # palette = QPalette() font.setPixelSize(60) font.setBold(True) # palette.setColor(QPalette.Text, Qt.white) # font.setPalette(palette) self.addText(self.selectText, font).setPos(350,130) #self.font.setStyleSheet("color:rgb(255,255,255") self.homeButton = Home(self) self.homeButton.setPos(300 - self.homeButton.pixmap().width() // 2, 300) self.addItem(self.homeButton) self.retryButton = CustomizeRetry(self) self.retryButton.setPos(500 - self.retryButton.pixmap().width() // 2, 300) self.addItem(self.retryButton) self.isInitialized = True else: self.player.game_update(self.keys_pressed) for b in self.bullets: b.game_update(self.keys_pressed, self.player) if self.homeButton.game_update(self.bullets): return elif self.retryButton.game_update(self.bullets): return
def game_update(self): if self.screen == "InitialScreen": if not self.isInitialized: # BackGround self.bg = BackGround("Black") self.addItem(self.bg) # Player self.player = Player() self.player.setPos((SCREEN_WIDTH-self.player.pixmap().width())/2, 500) self.addItem(self.player) # Bullets self.bullets = [Bullet(PLAYER_BULLET_X_OFFSETS[0],PLAYER_BULLET_Y), Bullet(PLAYER_BULLET_X_OFFSETS[1],PLAYER_BULLET_Y - 30), Bullet(PLAYER_BULLET_X_OFFSETS[2],PLAYER_BULLET_Y)] for b in self.bullets: b.setPos(SCREEN_WIDTH, SCREEN_HEIGHT) self.addItem(b) # Select self.foodSelect = Select("PNG/Initial_Screen/fork.png", "FoodScreen", self) self.foodSelect.setPos(100, 100) self.addItem(self.foodSelect) self.customizeSelect = Select("PNG/Initial_Screen/customize.png", "CustomizeScreen", self) self.customizeSelect.setPos(700 - self.customizeSelect.pixmap().width(), 100) self.addItem(self.customizeSelect) self.isInitialized = True else: self.player.game_update(self.keys_pressed) for b in self.bullets: b.game_update(self.keys_pressed, self.player) if self.foodSelect.game_update(self.bullets): return elif self.customizeSelect.game_update(self.bullets): return elif self.screen == "FoodScreen": if not self.isInitialized: # BackGround self.bg = BackGround('Blue') self.bg.setPos(0, 0) self.addItem(self.bg) # Player self.player = Player() self.player.setPos((SCREEN_WIDTH-self.player.pixmap().width())/2, 500) self.addItem(self.player) # Bullets self.bullets = [Bullet(PLAYER_BULLET_X_OFFSETS[0],PLAYER_BULLET_Y), Bullet(PLAYER_BULLET_X_OFFSETS[1],PLAYER_BULLET_Y - 30), Bullet(PLAYER_BULLET_X_OFFSETS[2],PLAYER_BULLET_Y)] for b in self.bullets: b.setPos(SCREEN_WIDTH, SCREEN_HEIGHT) self.addItem(b) # FoodCategory interval = 33.333333333 imageWidth = 100 self.koreanFood = FoodCategory("PNG/Category/KoreanFood.png", "KoreanFood", self) self.koreanFood.setPos(100+interval, interval) self.addItem(self.koreanFood) self.chineseFood = FoodCategory("PNG/Category/ChineseFood.png", "ChineseFood", self) self.chineseFood.setPos(100+interval*2 + imageWidth, interval) self.addItem(self.chineseFood) self.japaneseFood = FoodCategory("PNG/Category/JapaneseFood.png", "JapaneseFood", self) self.japaneseFood.setPos(100+interval*3 + imageWidth*2, interval) self.addItem(self.japaneseFood) self.westernFood = FoodCategory("PNG/Category/WesternFood.png", "WesternFood", self) self.westernFood.setPos(100+interval*4 + imageWidth*3, interval) self.addItem(self.westernFood) self.allFood = FoodCategory("PNG/Category/AllFood.png", "AllFood", self) self.allFood.setPos(100+interval*5 + imageWidth*4, interval) self.addItem(self.allFood) interval = None imageWidth = None # BackButton self.backButton = BackButton(self) self.backButton.setPos(10, 20) self.addItem(self.backButton) self.isInitialized = True else: self.player.game_update(self.keys_pressed) for b in self.bullets: b.game_update(self.keys_pressed, self.player) if self.koreanFood.game_update(self.bullets): return elif self.chineseFood.game_update(self.bullets): return elif self.japaneseFood.game_update(self.bullets): return elif self.westernFood.game_update(self.bullets): return elif self.allFood.game_update(self.bullets): return elif self.backButton.game_update(self.bullets): return elif self.screen == "KoreanFood": if not self.isInitialized: # BackGround self.bg = BackGround("DarkBlue") self.addItem(self.bg) # Player self.player = Player() self.player.setPos((SCREEN_WIDTH-self.player.pixmap().width())/2, 500) self.addItem(self.player) # Bullets self.bullets = [Bullet(PLAYER_BULLET_X_OFFSETS[0],PLAYER_BULLET_Y), Bullet(PLAYER_BULLET_X_OFFSETS[1],PLAYER_BULLET_Y - 30), Bullet(PLAYER_BULLET_X_OFFSETS[2],PLAYER_BULLET_Y)] for b in self.bullets: b.setPos(SCREEN_WIDTH, SCREEN_HEIGHT) self.addItem(b) self.foodList = [] # wholeFoodDic = {'koreanFoodDic': koreanFoodDic} # koreanFoodDic = {'bibimbab': bibimbab} # bibimbab = {'image': , :, :} # each == bibimbab for key, value in WholeFood.wholeFoodDic[self.screen].items(): food = FoodChoose(value['image'], key, value['URL'], self) self.foodList.append(food) food = None length = 0 for food in self.foodList: x, y = FoodChoose.foodLocation[length][0], FoodChoose.foodLocation[length][1] food.setPos(x, y) food.pos = length self.addItem(food) length += len(FoodChoose.foodLocation) // len(self.foodList) # BackButton self.backButton = BackButton(self) self.backButton.setPos(10, 20) self.addItem(self.backButton) self.isInitialized = True else: self.player.game_update(self.keys_pressed) for b in self.bullets: b.game_update(self.keys_pressed, self.player) if self.backButton.game_update(self.bullets): return for i in range(len(self.foodList)): if self.foodList[i].game_update(self.bullets): break elif self.screen == "ChineseFood": if not self.isInitialized: # BackGround self.bg = BackGround("DarkBlue") self.addItem(self.bg) # Player self.player = Player() self.player.setPos((SCREEN_WIDTH-self.player.pixmap().width())/2, 500) self.addItem(self.player) # Bullets self.bullets = [Bullet(PLAYER_BULLET_X_OFFSETS[0],PLAYER_BULLET_Y), Bullet(PLAYER_BULLET_X_OFFSETS[1],PLAYER_BULLET_Y - 30), Bullet(PLAYER_BULLET_X_OFFSETS[2],PLAYER_BULLET_Y)] for b in self.bullets: b.setPos(SCREEN_WIDTH, SCREEN_HEIGHT) self.addItem(b) self.foodList = [] # wholeFoodDic = {'koreanFoodDic': koreanFoodDic} # koreanFoodDic = {'bibimbab': bibimbab} # bibimbab = {'image': , :, :} # each == bibimbab for key, value in WholeFood.wholeFoodDic[self.screen].items(): food = FoodChoose(value['image'], key, value['URL'], self) self.foodList.append(food) food = None length = 0 for food in self.foodList: x, y = FoodChoose.foodLocation[length][0], FoodChoose.foodLocation[length][1] food.setPos(x, y) food.pos = length self.addItem(food) length += len(FoodChoose.foodLocation) // len(self.foodList) # BackButton self.backButton = BackButton(self) self.backButton.setPos(10, 20) self.addItem(self.backButton) self.isInitialized = True else: self.player.game_update(self.keys_pressed) for b in self.bullets: b.game_update(self.keys_pressed, self.player) if self.backButton.game_update(self.bullets): return for i in range(len(self.foodList)): if self.foodList[i].game_update(self.bullets): break elif self.screen == "JapaneseFood": if not self.isInitialized: # BackGround self.bg = BackGround("DarkBlue") self.addItem(self.bg) # Player self.player = Player() self.player.setPos((SCREEN_WIDTH-self.player.pixmap().width())/2, 500) self.addItem(self.player) # Bullets self.bullets = [Bullet(PLAYER_BULLET_X_OFFSETS[0],PLAYER_BULLET_Y), Bullet(PLAYER_BULLET_X_OFFSETS[1],PLAYER_BULLET_Y - 30), Bullet(PLAYER_BULLET_X_OFFSETS[2],PLAYER_BULLET_Y)] for b in self.bullets: b.setPos(SCREEN_WIDTH, SCREEN_HEIGHT) self.addItem(b) self.foodList = [] # wholeFoodDic = {'koreanFoodDic': koreanFoodDic} # koreanFoodDic = {'bibimbab': bibimbab} # bibimbab = {'image': , :, :} # each == bibimbab for key, value in WholeFood.wholeFoodDic[self.screen].items(): food = FoodChoose(value['image'], key, value['URL'], self) self.foodList.append(food) food = None length = 0 for food in self.foodList: x, y = FoodChoose.foodLocation[length][0], FoodChoose.foodLocation[length][1] food.setPos(x, y) food.pos = length self.addItem(food) length += len(FoodChoose.foodLocation) // len(self.foodList) # BackButton self.backButton = BackButton(self) self.backButton.setPos(10, 20) self.addItem(self.backButton) self.isInitialized = True else: self.player.game_update(self.keys_pressed) for b in self.bullets: b.game_update(self.keys_pressed, self.player) if self.backButton.game_update(self.bullets): return for i in range(len(self.foodList)): if self.foodList[i].game_update(self.bullets): break elif self.screen == "WesternFood": if not self.isInitialized: # BackGround self.bg = BackGround("DarkBlue") self.addItem(self.bg) # Player self.player = Player() self.player.setPos((SCREEN_WIDTH-self.player.pixmap().width())/2, 500) self.addItem(self.player) # Bullets self.bullets = [Bullet(PLAYER_BULLET_X_OFFSETS[0],PLAYER_BULLET_Y), Bullet(PLAYER_BULLET_X_OFFSETS[1],PLAYER_BULLET_Y - 30), Bullet(PLAYER_BULLET_X_OFFSETS[2],PLAYER_BULLET_Y)] for b in self.bullets: b.setPos(SCREEN_WIDTH, SCREEN_HEIGHT) self.addItem(b) self.foodList = [] # wholeFoodDic = {'koreanFoodDic': koreanFoodDic} # koreanFoodDic = {'bibimbab': bibimbab} # bibimbab = {'image': , :, :} # each == bibimbab for key, value in WholeFood.wholeFoodDic[self.screen].items(): food = FoodChoose(value['image'], key, value['URL'], self) self.foodList.append(food) food = None length = 0 for food in self.foodList: x, y = FoodChoose.foodLocation[length][0], FoodChoose.foodLocation[length][1] food.setPos(x, y) food.pos = length self.addItem(food) length += len(FoodChoose.foodLocation) // len(self.foodList) # BackButton self.backButton = BackButton(self) self.backButton.setPos(10, 20) self.addItem(self.backButton) self.isInitialized = True else: self.player.game_update(self.keys_pressed) for b in self.bullets: b.game_update(self.keys_pressed, self.player) if self.backButton.game_update(self.bullets): return for i in range(len(self.foodList)): if self.foodList[i].game_update(self.bullets): break elif self.screen == "AllFood": if not self.isInitialized: # BackGround self.bg = BackGround("DarkBlue") self.addItem(self.bg) # Player self.player = Player() self.player.setPos((SCREEN_WIDTH-self.player.pixmap().width())/2, 500) self.addItem(self.player) # Bullets self.bullets = [Bullet(PLAYER_BULLET_X_OFFSETS[0],PLAYER_BULLET_Y), Bullet(PLAYER_BULLET_X_OFFSETS[1],PLAYER_BULLET_Y - 30), Bullet(PLAYER_BULLET_X_OFFSETS[2],PLAYER_BULLET_Y)] for b in self.bullets: b.setPos(SCREEN_WIDTH, SCREEN_HEIGHT) self.addItem(b) self.foodList = [] # wholeFoodDic = {'koreanFoodDic': koreanFoodDic} # koreanFoodDic = {'bibimbab': bibimbab} # bibimbab = {'image': , :, :} # each == bibimbab for each in WholeFood.wholeFoodDic.values(): for key, value in each.items(): food = FoodChoose(value['image'], key, value['URL'], self) self.foodList.append(food) food = None length = 0 for food in self.foodList: x, y = FoodChoose.foodLocation[length][0], FoodChoose.foodLocation[length][1] food.setPos(x, y) food.pos = length self.addItem(food) length += len(FoodChoose.foodLocation) // len(self.foodList) # BackButton self.backButton = BackButton(self) self.backButton.setPos(10, 20) self.addItem(self.backButton) self.isAllFood = True self.isInitialized = True else: self.player.game_update(self.keys_pressed) for b in self.bullets: b.game_update(self.keys_pressed, self.player) if self.backButton.game_update(self.bullets): return for i in range(len(self.foodList)): if self.foodList[i].game_update(self.bullets): break elif self.screen in WholeFood.wholeFoodList: if not self.isInitialized: # BackGround self.bg = BackGround("Purple") self.addItem(self.bg) # Player self.player = Player() self.player.setPos((SCREEN_WIDTH-self.player.pixmap().width())/2, 500) self.addItem(self.player) # Bullets self.bullets = [Bullet(PLAYER_BULLET_X_OFFSETS[0],PLAYER_BULLET_Y), Bullet(PLAYER_BULLET_X_OFFSETS[1],PLAYER_BULLET_Y - 30), Bullet(PLAYER_BULLET_X_OFFSETS[2],PLAYER_BULLET_Y)] for b in self.bullets: b.setPos(SCREEN_WIDTH, SCREEN_HEIGHT) self.addItem(b) font = QFont() font.setPixelSize(25) font.setBold(True) for value in WholeFood.wholeFoodDic.values(): if self.screen in value: self.addText(value[self.screen]['foodInfo'], font).setPos(300, 105) break self.foodImage = FoodInfo(self.foodImagePath, self) self.foodImage.setPos(100, 100) self.addItem(self.foodImage) self.homeButton = Home(self) self.homeButton.setPos(200-self.homeButton.pixmap().width()//2, 300) self.addItem(self.homeButton) self.retryButton = Retry(self) self.retryButton.setPos(400-self.retryButton.pixmap().width()//2, 300) self.addItem(self.retryButton) self.openUrlButton = OpenURL(self) self.openUrlButton.setPos(600-self.openUrlButton.pixmap().width()//2, 300) self.addItem(self.openUrlButton) self.isInitialized = True else: self.player.game_update(self.keys_pressed) for b in self.bullets: b.game_update(self.keys_pressed, self.player) if self.homeButton.game_update(self.bullets): return elif self.retryButton.game_update(self.bullets): return elif self.openUrlButton.game_update(self.bullets): return elif self.screen == "CustomizeScreen": if not self.isInitialized: if not self.initUI: bg = BackGround("DarkBlue") self.addItem(bg) font = QFont() font.setPixelSize(60) font.setBold(True) self.addText("Selecting...", font).setPos(250, 250) self.customize.cancel = False self.customize.initUI() self.initUI = True else: if len(self.customizeDic) != 0: self.clear() self.bg = BackGround("DarkBlue") self.addItem(self.bg) # Player self.player = Player() self.player.setPos((SCREEN_WIDTH - self.player.pixmap().width()) / 2, 500) self.addItem(self.player) # Bullets self.bullets = [Bullet(PLAYER_BULLET_X_OFFSETS[0], PLAYER_BULLET_Y), Bullet(PLAYER_BULLET_X_OFFSETS[1], PLAYER_BULLET_Y - 30), Bullet(PLAYER_BULLET_X_OFFSETS[2], PLAYER_BULLET_Y)] for b in self.bullets: b.setPos(SCREEN_WIDTH, SCREEN_HEIGHT) self.addItem(b) self.selectList = [] for value in self.customizeDic.values(): select = Customize(value['image'], value['text'], self) self.selectList.append(select) select = None length = 0 for select in self.selectList: x, y = Customize.selectLocation[length][0], Customize.selectLocation[length][1] select.setPos(x, y) select.pos = length self.addItem(select) length += len(Customize.selectLocation) // len(self.selectList) # BackButton self.backButton = BackButton(self) self.backButton.setPos(10, 20) self.addItem(self.backButton) self.isInitialized = True else: if self.customize.cancel: self.screen = 'InitialScreen' self.isInitialized = False self.clear() else: self.player.game_update(self.keys_pressed) for b in self.bullets: b.game_update(self.keys_pressed, self.player) if self.backButton.game_update(self.bullets): return for i in range(len(self.selectList)): if self.selectList[i].game_update(self.bullets): return elif self.screen in self.customize.starImgList: if not self.isInitialized: # BackGround self.bg = BackGround("Purple") self.addItem(self.bg) # Player self.player = Player() self.player.setPos((SCREEN_WIDTH - self.player.pixmap().width()) / 2, 500) self.addItem(self.player) # Bulletsdc self.bullets = [Bullet(PLAYER_BULLET_X_OFFSETS[0], PLAYER_BULLET_Y), Bullet(PLAYER_BULLET_X_OFFSETS[1], PLAYER_BULLET_Y - 30), Bullet(PLAYER_BULLET_X_OFFSETS[2], PLAYER_BULLET_Y)] for b in self.bullets: b.setPos(SCREEN_WIDTH, SCREEN_HEIGHT) self.addItem(b) self.selectImage = CustomizeResult(self.screen, self) self.selectImage.setPos(100, 100) self.addItem(self.selectImage) font = QFont() # palette = QPalette() font.setPixelSize(60) font.setBold(True) # palette.setColor(QPalette.Text, Qt.white) # font.setPalette(palette) self.addText(self.selectText, font).setPos(350,130) #self.font.setStyleSheet("color:rgb(255,255,255") self.homeButton = Home(self) self.homeButton.setPos(300 - self.homeButton.pixmap().width() // 2, 300) self.addItem(self.homeButton) self.retryButton = CustomizeRetry(self) self.retryButton.setPos(500 - self.retryButton.pixmap().width() // 2, 300) self.addItem(self.retryButton) self.isInitialized = True else: self.player.game_update(self.keys_pressed) for b in self.bullets: b.game_update(self.keys_pressed, self.player) if self.homeButton.game_update(self.bullets): return elif self.retryButton.game_update(self.bullets): return
def gen_select_list(self): rank_list = self.get_rank_list() select_list = list() for i in range(len(rank_list)): select_list.append(Select(rank_list[i])) return select_list
def update(self): self.__update__() w = HeaderCustomize(self.titulo) w.slider = self.slider w._atras = self._atras w._screen = self._screen self.add(w) w = ButtonSettings("Ubicaciones de menús") w.slider = self.slider w.screen = self.screen w._screen = 0 w._siguiente = 2 self.add(w) self.addSeparador() w = ButtonSettings("Menús de enlaces de Redes Sociales") w.descripcion = "(Actualmente fijado en: Menú de enlaces de Redes Sociales)" w.slider = self.slider w.screen = self.screen w._screen = 1 w._siguiente = 2 self.add(w) w = ButtonSettings("Top Menú") w.descripcion = "(Actualmente fijado en: Top Menú)" w.slider = self.slider w.screen = self.screen w._screen = 2 w._siguiente = 2 self.add(w) w = ButtonInput("Añadir al menu") self.add(w) # w = HeaderCustomize("Ubicaciones de menús") w.slider = self.slider w._atras = 1 w._screen = 3 self.descripcion = """ Tu tema soporta 2 menús. Elige qué menú debería aparecer en cada lugar. También puedes poner menús en los widgets con el widget “Menú personalizado” """ self.screen.appendToTab(0, w) w = Select("Top Menu") w.opciones = [ "--Eligir--", "Menu de enlaces a redes sociales", "Top menu", ] self.screen.appendToTab(0, w) e = EnlaceButton("Editar menu") self.screen.appendToTab(0, e) w = Select("Top Menu") w.opciones = [ "--Eligir--", "Menu de enlaces a redes sociales", "Top menu", ] self.screen.appendToTab(0, w) e = EnlaceButton("Editar menu") self.screen.appendToTab(0, e) self.screen.tabs[0].find(">div:nth-child(n+2)").css({ "padding-left": "20px", "padding-right": "20px" }) w = HeaderCustomize("Menús de enlaces de Redes Sociales") w.slider = self.slider w._atras = 1 w._screen = 3 self.screen.appendToTab(1, w) w = Input() w.value = "Menús de enlaces de Redes Sociales" self.screen.appendToTab(1, w) a = Acordion("") t = TabAcordion("Yelp") w = Input("URL") w.value = "https://www.yelp.com" t.add(w) w = Input("Etiqueta de navegación") w.value = "Yelp" t.add(w) w = CheckBox("Abrir enlace en una nueva pestaña") t.add(w) w = Input("Atributos del titulo") t.add(w) w = Input("Relacion con el enlace (XFN)") t.add(w) #se debe agregar el widget antes de clonar y despues aplicar un reload si se modifican atributos w = Textarea("Descripción") w.postdescripcion = "La descripción se mostrará en los menús si el tema actual lo soporta." t.add(w) w = EnlaceButton("Eliminar") t.add(w) w.color = "red" a.addTab(t) t2 = t.clone() t2.titulo = "Facebook" t2.children[0].value = "https://facebook.com" t2.reload() a.addTab(t2) t3 = t.clone() t3.titulo = "Twitter" t3.children[0].value = "https://Twitter.com" t3.reload() a.addTab(t3) t4 = t.clone() t4.titulo = "Instagram" t4.children[0].value = "https://Instagram.com" a.addTab(t4) t5 = t.clone() t5.titulo = "Correo electronico" t3.children[0].value = "*****@*****.**" a.addTab(t5) self.screen.appendToTab(1, a) check = CheckBoxList("Mostrar ubicación") check.value = [ ["Top Menu", False, "(Actual: Top Menu)"], [ "Menu de enlaces de Redes Sociales", False, "(Actual: Menu de enlaces de Redes Sociales)" ], ] self.screen.appendToTab(1, check) check2 = CheckBoxList("Opciones de menú") check2.value = [ [ "Agregar automaticamente nuevas paginas de nivel superior a este menu", False ], ] self.screen.appendToTab(1, check2) self.screen.tabs[1].find(">div:nth-child(n+2)").css({ "padding-left": "20px", "padding-right": "20px" }) w = HeaderCustomize("Top Menú") w.slider = self.slider w._atras = 1 w._screen = 3 self.screen.appendToTab(2, w) w = Input() w.value = "Top Menu" self.screen.appendToTab(2, w) a = Acordion() t = t.clone() t.titulo = "Inicio" a.addTab(t) t = t.clone() t.titulo = "Acerca de" t.descripcion = "Pagina" a.addTab(t) t = t.clone() t.titulo = "Blog" t.descripcion = "Pagina" a.addTab(t) t = t.clone() t.titulo = "Contacto" t.descripcion = "Pagina" a.addTab(t) self.screen.appendToTab(2, a) check = check.clone() self.screen.appendToTab(2, check) check2 = check2.clone() self.screen.appendToTab(2, check2.clone()) self.css({ "padding-left": "20px", "padding-right": "20px" }, None, ">div:nth-child(n+2)")
class runable(object): ''' Class for selecting keywords and extracting keywords from online contentent. ''' def __init__(self, llwl='Brown', llNL=2, percen=80, NE=True, Col=True, Gram=True, Chu=True): ''' @param llwl:LogLikleyHood Corpa name ('Brown','AmE06','BE06') @param llNL:LogLikleyHood @param percen: Presision of output default = 20, 20% returned @param NE: Uses NE default True @param Col: Uses Collocation default True @param Gram: Uses N-Grams default True @param Chu: Uses Chunking default True ''' self.NEs = NE self.Col = Col self.Gram = Gram self.Chu = Chu self.p = percen print 'Starting to build ', llwl self.LL = LogLikelihood(wordlist=llwl, NLength=llNL) print 'LL Loaded' self.POS = POS() print 'POS Loaded' self.GD = GetData() print 'GD Loaded' self.Cu = Chunker(self.POS) print 'Cu Loaded' self.FL = Filter() print 'FL Loaded' self.CC = Collocation(self.POS) print 'CC Loaded' self.Ng = NGram() print 'Ng Loaded' self.S = Select(percentil=self.p) print 'S Loaded' self.To = Tokenize(self.FL) print 'To Loaded' def Select(self, url, depth): ''' Determin the best keywords for a webpage. @param url: the base url to start sampaling from @param depth: the depth of the website to be sampled @return: the list of selected keywords, ordered with the highest rated words to the lower bownd of array. ''' #Get data from web page text = self.GD.getWebPage(url, depth) #Tokonize sentance and words tok = self.To.Tok(text) #POS tag the text pos = self.POS.POSTag(tok, 'tok') #Log Likly Hood log = self.LL.calcualte(tok) #Collocations if self.Col == True: col = self.CC.col(pos, tok) else: col = [] #NE Extraction if self.NEs == True: ne = self.Cu.Chunks(pos, nodes=['PERSON', 'ORGANIZATION', 'LOCATION']) else: ne = [] #Extract NP if self.Chu == True: chu = [self.Cu.parse(p) for p in pos] else: chu = [] #Creat N-gram if self.Gram == True: ga = self.Ng.Grams(pos, n=6) else: ga = [] return self.S.keywords(ne, ga, col, chu, log)
#种群初始化 pop = np.random.randint(min_x_value, (max_x_value - 1), size=[popsize, 1]) #种群初始化 #变量初始化 GN = 0 #记录进化过程遗传代数 less_df_cnt = 0 #几率两代最优个体适应度差值连续小于上限的次数 best_code = Evaluate(pop) #记录进化最优个体,初始化 history_best_code = np.zeros((max_GN_limitation, 1), dtype=np.int) #记录每一代最优个体 history_cut = 0 #记录最优个体数组‘history_best_code’的索引 #开始遗传迭代 while GN < max_GN_limitation: #执行遗传、交叉、变异操作,产生新种群 pop = Select(pop, ps) pop = Crossover(pop, pc) pop = Mutation(pop, pm) current_beat_code = Evaluate(pop) #记录当前种群最优个体 #判断是否结束遗传过程 if np.abs(fit_function(best_code) - fit_function(current_beat_code)) < df_max: less_df_cnt += 1 else: less_df_cnt = 0 if less_df_cnt >= less_df_n: break #模拟退火
def images_sample(self, new_folder, root_dir, ns, n_jobs=None, fix_rotation=None, resize=None, required_columns=None, seed=None, attempts=None, timeout=None, wait=None, common_download_errors=None): """ Samples n random images and builds a new dataset in new_folder where only the specified classes are present Parameters ---------- new_folder : str New folder to place new CSV's root_dir : str Root directory containing csv files and new folder ns : tuple of int Number of images to select for (training, validation, test) respectively, if any are None all are sampled n_jobs : int Number of images to download in parallel at once. Default of 9, as there are around 9 farms, so this means on average we'll only be making 1 request to a farm at a time fix_rotation : bool Whether to fix the rotation of the image, by default true, see here for more information https://storage.googleapis.com/openimages/web/2018-05-17-rotation-information.html resize : bool Whether to resize images as described in the Faster RCNN paper, and discussed here https://github.com/tensorflow/models/issues/1794#issuecomment-311569473 . Benefit is reduces storage space without effecting training if using the FasterRCNN Inception ResNet V2 architecture. Default is False. required_columns : list of str Set of columns required to not be the empty string for the row to be included in the sample seed : int Seed for random number generator attempts : int Maximum number of attempts to try downloading an image timeout : float Timeout in seconds for a request wait : float Time to wait after a failed download attempt common_download_errors : bool Whether to show common expected download error (HTTP 404 and 410) messages, default False """ seed = seed or 0 n_jobs = n_jobs or 9 fix_rotation = fix_rotation if fix_rotation is not None else True new_root = os.path.join(root_dir, new_folder) images_folder = os.path.join(new_root, "images") if not os.path.isdir(new_root): os.mkdir(new_root) if not os.path.isdir(images_folder): os.mkdir(images_folder) subsets = ["train", "validation", "test"] for i in range(len(subsets)): subset = subsets[i] n = ns[i] print("Building subset for {}".format(subset)) image_ids_file = self.common.get_image_ids_file(subset) image_ids_path = os.path.join(root_dir, image_ids_file) print("Loading images rows") rows = Select.get_rows(image_ids_path, required_columns=required_columns) selected_image_ids = set() subset_path = os.path.join(images_folder, subset) if not os.path.isdir(subset_path): os.mkdir(subset_path) if n is None: n = len(rows) else: print("Selecting {} rows".format(n)) random.seed(seed) random.shuffle(rows) pos = 0 pool = multiprocessing.Pool(n_jobs) downloader = partial(Common.pass_args_to_f, partial(Download.download_image, images_folder, resize=resize, download_folder=subset, attempts=attempts, timeout=timeout, wait=wait, common_download_errors=common_download_errors)) req = n print("Downloading images") while req > 0: args = [[row["ImageID"], row["OriginalMD5"], row["OriginalURL"], int(float(row["Rotation"])) if fix_rotation and row["Rotation"] is not '' else None] for row in rows[pos: pos + req]] successful_download_ids = tqdm(pool.imap(downloader, args)) for image_id in successful_download_ids: if image_id is not None: selected_image_ids.add(image_id) pos += req available = len(rows) - pos failed = n - len(selected_image_ids) req = min(failed, available) if req > 0: print("Failed to download {} images, trying to download next {} instead".format(failed, req)) image_labels_file = self.common.get_image_labels_file(subset) to_process = [image_ids_file, image_labels_file] if not self.image_level: to_process.append(self.common.get_boxes_file(subset)) print("Creating new CSVs for subset") for csv_file in to_process: Common.copy_rows_on_image_id(root_dir, new_folder, csv_file, selected_image_ids)
class runable(object): ''' Class for selecting keywords and extracting keywords from online contentent. ''' def __init__(self, llwl='Brown', llNL=2, percen=80, NE = True, Col = True, Gram = True, Chu = True): ''' @param llwl:LogLikleyHood Corpa name ('Brown','AmE06','BE06') @param llNL:LogLikleyHood @param percen: Presision of output default = 20, 20% returned @param NE: Uses NE default True @param Col: Uses Collocation default True @param Gram: Uses N-Grams default True @param Chu: Uses Chunking default True ''' self.NEs = NE self.Col = Col self.Gram = Gram self.Chu = Chu self.p = percen print 'Starting to build ', llwl self.LL = LogLikelihood(wordlist=llwl, NLength=llNL) print 'LL Loaded' self.POS = POS() print 'POS Loaded' self.GD = GetData() print 'GD Loaded' self.Cu = Chunker(self.POS) print 'Cu Loaded' self.FL = Filter() print 'FL Loaded' self.CC = Collocation(self.POS) print 'CC Loaded' self.Ng = NGram() print 'Ng Loaded' self.S = Select(percentil=self.p) print 'S Loaded' self.To = Tokenize(self.FL) print 'To Loaded' def Select(self, url, depth): ''' Determin the best keywords for a webpage. @param url: the base url to start sampaling from @param depth: the depth of the website to be sampled @return: the list of selected keywords, ordered with the highest rated words to the lower bownd of array. ''' #Get data from web page text = self.GD.getWebPage(url, depth) #Tokonize sentance and words tok = self.To.Tok(text) #POS tag the text pos = self.POS.POSTag(tok, 'tok') #Log Likly Hood log = self.LL.calcualte(tok) #Collocations if self.Col == True: col = self.CC.col(pos, tok) else: col = [] #NE Extraction if self.NEs == True: ne = self.Cu.Chunks(pos, nodes=['PERSON', 'ORGANIZATION', 'LOCATION']) else: ne = [] #Extract NP if self.Chu == True: chu = [self.Cu.parse(p) for p in pos] else: chu = [] #Creat N-gram if self.Gram == True: ga = self.Ng.Grams(pos, n=6) else: ga = [] return self.S.keywords(ne, ga , col , chu, log)
def select(columns): return Select(columns)