Python : convertir é et è

Bonjour,

J'ai développé un toolkit pour un jeu en ligne appellé "grepolis" !

Voici mon problème, la liste de donné télécharger (donné d'alliances, joueurs, villes, pts, ...) ne contient pas de é et è mais de %C3%A9 ! Ce qui pose un problème lors de recherche ! Mon logiciel affichant dans les listebox exactement ce qui est ecrit ! J'ai remplacé manuellement qq %C3%A9 par des é et les a très bien affiché !

D'où ma question, comment les convertirs automatiquement ??

4 réponses

  1. Mon programme : (trop long donc en 4 fois ;)

    #!/usr/bin/python
    # -*- coding: iso-8859-1 -*-
    import wx, os, shutil, sys, time, datetime
    import urllib2
    from urllib2 import urlopen
    import pygame
    from pygame.locals import *
    from pygame.font import *
    from datetime import datetime, date

    # The following line is a solution to the problem
    # "pygame.error: No available video device"
    # but might cause problems for other users
    os.environ['SDL_VIDEODRIVER'] = 'windib'

    global pics_hor; pics_hor = 500
    global pics_ver; pics_ver = 500
    global BLACK; BLACK = (0, 0, 0)
    global WHITE; WHITE = (255, 255, 255)
    global RED; RED = (255, 0, 0)
    global GREEN; GREEN = (0, 255, 0)
    global BLUE; BLUE = (0, 0, 255)
    global GREY; GREY = (100, 100, 100)
    global G_BROWN_1; G_BROWN_1 = (193, 153, 57)
    global G_BROWN_2; G_BROWN_2 = (255, 224, 155)

    global pygame_events_on
    global px, py, xpos, ypos, zoom, pxz, pyz
    px=500 # map x-size in pixels
    py=500 # map y-size in pixels
    xpos=0 # x-offset for drawing the map
    ypos=0 # y-offset for drawing the map
    zoom=1
    pxz = px/zoom
    pyz = py/zoom

    #-------------------------------------------------------------------------------
    # Here the main user interface window is created
    #-------------------------------------------------------------------------------
    #!/usr/bin/python
    # -*- coding: utf-8 -*-
    class Menu(wx.Frame):
    def __init__(self, parent, id, title):
    wx.Frame.__init__(self, parent, id, title='Grepolis Toolkit', pos = (0,0), size=(1020, 720))

    #-----------------------------------------------------------------------
    # Creating the menu
    #-----------------------------------------------------------------------

    # load the URLs from the config file
    LoadConfigData()
    self.MakeWorldMap()

    # Create the panel to put the widgets on
    panel = wx.Panel(self)
    panel.SetBackgroundColour(WHITE)

    # Create a menu bar with a file menu and a map menu
    menubar = wx.MenuBar()
    file = wx.Menu()
    map = wx.Menu()

    # Define the choices for the file menu
    Fetch_data = wx.MenuItem(file, 1, '&Télécharger les données de ce monde\tCtrl+F')
    file.AppendItem(Fetch_data)
    Load_data = wx.MenuItem(file, 2, '&Charger les données existantes de ce monde\tCtrl+L')
    file.AppendItem(Load_data)
    quit = wx.MenuItem(file, 3, '&Quitter\tCtrl+Q')
    file.AppendItem(quit)

    # Define the choices for the map menu
    Show_map = wx.MenuItem(map, 4, '&Montrer/recharger la carte\tCtrl+M')
    map.AppendItem(Show_map)
    Draw_cities = wx.MenuItem(map, 6, '&Dessiner les villes\tCtrl+C')
    map.AppendItem(Draw_cities)
    Draw_conquers = wx.MenuItem(map, 9, '&Montrer la carte des conquêtes\tCtrl+C')
    map.AppendItem(Draw_conquers)
    Save_Map = wx.MenuItem(map, 8, '&Sauvegarder la carte\tCtrl+S')
    map.AppendItem(Save_Map)
    testbutton = wx.MenuItem(map, 7, '&Bouton Test\tCtrl+C')
    map.AppendItem(testbutton)

    # Link the choices to the def routines
    self.Bind(wx.EVT_MENU, self.OnFetchData, id=1)
    self.Bind(wx.EVT_MENU, self.OnLoadData, id=2)
    self.Bind(wx.EVT_MENU, self.OnQuit, id=3)
    self.Bind(wx.EVT_MENU, self.OnShowMap, id=4)
    self.Bind(wx.EVT_MENU, self.OnDrawCities, id=6)
    self.Bind(wx.EVT_MENU, Ontestbutton, id=7)
    self.Bind(wx.EVT_MENU, self.OnSaveMap, id=8)
    self.Bind(wx.EVT_MENU, self.OnShowConquers, id=9)

    # Add the menus to the menu bar
    menubar.Append(file, '&Fichier')
    menubar.Append(map, '&Carte')

    # add the menu bar to the window
    self.SetMenuBar(menubar)
    self.statusbar = self.CreateStatusBar()

    #-----------------------------------------------------------------------
    # Creating player data section
    #-----------------------------------------------------------------------
    #!/usr/bin/python
    # -*- coding: iso-8859-1 -*-
    box1=wx.StaticBox(panel, -1, 'Données du monde', pos=(5, 3), size=(170, 140))

    # Create the text labels and widgets on the interface window
    self.aw = aw
    world_label = wx.StaticText(panel, -1, 'Monde: ', (10, 20))
    self.world_box = wx.ComboBox(panel, -1, str(world[aw]), pos=(50, 17), size=(100, 10), name = 'World')
    self.world_box.SetBackgroundColour(WHITE)
    for w in range(0, len(world)):
    self.world_box.Append(world[w])

    players = "Pas de données"
    self.players_text = wx.StaticText(panel, -1, players, (80, 40), (90,60))
    self.players_label = wx.StaticText(panel, -1, "Joueurs:", (10, 40))

    alliances = "Pas de données"
    self.alliances_text = wx.StaticText(panel, -1, alliances, (80, 60), (90,20))
    self.alliances_label = wx.StaticText(panel, -1, "Alliances:", (10, 60))

    cities = "Pas de données"
    self.cities_text = wx.StaticText(panel, -1, cities, (80, 80), (90,20))
    self.cities_label = wx.StaticText(panel, -1, "Villes:", (10, 80))

    islands = "Pas de données"
    self.islands_text = wx.StaticText(panel, -1, islands, (80, 100), (90,20))
    self.islands_label = wx.StaticText(panel, -1, "Iles:", (10, 100))

    conquers = "Pas de données"
    self.conquers_text = wx.StaticText(panel, -1, conquers, (80, 120), (90,20))
    self.conquers_label = wx.StaticText(panel, -1, "Conquêtes:", (10, 120))

    #-----------------------------------------------------------------------
    # Creating the conquer map section
    #-----------------------------------------------------------------------

    box2=wx.StaticBox(panel, -1, 'Carte des conquêtes', pos=(185, 3), size=(170, 140))
    date_start_text = wx.StaticText(panel, -1, 'Selectionner une première date', (190,22), (150,20))
    self.start_date=wx.DatePickerCtrl(panel, -1, size=(120, -1), pos=(200,40),
    style=wx.DP_DROPDOWN | wx.DP_SHOWCENTURY)

    date_end_text = wx.StaticText(panel, -1, 'Selectionner une deuxième date', (190,62), (160,20))
    self.end_date=wx.DatePickerCtrl(panel, -1, size=(120, -1), pos=(200,80),
    style=wx.DP_DROPDOWN | wx.DP_SHOWCENTURY)

    self.ok_button=wx.Button(panel, -1, "Dessiner la carte", pos=(193, 110))
    self.ok_button.SetBackgroundColour(WHITE)
    self.Bind(wx.EVT_BUTTON, self.OnShowConquers, self.ok_button)
    #-----------------------------------------------------------------------
    # Creating the message alliance section
    #-----------------------------------------------------------------------
    box1=wx.StaticBox(panel, -1, 'Message pour alliance', pos=(500, 50), size=(500, 500))
    self.copy_players = wx.ListBox(panel, -1, pos=(550, 100), size=(140, 270))
    self.copy_players.SetBackgroundColour(WHITE)
    self.Bind(wx.EVT_BUTTON, self.OnCopyPlayers, self.copy_players)
    1. #----------------
      # Load conquer data
      #----------------

      global conquer_town_ID; conquer_town_ID = []
      global conquer_time; conquer_time = []
      global conquer_new_player_ID; conquer_new_player_ID = []
      global conquer_old_player_ID; conquer_old_player_ID = []
      global conquer_new_ally_ID; conquer_new_ally_ID = []
      global conquer_old_ally_ID; conquer_old_ally_ID = []
      global conquer_town_points; conquer_town_points = []

      fn = r'data\world_' + world[self.aw]+ '_conquers.txt'
      f = open(fn, 'r')
      self.conquers_text.SetLabel("Chargement...")
      x = 0
      conquer = f.readline()
      while (len(conquer) > 0):
      k1 = conquer.find(',')
      k2 = conquer.find(',', k1+1)
      k3 = conquer.find(',', k2+1)
      k4 = conquer.find(',', k3+1)
      k5 = conquer.find(',', k4+1)
      k6 = conquer.find(',', k5+1)
      conquer_town_ID.append(conquer[0:k1])
      conquer_time.append(conquer[k1+1:k2])
      conquer_new_player_ID.append(conquer[k2+1:k3])
      conquer_old_player_ID.append(conquer[k3+1:k4])
      conquer_new_ally_ID.append(conquer[k4+1:k5])
      conquer_old_ally_ID.append(conquer[k5+1:k6])
      conquer_town_points.append(conquer[k6+1:len(conquer)-1])
      x+=1
      conquer = f.readline()
      f.close()
      self.conquers_text.SetLabel(str(len(conquer_town_ID)))

      #-------------------------------------------------------------------------------
      # The following routines are initiated by pressing the filter button
      # The string entered in the text input field is collected
      # then the names containing the string are appended to the listbox
      #-------------------------------------------------------------------------------
      #!/usr/bin/python
      # -*- coding: iso-8859-1 -*-
      def OnFilterPlayer(self, event):
      self.player_listbox.Clear()
      s = self.player_filter.GetValue()
      for x in range (0, len(player_ID)):
      if s in player_name[x]:
      self.player_listbox.Append(str(player_name[x]))

      def OnFilterAlly(self, event):
      self.ally_listbox.Clear()
      s = self.ally_filter.GetValue()
      for x in range (0, len(alliance_ID)):
      if s in alliance_name[x]:
      self.ally_listbox.Append(str(alliance_name[x]))

      def OnFilterCities(self, event):
      self.cities_listbox.Clear()
      s = self.cities_filter.GetValue()
      for x in range (0, len(town_ID)):
      if s in town_name[x]:
      self.cities_listbox.Append(str(town_name[x]))

      def OnCopyPlayers(self, event):
      alliance_name = self.ally_listbox.GetStringSelection()
      alliance = get_alliance_ID(alliance_name)
      self.player_listbox.Clear()
      for player in range(0, len(player_ID)):
      if (str(player_alliance_ID[player]) == str(alliance)):
      self.player_listbox.Append(str(player_name[player]))

      def OnCopyCities(self, event):
      player_name = self.player_listbox.GetStringSelection()
      player = get_player_ID(player_name)
      self.cities_listbox.Clear()
      for city in range(0, len(town_ID)):
      # print str(town_player[city]), str(player)
      if (str(town_player[city]) == str(player)):
      self.cities_listbox.Append(str(town_name[city]))

      def OnCopyPlayersToClipboard(self, event):
      alliance_name = self.ally_listbox.GetStringSelection()
      alliance = get_alliance_ID(alliance_name)
      ct=''
      for player in range(0, len(player_ID)):
      if (str(player_alliance_ID[player]) == str(alliance)):
      ct=ct + '[player]'+(str(player_name[player]))+'/player\n'
      CopyToClipboard(ct)

      def OnCopyCitiesToClipboard(self, event):
      player_name = self.player_listbox.GetStringSelection()
      player = get_player_ID(player_name)
      ct=''
      for city in range(0, len(town_ID)):
      if (str(town_player[city]) == str(player)):
      ct=ct + '[town]'+(str(town_ID[city]))+'/town\n'
      CopyToClipboard(ct)

      #-------------------------------------------------------------------------------
      # The following toutines are initiated by pressing the draw button
      # The selected name is collected, then the corresponding ID is searched for
      # For one player the towns are checked and drawn if belonging to the player
      # For an alliance the players are checked and drawn if belonging to the alliance
      #-------------------------------------------------------------------------------

      def OnDrawCity(self, event):
      city_name = self.cities_listbox.GetStringSelection()
      t = town_name.index(city_name)
      color = choose_colour()
      x = int(town_island_x[t])
      y = int(town_island_y[t])
      self.draw_town(x, y, color, 'big')

      # Done drawing, now handle control to pygame
      pygame_events_on=1
      self.Handle_Pygame_Events(self)

      def OnDrawPlayer(self, event):
      player_name = self.player_listbox.GetStringSelection()
      player = get_player_ID(player_name)
      color = choose_colour()
      for town in range(0, len(town_ID)):
      if (town_player[town] == player):
      x = int(town_island_x[town])
      y = int(town_island_y[town])
      self.draw_town(x, y, color, 'big')

      # Done drawing, now handle control to pygame
      pygame_events_on=1
      self.Handle_Pygame_Events(self)

      def OnDrawAlly(self, event):
      alliance_name = self.ally_listbox.GetStringSelection()
      alliance = get_alliance_ID(alliance_name)
      color = choose_colour()
      for player in range(0, len(player_ID)):
      if (str(player_alliance_ID[player]) == str(alliance)):
      for town in range(0, len(town_ID)):
      if (town_player[town] == player_ID[player]):
      x = int(town_island_x[town])
      y = int(town_island_y[town])
      self.draw_town(x, y, color, 'big')

      # Done drawing, now handle control to pygame
      pygame_events_on=1
      self.Handle_Pygame_Events(self)

      def OnShowConquers(self, event):

      date_start = get_date(self.start_date.GetValue())
      date_end = get_date(self.end_date.GetValue())

      mark = pygame.image.load("mark2.tga").convert_alpha()
      print 'start date' + str(date_start)
      print 'end date' + str(date_end)
      for i in range(0, len(conquer_town_ID)):
      d=datetime.fromtimestamp(float(conquer_time[i]))
      date = d.date()
      if (date > date_start and date < date_end and len(conquer_old_player_ID[i])>1):
      c = conquer_town_ID[i]
      if c in town_ID:
      t = town_ID.index(c)
      x = int(town_island_x[t])
      y = int(town_island_y[t])
      name = town_name[t]
      player = get_player_name(town_player[t])
      self.worldmap.blit(mark, (x-5, y-5))

      # Done drawing, now handle control to pygame
      pygame_events_on=1
      self.Handle_Pygame_Events(self)

      #-------------------------------------------------------------------------------
      # This routine is initiated when another world is selected in the drop-down box
      #-------------------------------------------------------------------------------

      def OnSelectWorld(self, event):
      self.aw = self.world_box.GetSelection()

      #-------------------------------------------------------------------------------
      # This routine is selected when quit is selected from the menu bar
      #-------------------------------------------------------------------------------

      def OnQuit(self, event):
      pygame.quit()
      self.Close()

      #-------------------------------------------------------------------------------
      # This routine is selected when the show map is selected from the menu bar
      # A pygame surface withis created which opens in a new window
      #-------------------------------------------------------------------------------

      def OnShowMap(self, event):

      # os.environ['SDL_VIDEO_WINDOW_POS'] = ('5,20') # this positions the map screen top left.
      self.windowSurface = pygame.display.set_mode((px, py), RESIZABLE, 32)
      pygame.display.set_caption('Carte du monde de Grepolis')
      self.windowSurface.fill(BLACK)
      self.windowSurface.blit(self.worldmap, dest=(0,0) , area=(xpos, ypos, px, py))
      pygame.display.update()
      self.Handle_Pygame_Events(self)

      def Handle_Pygame_Events(self, event):
      global pygame_events_on
      global px, py, xpos, ypos, zoom, pxz, pyz
      pygame_events_on = 1 # handle pygame events
      move_screen=0 # dont move the screen
      redraw=1 # redraw the screen on first pass
      self.statusbar.SetStatusText('Handling pygame events on')
      while pygame_events_on:
      pygame.time.wait(10) # snooze a little to spare processor time
      for action in pygame.event.get():

      if action.type == QUIT: # User want to leave pygame control
      pygame.display.quit()
      pygame_events_on=0

      if action.type== VIDEORESIZE: # window screen was resized
      px = action.w
      py = action.h
      zoom = 1
      redraw=1

      if action.type == MOUSEMOTION: # mouse movenemt detected
      if move_screen==1: # map movement required?
      mouse_x = action.rel[0]
      mouse_y = action.rel[1]
      xpos=xpos-mouse_x # calculate new position
      ypos=ypos-mouse_y
      pxz = int(px/zoom)
      pyz = int(py/zoom)
      if (xpos<0): # dont leave the map area
      xpos=0
      if (ypos<0):
      ypos=0
      if (xpos+pxz>1000):
      xpos=1000-pxz
      if (ypos+pyz>1000):
      ypos=1000-pyz

      # In order to zoom the part of the worldmap the user wants to see
      # is copied to a temporary surface, next the surface is scaled
      # and copied to the window surface

      self.tempmap=pygame.Surface((px/zoom, py/zoom))
      self.tempmap.blit(self.worldmap, dest=(0,0) , area=(xpos, ypos, int(px/zoom), int(py/zoom)))
      pygame.transform.smoothscale(self.tempmap, (px, py), self.windowSurface)
      pygame.display.update()
      redraw=0

      if action.type == MOUSEBUTTONDOWN: # left mouse button pressed
      mouse_button = action.button
      if mouse_button == 1:
      move_screen=1

      if action.type == MOUSEBUTTONUP: # finished pressing left mouse button
      move_screen=0

      if action.type == KEYDOWN:

      if (action.key == K_UP): # Calculate new zoom factor
      zoom = zoom + 0.05
      redraw=1

      if (action.key == K_DOWN):
      zoom = zoom - 0.05
      redraw=1

      # Dont redraw the window surface when not needed because
      # the display_set_mode command causes a mouse-up event
      # which messes-up the scrolling of the window.

      if(redraw==1):
      self.windowSurface = pygame.display.set_mode((px, py), RESIZABLE)
      self.tempmap=pygame.Surface((px/zoom, py/zoom))
      self.tempmap.blit(self.worldmap, dest=(0,0) , area=(xpos, ypos, int(px/zoom), int(py/zoom)))
      pygame.transform.smoothscale(self.tempmap, (px, py), self.windowSurface)
      pygame.display.update()
      redraw=0
      self.statusbar.SetStatusText('Handling pygame events off')

      #-------------------------------------------------------------------------------
      # This routine makes a 1000x1000 world map that is NOT presented to the user
      # This is the original world-size map
      # It also draws the grid and places ocean numbers on the map
      #-------------------------------------------------------------------------------

      def MakeWorldMap(self):
      f=pygame.font.init()
      self.worldmap = pygame.Surface((1000, 1000))

      for i in range(1,11):
      pygame.draw.line(self.worldmap, (125, 125, 125), (100*i, 0), (100*i, 1000), 1)
      pygame.draw.line(self.worldmap, (125, 125, 125), (0, 100*i), (1000, 100*i), 1)
      self.show_text(str((i*10)-10), 100*(i-1)+2, 2, WHITE)
      self.show_text(str(i-1), 990, 100*(i-1)+2, WHITE)

      #-------------------------------------------------------------------------------
      # The following routine displays a text on the world map
      #-------------------------------------------------------------------------------

      def show_text(self, t, x, y, color):

      basicFont = pygame.font.Font("freesansbold.ttf", 20)
      text = basicFont.render(t, True, color, BLACK)
      textRect = text.get_rect()
      textRect.top = y
      textRect.left = x
      self.worldmap.blit(text, textRect)

      #-------------------------------------------------------------------------------
      # This routine draws all cities in the towns array
      #-------------------------------------------------------------------------------

      def OnDrawCities(self, event):
      for i in range(0, len(town_ID)):
      x = int(town_island_x[i])
      y = int(town_island_y[i])
      self.draw_town(x, y, GREY, 'small')

      # Done drawing, now handle control to pygame

      pygame_events_on=1
      self.Handle_Pygame_Events(self)

      #-------------------------------------------------------------------------------
      # The following routine draws one single town on the map
      # The town is made of 4 (small) or 8 (big) pixels
      #-------------------------------------------------------------------------------

      def draw_town(self, x, y, c, size):

      self.worldmap.set_at((x, y), c)
      self.worldmap.set_at((x+1, y), c)
      self.worldmap.set_at((x-1, y), c)
      self.worldmap.set_at((x, y+1), c)
      self.worldmap.set_at((x, y-1), c)

      if (size == 'big'):
      self.worldmap.set_at((x+1, y+1), c)
      self.worldmap.set_at((x+1, y-1), c)
      self.worldmap.set_at((x-1, y+1), c)
      self.worldmap.set_at((x-1, y-1), c)

      #-------------------------------------------------------------------------------
      # This routine saves the map as presented on the windowsurface
      #-------------------------------------------------------------------------------

      def OnSaveMap(self, event):
      dialog = wx.FileDialog(None, "Entrer le nom d'un fichier", style=wx.FD_SAVE)
      if dialog.ShowModal() == wx.ID_OK:
      filename = dialog.GetPath()
      dialog.Destroy()
      pygame.image.save(self.windowSurface, filename)

      #-------------------------------------------------------------------------------
      # Here the creation of the main user interface window ends
      # The following routines are not part of the user interface
      #-------------------------------------------------------------------------------

      #-------------------------------------------------------------------------------
      # This routine is used for testing purposes
      #-------------------------------------------------------------------------------

      def Ontestbutton(event):
      pass
      #print 'This is the test button allright'

      #-------------------------------------------------------------------------------
      # This routine loads the URLs of all worlds from the file grepomaps.cfg
      #-------------------------------------------------------------------------------

      def LoadConfigData():

      global aw;aw = 0
      global world; world = []
      global url_players; url_players = []
      global url_conquers; url_conquers = []
      global url_alliances; url_alliances = []
      global url_towns; url_towns = []
      global url_islands; url_islands = []

      f = open (r"grepomaps.cfg", 'r')
      line = f.readline()
      count = int(line[9:len(line)-1])

      for w in range(0,count):
      line = f.readline()
      world.append(line[8:len(line)-1])
      line = f.readline()
      url_players.append(line[14:len(line)-1])
      line = f.readline()
      url_conquers.append(line[15:len(line)-1])
      line = f.readline()
      url_alliances.append(line[16:len(line)-1])
      line = f.readline()
      url_towns.append(line[12:len(line)-1])
      line = f.readline()
      url_islands.append(line[14:len(line)-1])

      #-------------------------------------------------------------------------------
      # The following routines transfer IDs in names and vice versa
      #-------------------------------------------------------------------------------

      def get_player_ID(player):
      if player in player_name:
      return player_ID[player_name.index(player)]

      def get_player_name(player):
      if player in player_ID:
      return player_name[player_ID.index(player)]

      def get_alliance_ID(alliance):
      if alliance in alliance_name:
      return alliance_ID[alliance_name.index(alliance)]

      def get_alliance_name(alliance):
      if alliance in alliance_ID:
      return alliance_name[alliance_ID.index(alliance)]

      def get_date(datestring):
      yy=datestring.GetYear()
      mm=datestring.GetMonth()+1
      dd=datestring.GetDay()
      return date(yy, mm, dd)

      #-------------------------------------------------------------------------------
      # The following routine presents the colour chooser window and returns a colour
      #-------------------------------------------------------------------------------

      def choose_colour():
      dialog = wx.ColourDialog(None)
      dialog.GetColourData().SetChooseFull(True)
      if dialog.ShowModal() == wx.ID_OK:
      data = dialog.GetColourData()
      color = data.GetColour().Get()
      dialog.Destroy()
      return color

      def CopyToClipboard(text):
      text2=text.replace('+', ' ')
      clipdata = wx.TextDataObject()
      clipdata.SetText(text2)
      wx.TheClipboard.Open()
      wx.TheClipboard.SetData(clipdata)
      wx.TheClipboard.Close()

      #-------------------------------------------------------------------------------
      # At this point we're done with defining routines
      # The actual program (application) is initiated
      #
      # First the application that wxpython needs is defined
      # Next the menu window is generated and presented to the user
      # After that pygame is initiated
      # Then the application loop is entered waiting for user generated events
      #-------------------------------------------------------------------------------

      app = wx.App()
      Menu(None, -1, '')
      pygame.init() # initialise the pygame engine
      app.MainLoop()
      1. #----------------
        # Load conquer data
        #----------------

        global conquer_town_ID; conquer_town_ID = []
        global conquer_time; conquer_time = []
        global conquer_new_player_ID; conquer_new_player_ID = []
        global conquer_old_player_ID; conquer_old_player_ID = []
        global conquer_new_ally_ID; conquer_new_ally_ID = []
        global conquer_old_ally_ID; conquer_old_ally_ID = []
        global conquer_town_points; conquer_town_points = []

        fn = r'data\world_' + world[self.aw]+ '_conquers.txt'
        f = open(fn, 'r')
        self.conquers_text.SetLabel("Chargement...")
        x = 0
        conquer = f.readline()
        while (len(conquer) > 0):
        k1 = conquer.find(',')
        k2 = conquer.find(',', k1+1)
        k3 = conquer.find(',', k2+1)
        k4 = conquer.find(',', k3+1)
        k5 = conquer.find(',', k4+1)
        k6 = conquer.find(',', k5+1)
        conquer_town_ID.append(conquer[0:k1])
        conquer_time.append(conquer[k1+1:k2])
        conquer_new_player_ID.append(conquer[k2+1:k3])
        conquer_old_player_ID.append(conquer[k3+1:k4])
        conquer_new_ally_ID.append(conquer[k4+1:k5])
        conquer_old_ally_ID.append(conquer[k5+1:k6])
        conquer_town_points.append(conquer[k6+1:len(conquer)-1])
        x+=1
        conquer = f.readline()
        f.close()
        self.conquers_text.SetLabel(str(len(conquer_town_ID)))

        #-------------------------------------------------------------------------------
        # The following routines are initiated by pressing the filter button
        # The string entered in the text input field is collected
        # then the names containing the string are appended to the listbox
        #-------------------------------------------------------------------------------
        #!/usr/bin/python
        # -*- coding: iso-8859-1 -*-
        def OnFilterPlayer(self, event):
        self.player_listbox.Clear()
        s = self.player_filter.GetValue()
        for x in range (0, len(player_ID)):
        if s in player_name[x]:
        self.player_listbox.Append(str(player_name[x]))

        def OnFilterAlly(self, event):
        self.ally_listbox.Clear()
        s = self.ally_filter.GetValue()
        for x in range (0, len(alliance_ID)):
        if s in alliance_name[x]:
        self.ally_listbox.Append(str(alliance_name[x]))

        def OnFilterCities(self, event):
        self.cities_listbox.Clear()
        s = self.cities_filter.GetValue()
        for x in range (0, len(town_ID)):
        if s in town_name[x]:
        self.cities_listbox.Append(str(town_name[x]))

        def OnCopyPlayers(self, event):
        alliance_name = self.ally_listbox.GetStringSelection()
        alliance = get_alliance_ID(alliance_name)
        self.player_listbox.Clear()
        for player in range(0, len(player_ID)):
        if (str(player_alliance_ID[player]) == str(alliance)):
        self.player_listbox.Append(str(player_name[player]))

        def OnCopyCities(self, event):
        player_name = self.player_listbox.GetStringSelection()
        player = get_player_ID(player_name)
        self.cities_listbox.Clear()
        for city in range(0, len(town_ID)):
        # print str(town_player[city]), str(player)
        if (str(town_player[city]) == str(player)):
        self.cities_listbox.Append(str(town_name[city]))

        def OnCopyPlayersToClipboard(self, event):
        alliance_name = self.ally_listbox.GetStringSelection()
        alliance = get_alliance_ID(alliance_name)
        ct=''
        for player in range(0, len(player_ID)):
        if (str(player_alliance_ID[player]) == str(alliance)):
        ct=ct + '[player]'+(str(player_name[player]))+'/player\n'
        CopyToClipboard(ct)

        def OnCopyCitiesToClipboard(self, event):
        player_name = self.player_listbox.GetStringSelection()
        player = get_player_ID(player_name)
        ct=''
        for city in range(0, len(town_ID)):
        if (str(town_player[city]) == str(player)):
        ct=ct + '[town]'+(str(town_ID[city]))+'/town\n'
        CopyToClipboard(ct)

        #-------------------------------------------------------------------------------
        # The following toutines are initiated by pressing the draw button
        # The selected name is collected, then the corresponding ID is searched for
        # For one player the towns are checked and drawn if belonging to the player
        # For an alliance the players are checked and drawn if belonging to the alliance
        #-------------------------------------------------------------------------------

        def OnDrawCity(self, event):
        city_name = self.cities_listbox.GetStringSelection()
        t = town_name.index(city_name)
        color = choose_colour()
        x = int(town_island_x[t])
        y = int(town_island_y[t])
        self.draw_town(x, y, color, 'big')

        # Done drawing, now handle control to pygame
        pygame_events_on=1
        self.Handle_Pygame_Events(self)

        def OnDrawPlayer(self, event):
        player_name = self.player_listbox.GetStringSelection()
        player = get_player_ID(player_name)
        color = choose_colour()
        for town in range(0, len(town_ID)):
        if (town_player[town] == player):
        x = int(town_island_x[town])
        y = int(town_island_y[town])
        self.draw_town(x, y, color, 'big')

        # Done drawing, now handle control to pygame
        pygame_events_on=1
        self.Handle_Pygame_Events(self)

        def OnDrawAlly(self, event):
        alliance_name = self.ally_listbox.GetStringSelection()
        alliance = get_alliance_ID(alliance_name)
        color = choose_colour()
        for player in range(0, len(player_ID)):
        if (str(player_alliance_ID[player]) == str(alliance)):
        for town in range(0, len(town_ID)):
        if (town_player[town] == player_ID[player]):
        x = int(town_island_x[town])
        y = int(town_island_y[town])
        self.draw_town(x, y, color, 'big')

        # Done drawing, now handle control to pygame
        pygame_events_on=1
        self.Handle_Pygame_Events(self)

        def OnShowConquers(self, event):

        date_start = get_date(self.start_date.GetValue())
        date_end = get_date(self.end_date.GetValue())

        mark = pygame.image.load("mark2.tga").convert_alpha()
        print 'start date' + str(date_start)
        print 'end date' + str(date_end)
        for i in range(0, len(conquer_town_ID)):
        d=datetime.fromtimestamp(float(conquer_time[i]))
        date = d.date()
        if (date > date_start and date < date_end and len(conquer_old_player_ID[i])>1):
        c = conquer_town_ID[i]
        if c in town_ID:
        t = town_ID.index(c)
        x = int(town_island_x[t])
        y = int(town_island_y[t])
        name = town_name[t]
        player = get_player_name(town_player[t])
        self.worldmap.blit(mark, (x-5, y-5))

        # Done drawing, now handle control to pygame
        pygame_events_on=1
        self.Handle_Pygame_Events(self)

        #-------------------------------------------------------------------------------
        # This routine is initiated when another world is selected in the drop-down box
        #-------------------------------------------------------------------------------

        def OnSelectWorld(self, event):
        self.aw = self.world_box.GetSelection()

        #-------------------------------------------------------------------------------
        # This routine is selected when quit is selected from the menu bar
        #-------------------------------------------------------------------------------

        def OnQuit(self, event):
        pygame.quit()
        self.Close()

        #-------------------------------------------------------------------------------
        # This routine is selected when the show map is selected from the menu bar
        # A pygame surface withis created which opens in a new window
        #-------------------------------------------------------------------------------

        def OnShowMap(self, event):

        # os.environ['SDL_VIDEO_WINDOW_POS'] = ('5,20') # this positions the map screen top left.
        self.windowSurface = pygame.display.set_mode((px, py), RESIZABLE, 32)
        pygame.display.set_caption('Carte du monde de Grepolis')
        self.windowSurface.fill(BLACK)
        self.windowSurface.blit(self.worldmap, dest=(0,0) , area=(xpos, ypos, px, py))
        pygame.display.update()
        self.Handle_Pygame_Events(self)

        def Handle_Pygame_Events(self, event):
        global pygame_events_on
        global px, py, xpos, ypos, zoom, pxz, pyz
        pygame_events_on = 1 # handle pygame events
        move_screen=0 # dont move the screen
        redraw=1 # redraw the screen on first pass
        self.statusbar.SetStatusText('Handling pygame events on')
        while pygame_events_on:
        pygame.time.wait(10) # snooze a little to spare processor time
        for action in pygame.event.get():

        if action.type == QUIT: # User want to leave pygame control
        pygame.display.quit()
        pygame_events_on=0

        if action.type== VIDEORESIZE: # window screen was resized
        px = action.w
        py = action.h
        zoom = 1
        redraw=1

        if action.type == MOUSEMOTION: # mouse movenemt detected
        if move_screen==1: # map movement required?
        mouse_x = action.rel[0]
        mouse_y = action.rel[1]
        xpos=xpos-mouse_x # calculate new position
        ypos=ypos-mouse_y
        pxz = int(px/zoom)
        pyz = int(py/zoom)
        if (xpos<0): # dont leave the map area
        xpos=0
        if (ypos<0):
        ypos=0
        if (xpos+pxz>1000):
        xpos=1000-pxz
        if (ypos+pyz>1000):
        ypos=1000-pyz

        # In order to zoom the part of the worldmap the user wants to see
        # is copied to a temporary surface, next the surface is scaled
        # and copied to the window surface

        self.tempmap=pygame.Surface((px/zoom, py/zoom))
        self.tempmap.blit(self.worldmap, dest=(0,0) , area=(xpos, ypos, int(px/zoom), int(py/zoom)))
        pygame.transform.smoothscale(self.tempmap, (px, py), self.windowSurface)
        pygame.display.update()
        redraw=0

        if action.type == MOUSEBUTTONDOWN: # left mouse button pressed
        mouse_button = action.button
        if mouse_button == 1:
        move_screen=1

        if action.type == MOUSEBUTTONUP: # finished pressing left mouse button
        move_screen=0

        if action.type == KEYDOWN:

        if (action.key == K_UP): # Calculate new zoom factor
        zoom = zoom + 0.05
        redraw=1

        if (action.key == K_DOWN):
        zoom = zoom - 0.05
        redraw=1

        # Dont redraw the window surface when not needed because
        # the display_set_mode command causes a mouse-up event
        # which messes-up the scrolling of the window.

        if(redraw==1):
        self.windowSurface = pygame.display.set_mode((px, py), RESIZABLE)
        self.tempmap=pygame.Surface((px/zoom, py/zoom))
        self.tempmap.blit(self.worldmap, dest=(0,0) , area=(xpos, ypos, int(px/zoom), int(py/zoom)))
        pygame.transform.smoothscale(self.tempmap, (px, py), self.windowSurface)
        pygame.display.update()
        redraw=0
        self.statusbar.SetStatusText('Handling pygame events off')
        1. #-------------------------------------------------------------------------------
          # This routine makes a 1000x1000 world map that is NOT presented to the user
          # This is the original world-size map
          # It also draws the grid and places ocean numbers on the map
          #-------------------------------------------------------------------------------

          def MakeWorldMap(self):
          f=pygame.font.init()
          self.worldmap = pygame.Surface((1000, 1000))

          for i in range(1,11):
          pygame.draw.line(self.worldmap, (125, 125, 125), (100*i, 0), (100*i, 1000), 1)
          pygame.draw.line(self.worldmap, (125, 125, 125), (0, 100*i), (1000, 100*i), 1)
          self.show_text(str((i*10)-10), 100*(i-1)+2, 2, WHITE)
          self.show_text(str(i-1), 990, 100*(i-1)+2, WHITE)

          #-------------------------------------------------------------------------------
          # The following routine displays a text on the world map
          #-------------------------------------------------------------------------------

          def show_text(self, t, x, y, color):

          basicFont = pygame.font.Font("freesansbold.ttf", 20)
          text = basicFont.render(t, True, color, BLACK)
          textRect = text.get_rect()
          textRect.top = y
          textRect.left = x
          self.worldmap.blit(text, textRect)

          #-------------------------------------------------------------------------------
          # This routine draws all cities in the towns array
          #-------------------------------------------------------------------------------

          def OnDrawCities(self, event):
          for i in range(0, len(town_ID)):
          x = int(town_island_x[i])
          y = int(town_island_y[i])
          self.draw_town(x, y, GREY, 'small')

          # Done drawing, now handle control to pygame

          pygame_events_on=1
          self.Handle_Pygame_Events(self)

          #-------------------------------------------------------------------------------
          # The following routine draws one single town on the map
          # The town is made of 4 (small) or 8 (big) pixels
          #-------------------------------------------------------------------------------

          def draw_town(self, x, y, c, size):

          self.worldmap.set_at((x, y), c)
          self.worldmap.set_at((x+1, y), c)
          self.worldmap.set_at((x-1, y), c)
          self.worldmap.set_at((x, y+1), c)
          self.worldmap.set_at((x, y-1), c)

          if (size == 'big'):
          self.worldmap.set_at((x+1, y+1), c)
          self.worldmap.set_at((x+1, y-1), c)
          self.worldmap.set_at((x-1, y+1), c)
          self.worldmap.set_at((x-1, y-1), c)

          #-------------------------------------------------------------------------------
          # This routine saves the map as presented on the windowsurface
          #-------------------------------------------------------------------------------

          def OnSaveMap(self, event):
          dialog = wx.FileDialog(None, "Entrer le nom d'un fichier", style=wx.FD_SAVE)
          if dialog.ShowModal() == wx.ID_OK:
          filename = dialog.GetPath()
          dialog.Destroy()
          pygame.image.save(self.windowSurface, filename)

          #-------------------------------------------------------------------------------
          # Here the creation of the main user interface window ends
          # The following routines are not part of the user interface
          #-------------------------------------------------------------------------------

          #-------------------------------------------------------------------------------
          # This routine is used for testing purposes
          #-------------------------------------------------------------------------------

          def Ontestbutton(event):
          pass
          #print 'This is the test button allright'

          #-------------------------------------------------------------------------------
          # This routine loads the URLs of all worlds from the file grepomaps.cfg
          #-------------------------------------------------------------------------------

          def LoadConfigData():

          global aw;aw = 0
          global world; world = []
          global url_players; url_players = []
          global url_conquers; url_conquers = []
          global url_alliances; url_alliances = []
          global url_towns; url_towns = []
          global url_islands; url_islands = []

          f = open (r"grepomaps.cfg", 'r')
          line = f.readline()
          count = int(line[9:len(line)-1])

          for w in range(0,count):
          line = f.readline()
          world.append(line[8:len(line)-1])
          line = f.readline()
          url_players.append(line[14:len(line)-1])
          line = f.readline()
          url_conquers.append(line[15:len(line)-1])
          line = f.readline()
          url_alliances.append(line[16:len(line)-1])
          line = f.readline()
          url_towns.append(line[12:len(line)-1])
          line = f.readline()
          url_islands.append(line[14:len(line)-1])

          #-------------------------------------------------------------------------------
          # The following routines transfer IDs in names and vice versa
          #-------------------------------------------------------------------------------

          def get_player_ID(player):
          if player in player_name:
          return player_ID[player_name.index(player)]

          def get_player_name(player):
          if player in player_ID:
          return player_name[player_ID.index(player)]

          def get_alliance_ID(alliance):
          if alliance in alliance_name:
          return alliance_ID[alliance_name.index(alliance)]

          def get_alliance_name(alliance):
          if alliance in alliance_ID:
          return alliance_name[alliance_ID.index(alliance)]

          def get_date(datestring):
          yy=datestring.GetYear()
          mm=datestring.GetMonth()+1
          dd=datestring.GetDay()
          return date(yy, mm, dd)

          #-------------------------------------------------------------------------------
          # The following routine presents the colour chooser window and returns a colour
          #-------------------------------------------------------------------------------

          def choose_colour():
          dialog = wx.ColourDialog(None)
          dialog.GetColourData().SetChooseFull(True)
          if dialog.ShowModal() == wx.ID_OK:
          data = dialog.GetColourData()
          color = data.GetColour().Get()
          dialog.Destroy()
          return color

          def CopyToClipboard(text):
          text2=text.replace('+', ' ')
          clipdata = wx.TextDataObject()
          clipdata.SetText(text2)
          wx.TheClipboard.Open()
          wx.TheClipboard.SetData(clipdata)
          wx.TheClipboard.Close()

          #-------------------------------------------------------------------------------
          # At this point we're done with defining routines
          # The actual program (application) is initiated
          #
          # First the application that wxpython needs is defined
          # Next the menu window is generated and presented to the user
          # After that pygame is initiated
          # Then the application loop is entered waiting for user generated events
          #-------------------------------------------------------------------------------

          app = wx.App()
          Menu(None, -1, '')
          pygame.init() # initialise the pygame engine
          app.MainLoop()