def __init_settings__(self): self.dibujar_imagen(self.fondo, self.width//2,self.height//2) self.focus=Focus() y=self.height//2+50 x=self.width//2 dy=40 self.print_text("Parametros de los Algoritmos",x-150, y-dy) level=str(self.game.minimax.MAX_LEVEL) self.nivel_textField=TextField(self.screen,self.focus, "Max Level: ",level,220,y) peso_dama=str(self.game.tablero.peso_dama) self.peso_dama_textField=TextField(self.screen,self.focus,"Peso Dama: ",peso_dama,220,y+dy) peso_normal=str(self.game.tablero.peso_normal) self.peso_normal_textField=TextField(self.screen,self.focus,"Peso Normal:",peso_normal,220,y+2*dy) y=100 dy=50 self.print_text("Algoritmos de busqueda",x-120,y+dy) self.minimax_button=self.cargar_imagen("img/minimax.png") self.minimax_button_rect=self.dibujar_imagen(self.minimax_button, x-100,y+2*dy) self.alpha_beta_button=self.cargar_imagen("img/alpha_beta.png") self.alpha_beta_button_rect=self.dibujar_imagen(self.alpha_beta_button,x+100,y+2*dy) self.print_text("Funciones de Evaluacion",x-120, y+3*dy) self.eval_suma_peso_button=self.cargar_imagen("img/suma_peso.png") self.eval_suma_peso_button_rect=self.dibujar_imagen(self.eval_suma_peso_button,x+100,y+4*dy) self.eval_suma_button=self.cargar_imagen("img/suma.png",) self.eval_suma_button_rect=self.dibujar_imagen(self.eval_suma_button,x-100,y+4*dy) self.button_clicked=self.cargar_imagen("img/button_clicked.png") pygame.display.flip()
def __init__(self, program, programSize, pos, font, w=100, h=600, borderColor=(0, 0, 0), fillColor=(240, 240, 240)): WindowRectangle.__init__(self, program, programSize, pos, w, h, borderColor, fillColor) self.rect_border.center = (self.pos[0], self.pos[1]) self.rect.center = (self.pos[0], self.pos[1]) self.username_field = TextField.TextField( (self.pos[0], self.pos[1] - self.height / 2 + 50), 20, "Username: "******"Server IP: ", font) self.server_pass_field = TextField.TextField( (self.pos[0], self.server_field.pos[1] + 50), 20, "Server Password: "******"Connect", font) self.load_cfg()
def __init__(self, program, programSize, pos, font, client, w=600, h=300, borderColor=(0, 0, 0), fillColor=(240, 240, 240)): WindowTextlist.__init__(self, program, programSize, pos, w, h, borderColor, fillColor) self.client = client self.counter = 0 self.chat_rect_border = pygame.Rect( 0, 0, self.width - 8, self.height - font.size("X")[1] - 26) self.chat_rect_border.topleft = (self.pos[0] + 4, self.pos[1] + 3) self.chat_rect = pygame.Rect(0, 0, self.width - 10, self.height - font.size("X")[1] - 28) self.chat_rect.topleft = (self.pos[0] + 5, self.pos[1] + 4) self.chat_field = TextField.TextField( (pos[0] + w / 2, pos[1] + h - font.size("X")[1] - 4), int(w / font.size("X")[0]) - (len(client.username) * 2) - 2, #max chars client.username, #username font) #font
def __init__(self, session): '''constructor''' gtk.VBox.__init__(self) self.session = session self.config_dir = session.config_dir self._enabled = True Avatar = extension.get_default('avatar') self.avatar = Avatar(cell_dimension=48) self.avatarBox = gtk.EventBox() self.avatarBox.set_events(gtk.gdk.BUTTON_PRESS_MASK) self.avatarBox.connect('button-press-event', self.on_avatar_click) self.avatarBox.add(self.avatar) self.avatarBox.set_tooltip_text(_('Click here to set your avatar')) self.avatarBox.set_border_width(4) self.avatar_path = self.config_dir.get_path("last_avatar") if not self.session.config_dir.file_readable(self.avatar_path): path = gui.theme.image_theme.user else: path = self.avatar_path self.avatar.set_from_file(path) self.nick = TextField.TextField(session.contacts.me.display_name, session.contacts.me.account, False) self.nick.set_tooltip_text(_('Click here to set your nick name')) self.status = StatusButton.StatusButton(session) self.status.set_tooltip_text(_('Click here to change your status')) self.status.set_status(session.contacts.me.status) self.search = gtk.ToggleButton() self.search.set_tooltip_text(_('Search (Ctrl+F)')) self.mail = gtk.Button(label="(0)") self.mail.set_tooltip_text(_('Click here to access your mail')) self.mail.get_settings().set_property("gtk-button-images", True) self.mail.set_image( gtk.image_new_from_file(gui.theme.image_theme.mailbox)) self.mail.set_relief(gtk.RELIEF_NONE) self.search.set_image( gtk.image_new_from_stock(gtk.STOCK_FIND, gtk.ICON_SIZE_MENU)) self.search.set_relief(gtk.RELIEF_NONE) self.empty_message_text = _("Click here to set your message") self.message = TextField.TextField( session.contacts.me.message, '[I]' + self.empty_message_text + '[/I]', True) self.message.set_tooltip_text(self.empty_message_text) self.toolbar = gtk.HBox() hbox = gtk.HBox() hbox.set_border_width(1) hbox.pack_start(self.avatarBox, False) vbox = gtk.VBox() nick_hbox = gtk.HBox() nick_hbox.pack_start(self.nick, True, True) nick_hbox.pack_start(self.mail, False) nick_hbox.pack_start(self.search, False) # enable this code and you'll get a nice button which fires a signal #def do_something_weird(item): # from e3.base.Event import Event # session.add_event(Event.EVENT_DISCONNECTED, 'Tested disconnection', 0) #test_btn=gtk.Button(label="(!)") #test_btn.connect('clicked', do_something_weird) #test_btn.show() #nick_hbox.pack_start(test_btn, False) vbox.pack_start(nick_hbox, False) message_hbox = gtk.HBox() message_hbox.pack_start(self.message, True, True) message_hbox.pack_start(self.status, False) vbox.pack_start(message_hbox, False) hbox.pack_start(vbox, True, True) self.pack_start(hbox, True, True) self.pack_start(self.toolbar, False) hbox.show() nick_hbox.show() message_hbox.show() vbox.show() self._add_subscriptions()
def Add(self, display_surf, type, xmlObject): if type == 'text': line = xmlObject.firstChild.data words = line.split(' ') self.bloc.append(words) self.tipus.append('text') for word in words: tmpSurf = self.font.render(word, 1, Constants.colorBlack) surf = pygame.Surface((self.font.size(word))).convert() surf.fill(self.backgroundColor) if (self.xActCell + self.font.size(word)[0]) > self.Rect.width - 10: self.xActCell = self.X_NEW_LINE self.yActCell += self.OFFSET_TOP_NEW_LINE surf.blit(tmpSurf, (0, 0)) rect = pygame.Rect((self.xActCell, self.yActCell), (surf.get_size())) textCell = TextCell(rect, self.idCell, 'text') contentCell = ContentCell() contentCell.img = surf.copy() if (self.isOrder != None): contentCell.id = None else: contentCell.id = self.idCell self.idCell = self.idCell + 1 textCell.contentCell = contentCell self.textCells.append(textCell) #self.idCell = self.idCell + 1 self.xActCell += rect.width + 5 if self.xActCell >= self.Rect.width - 10: self.xActCell = self.X_NEW_LINE self.yActCell += self.OFFSET_TOP_NEW_LINE elif type == 'text2': if (xmlObject == '\n'): self.bloc.append('\n') self.tipus.append('return') else: line = xmlObject.firstChild.data try: text = xmlObject.getElementsByTagName( "text")[0].firstChild.data line = text except: pass words = line.split(' ') self.bloc.append(words) self.numeracio.append(self.numCells) self.tipus.append('text2') self.lenTipus2 += 1 for word in words: tmpSurf = self.font.render(word, 1, Constants.colorLila) surf = pygame.Surface((self.font.size(word))).convert() surf.fill(Constants.colorBlack) if (self.xActCell + self.font.size(word)[0]) > self.Rect.width - 10: self.xActCell = self.X_NEW_LINE self.yActCell += self.OFFSET_TOP_NEW_LINE surf.blit(tmpSurf, (0, 0)) rect = pygame.Rect((self.xActCell, self.yActCell), (surf.get_size())) textCell = TextCell(rect, self.idCell, 'text') contentCell = ContentCell() contentCell.img = surf.copy() contentCell.id = self.id textCell.contentCell = contentCell textCell.contentCell.id = self.id self.textCells2.append(textCell) self.numCells += 1 #self.idCell = self.idCell + 1 self.xActCell += rect.width + 5 if self.xActCell >= self.Rect.width - 10: self.xActCell = self.X_NEW_LINE self.yActCell += self.OFFSET_TOP_NEW_LINE self.ids.append(self.id) self.id += 1 elif type == 'cell': try: width = int(xmlObject.getAttribute('width')) height = int(xmlObject.getAttribute('height')) image = xmlObject.getAttribute('image') image = self.mediaBag[image] fullPath = self.pathToMedia + '/' + image cellRect = pygame.Rect(self.xActCell, self.yActCell, width, height) cell = Cell(cellRect, display_surf, self.idCell, True) contentCell = ContentCell() contentCell.id = self.idCell contentCell.img = pygame.Surface((width, height)) cellImg = pygame.image.load(fullPath).convert_alpha() cellImg = pygame.transform.scale(cellImg, (width, height)) contentCell.img.blit(cellImg, (0, 0)) cell.contentCell = contentCell self.textCells.append(cell) self.idCell += 1 self.xActCell += width + int( (Constants.ACTIVITY_WIDTH - (self.numCells * width)) / self.numCells) except: pass elif type == 'textField': textField = TextField(xmlObject, self.font, self.backgroundColor) textField.Load(self.xActCell, self.yActCell, display_surf) textCell = TextCell(None, self.idCell, 'textField') textCell.contentCell = textField self.textCells.append(textCell) self.idCell += 1 self.xActCell = self.X_NEW_LINE self.yActCell += textField.textCell.Rect.height + self.OFFSET_TOP_NEW_LINE elif type == 'target': try: '''Si el target es de tipus optionList''' xmlObject.getElementsByTagName('optionList') if (self.xActCell + Constants.widthOpt + self.font.size('V')[0]) > self.Rect.width: self.xActCell = self.X_NEW_LINE self.yActCell += self.OFFSET_TOP_NEW_LINE option = OptionList(xmlObject, self.font) option.Load(self.xActCell, self.yActCell, display_surf) optionCell = TextCell(None, self.idCell, 'option') optionCell.contentCell = option self.textCells.append(optionCell) self.idCell = self.idCell + 1 self.xActCell += option.textCell.Rect.width + option.openCell.Rect.width + 5 if self.xActCell >= self.Rect.width: self.xActCell = self.X_NEW_LINE self.yActCell += self.OFFSET_TOP_NEW_LINE return except: print 'no es optionList' try: '''Si el target es de tipus response''' xmlObject.getElementsByTagName('response') print 'es de tipus response' resp = Response(xmlObject, self.font, self.backgroundColor) resp.Load(self.xActCell, self.yActCell, display_surf) respCell = TextCell(None, self.idCell, 'response') respCell.contentCell = resp self.textCells.append(respCell) self.idCell += 1 self.xActCell += respCell.contentCell.totalWidth + 5 if self.xActCell >= self.Rect.width: self.xActCell = self.X_NEW_LINE self.yActCell += self.OFFSET_TOP_NEW_LINE return except: print 'no es de tipus response'
def __init__(self, session): '''constructor''' gtk.VBox.__init__(self) self.session = session self.config_dir = session.config_dir self._enabled = True Avatar = extension.get_default('avatar') self.avatar = Avatar(cellDimention=48) self.avatarBox = gtk.EventBox() self.avatarBox.set_events(gtk.gdk.BUTTON_PRESS_MASK) self.avatarBox.connect('button-press-event', self.on_avatar_click) self.avatarBox.add(self.avatar) self.avatarBox.set_tooltip_text(_('Click here to set your avatar')) self.avatarBox.set_border_width(4) self.avatar_path = self.config_dir.get_path("last_avatar") if not self.session.config_dir.file_readable(self.avatar_path): path = gui.theme.user else: path = self.avatar_path self.avatar.set_from_file(path) self.nick = TextField.TextField(session.contacts.me.display_name, session.contacts.me.account, False) self.nick.set_tooltip_text(_('Click here to set your nick name')) self.status = StatusButton.StatusButton(session) self.status.set_tooltip_text(_('Click here to change your status')) self.status.set_status(session.contacts.me.status) self.search = gtk.ToggleButton() self.search.set_tooltip_text(_('Search (Ctrl+F)')) self.mail = gtk.Button(label="(0)") self.mail.set_tooltip_text(_('Click here to access your mail')) self.mail.get_settings().set_property("gtk-button-images", True) self.mail.set_image(gtk.image_new_from_file(gui.theme.mailbox)) self.mail.set_relief(gtk.RELIEF_NONE) self.search.set_image( gtk.image_new_from_stock(gtk.STOCK_FIND, gtk.ICON_SIZE_MENU)) self.search.set_relief(gtk.RELIEF_NONE) self.message = TextField.TextField( session.contacts.me.message, '[C=#969696][I]' + _("Click here to set your message") + '[/I][/C]', True) self.message.set_tooltip_text(_('Click here to set your message')) self.toolbar = gtk.HBox() hbox = gtk.HBox() hbox.set_border_width(1) hbox.pack_start(self.avatarBox, False) vbox = gtk.VBox() nick_hbox = gtk.HBox() nick_hbox.pack_start(self.nick, True, True) nick_hbox.pack_start(self.mail, False) nick_hbox.pack_start(self.search, False) vbox.pack_start(nick_hbox, False) message_hbox = gtk.HBox() message_hbox.pack_start(self.message, True, True) message_hbox.pack_start(self.status, False) vbox.pack_start(message_hbox, False) hbox.pack_start(vbox, True, True) self.pack_start(hbox, True, True) self.pack_start(self.toolbar, False) hbox.show() nick_hbox.show() message_hbox.show() vbox.show() session.signals.message_change_succeed.subscribe( self.on_message_change_succeed) session.signals.media_change_succeed.subscribe( self.on_media_change_succeed) session.signals.status_change_succeed.subscribe( self.on_status_change_succeed) session.signals.contact_list_ready.subscribe( self.on_contact_list_ready) session.signals.picture_change_succeed.subscribe( self.on_picture_change_succeed) session.signals.profile_get_succeed.subscribe( self.on_profile_update_succeed) session.signals.profile_set_succeed.subscribe( self.on_profile_update_succeed)
class Settings: def __init__(self, screen,fondo,width,height): self.screen=screen self.width, self.height=width,height self.fondo=fondo self.new_game_rect=None ''' Reutilizamos codigo de la clase Damas.py ''' def set_gui_fuctions(self, cargar_imagen, dibujar_imagen,print_text): self.cargar_imagen=cargar_imagen self.dibujar_imagen=dibujar_imagen self.print_text=print_text def set_ia_game(self, game): self.game=game def __init_settings__(self): self.dibujar_imagen(self.fondo, self.width//2,self.height//2) self.focus=Focus() y=self.height//2+50 x=self.width//2 dy=40 self.print_text("Parametros de los Algoritmos",x-150, y-dy) level=str(self.game.minimax.MAX_LEVEL) self.nivel_textField=TextField(self.screen,self.focus, "Max Level: ",level,220,y) peso_dama=str(self.game.tablero.peso_dama) self.peso_dama_textField=TextField(self.screen,self.focus,"Peso Dama: ",peso_dama,220,y+dy) peso_normal=str(self.game.tablero.peso_normal) self.peso_normal_textField=TextField(self.screen,self.focus,"Peso Normal:",peso_normal,220,y+2*dy) y=100 dy=50 self.print_text("Algoritmos de busqueda",x-120,y+dy) self.minimax_button=self.cargar_imagen("img/minimax.png") self.minimax_button_rect=self.dibujar_imagen(self.minimax_button, x-100,y+2*dy) self.alpha_beta_button=self.cargar_imagen("img/alpha_beta.png") self.alpha_beta_button_rect=self.dibujar_imagen(self.alpha_beta_button,x+100,y+2*dy) self.print_text("Funciones de Evaluacion",x-120, y+3*dy) self.eval_suma_peso_button=self.cargar_imagen("img/suma_peso.png") self.eval_suma_peso_button_rect=self.dibujar_imagen(self.eval_suma_peso_button,x+100,y+4*dy) self.eval_suma_button=self.cargar_imagen("img/suma.png",) self.eval_suma_button_rect=self.dibujar_imagen(self.eval_suma_button,x-100,y+4*dy) self.button_clicked=self.cargar_imagen("img/button_clicked.png") pygame.display.flip() ''' metodos que tienen que ver con el formulario a completar ''' def printText(self,str,i,j,size=50, color=(255,255,255)): pygame.font.init() fuente = pygame.font.Font(None, size) texto = fuente.render(str, 1, color) self.screen.blit(texto, (i, j)) pygame.display.flip() ''' Fin de metodos de formulario ''' def set_clicked(self,eval_suma_focus, minimax_focus): x_suma,y_suma=self.eval_suma_button_rect.center self.dibujar_imagen(self.eval_suma_button,x_suma,y_suma) x_peso,y_peso=self.eval_suma_peso_button_rect.center self.dibujar_imagen(self.eval_suma_peso_button,x_peso,y_peso) x_mini,y_mini=self.minimax_button_rect.center self.dibujar_imagen(self.minimax_button,x_mini,y_mini) x_poda,y_poda=self.alpha_beta_button_rect.center self.dibujar_imagen(self.alpha_beta_button,x_poda,y_poda) if(eval_suma_focus): self.dibujar_imagen(self.button_clicked,x_suma,y_suma) else: self.dibujar_imagen(self.button_clicked,x_peso,y_peso) if minimax_focus: self.dibujar_imagen(self.button_clicked,x_mini,y_mini) else: self.dibujar_imagen(self.button_clicked,x_poda,y_poda) pygame.display.flip() def start_config(self): clock=pygame.time.Clock() self.__init_settings__() minimax_function=Minimax() tablero_function=Tablero() minimax_focus=True eval_suma_focus=False self.set_clicked(eval_suma_focus, minimax_focus) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: quit = True pygame.quit() #Se hizo click elif event.type == 5: mouse_x, mouse_y = pygame.mouse.get_pos() self.nivel_textField.is_selected(mouse_x, mouse_y) self.peso_dama_textField.is_selected(mouse_x, mouse_y) self.peso_normal_textField.is_selected(mouse_x, mouse_y) if(self.minimax_button_rect.collidepoint(mouse_x, mouse_y)): self.game.minimax.start=minimax_function.minimax print "minimax" minimax_focus=True elif(self.alpha_beta_button_rect.collidepoint(mouse_x, mouse_y)): self.game.minimax.start=minimax_function.minimax_alpha_beta minimax_focus=False elif(self.eval_suma_peso_button_rect.collidepoint(mouse_x, mouse_y)): self.game.tablero.start=tablero_function.evaluar_suma_peso eval_suma_focus=False elif(self.eval_suma_button_rect.collidepoint(mouse_x, mouse_y)): self.game.tablero.start=tablero_function.evaluar_suma eval_suma_focus=True #al juego elif self.new_game_rect.collidepoint(mouse_x, mouse_y): self.game.minimax.MAX_LEVEL= int(self.nivel_textField.text.text) self.game.tablero.peso_dama=int(self.peso_dama_textField.text.text) self.game.tablero.peso_normal=int(self.peso_normal_textField.text.text) return True self.set_clicked(eval_suma_focus, minimax_focus) elif event.type== pygame.KEYDOWN: key=event.key if(self.nivel_textField.get_focus()): self.nivel_textField.set_key_presed(key) elif self.peso_dama_textField.get_focus(): self.peso_dama_textField.set_key_presed(key) elif self.peso_normal_textField.get_focus(): self.peso_normal_textField.set_key_presed(key) clock.tick(50)
def __init__(self, session): '''constructor''' gtk.VBox.__init__(self) self.session = session self.config_dir = session.config_dir self._enabled = True Avatar = extension.get_default('avatar') AvatarManager = extension.get_default('avatar manager') self.avatar = Avatar(cellDimention=48) self.avatarBox = gtk.EventBox() self.avatarBox.set_events(gtk.gdk.BUTTON_PRESS_MASK) self.avatarBox.connect('button-press-event', self.on_avatar_click) self.avatarBox.add(self.avatar) self.avatarBox.set_tooltip_text(_('Click here to set your avatar')) self.avatar_path = self.config_dir.get_path("last_avatar") self.avatar_manager = AvatarManager(self.session) if not self.session.config_dir.file_readable(self.avatar_path): path = gui.theme.user else: path = self.avatar_path self.avatar.set_from_file(path) self.nick = TextField.TextField(session.contacts.me.display_name, '', False) self.status = StatusButton.StatusButton(session) self.status.set_status(session.contacts.me.status) self.search = gtk.ToggleButton() self.search.set_image( gtk.image_new_from_stock(gtk.STOCK_FIND, gtk.ICON_SIZE_MENU)) self.search.set_relief(gtk.RELIEF_NONE) self.message = TextField.TextField( session.contacts.me.message, '<span style="italic"><Click here to set message></span>', True) self.toolbar = gtk.HBox() hbox = gtk.HBox() hbox.set_border_width(2) hbox.pack_start(self.avatarBox, False) vbox = gtk.VBox() nick_hbox = gtk.HBox() nick_hbox.pack_start(self.nick, True, True) nick_hbox.pack_start(self.search, False) vbox.pack_start(nick_hbox, False) message_hbox = gtk.HBox() message_hbox.pack_start(self.message, True, True) message_hbox.pack_start(self.status, False) vbox.pack_start(message_hbox, False) hbox.pack_start(vbox, True, True) self.pack_start(hbox, True, True) self.pack_start(self.toolbar, False) hbox.show() nick_hbox.show() message_hbox.show() vbox.show() session.signals.message_change_succeed.subscribe( self.on_message_change_succeed) session.signals.media_change_succeed.subscribe( self.on_media_change_succeed) session.signals.status_change_succeed.subscribe( self.on_status_change_succeed) session.signals.contact_list_ready.subscribe( self.on_contact_list_ready) session.signals.picture_change_succeed.subscribe( self.on_picture_change_succeed) session.signals.profile_get_succeed.subscribe( self.on_profile_update_succeed) session.signals.profile_set_succeed.subscribe( self.on_profile_update_succeed)