IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Python Discussion :

Python é et è convertir


Sujet :

Python

  1. #21
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2011
    Messages
    148
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2011
    Messages : 148
    Points : 54
    Points
    54
    Par défaut
    j'ai vérifié pour pygame et wx, c'est en beta on va évité ^^

    Je vais modifier pour l'encodage et pour les joueurs ! J'te dis sa dans 30 min

  2. #22
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2011
    Messages
    148
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2011
    Messages : 148
    Points : 54
    Points
    54
    Par défaut
    bon, je m'occuperais après de l'encodage ... je m'attaque au player

    petit minuscle bug

    j'ai transformé la partie player :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
     fn = r'data\world_' + world[self.aw]+ '_players.txt'
            if not (os.path.isfile(fn)):
                dlg = wx.MessageDialog(None, "Aucune données disponible pour ce monde "+ world[self.aw], caption="No Data Available", style = wx.OK) 
                dlg.ShowModal()
                return
     
            f = open(fn, 'r')
            self.players_text.SetLabel("Chargement...")
            x = 0
            player = f.readline()
            while (len(player) > 0):
                k1 = player.find(',')
                k2 = player.find(',', k1+1)
                k3 = player.find(',', k2+1)
                k4 = player.find(',', k3+1)
                k5 = player.find(',', k4+1)
                player_ID.append(player[0:k1])
                player_name.append(player[k1+1:k2]) 
                player_alliance_ID.append(player[k2+1:k3]) 
                player_points.append(player[k3+1:k4]) 
                player_rank.append(player[k4+1:k5]) 
                player_cities.append(player[k5+1:len(player)-1])
                x+=1
                player = f.readline()
            f.close()
     
            for x in range(1, len(player_ID)):
                self.player_listbox.Append(str(player_name[x]))
            self.players_text.SetLabel(str(len(player_ID)))
    en sa :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    fn = r'data\world_' + world[self.aw]+ '_players.txt'
            if not (os.path.isfile(fn)):
                dlg = wx.MessageDialog(None, "Aucune données disponible pour ce monde "+ world[self.aw], caption="No Data Available", style = wx.OK) 
                dlg.ShowModal()
                return
     
            with open(fn, 'r') as f:
                self.players_text.SetLabel("Chargement...")
                for player in f:
                   el = player.split(',')
                   player_ID.append(unquote_plus(el[0]))
                   player_name.append(unquote_plus(el[1]))
                   player_alliance_ID.append(unquote_plus(el[2])) 
                   player_points.append(unquote_plus(el[3])) 
                   player_rank.append(unquote_plus(el[4]))
                   player_cities.append(unquote_plus(el[5]))
                self.players_text.SetLabel(str(len(player_ID)))
    Il m'affiche rien lors de la compilation mais sa lors de l'utilisation du logiciel :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    N:\Users\JBG\Desktop\grepomaps\grepomaps.py:875: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
      if player in player_name:
    N:\Users\JBG\Desktop\grepomaps\grepomaps.py:876: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
      return player_ID[player_name.index(player)]


  3. #23
    Membre éclairé
    Homme Profil pro
    heu...
    Inscrit en
    Octobre 2007
    Messages
    648
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : heu...

    Informations forums :
    Inscription : Octobre 2007
    Messages : 648
    Points : 773
    Points
    773
    Par défaut
    Ahhhh, la joie des encodages et de l'unicode... un vrai casse-tête au début...

    Tiens, quand tu voudras t'y attaquer, voici trois liens bien utiles:

  4. #24
    Membre éprouvé

    Homme Profil pro
    Diverses et multiples
    Inscrit en
    Mai 2008
    Messages
    662
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Diverses et multiples

    Informations forums :
    Inscription : Mai 2008
    Messages : 662
    Points : 1 273
    Points
    1 273
    Par défaut
    Encore un problème unicode/str…

    Bon, d’abord, je crois que tu as oublié une ligne dans ton nouveau code, non*?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    fn = r'data\world_' + world[self.aw]+ '_players.txt'
            if not (os.path.isfile(fn)):
                dlg = wx.MessageDialog(None, "Aucune données disponible pour ce monde "+ world[self.aw], caption="No Data Available", style = wx.OK) 
                dlg.ShowModal()
                return
     
            with open(fn, 'r') as f:
                self.players_text.SetLabel("Chargement...")
                for player in f:
                   el = player.split(',')
                   player_ID.append(unquote_plus(el[0]))
                   player_name.append(unquote_plus(el[1]))
                   self.player_listbox.Append(player_name[-1]))
                   player_alliance_ID.append(unquote_plus(el[2])) 
                   player_points.append(unquote_plus(el[3])) 
                   player_rank.append(unquote_plus(el[4]))
                   player_cities.append(unquote_plus(el[5]))
                self.players_text.SetLabel(str(len(player_ID)))
    Ensuite, dans
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    def get_player_ID(player):
        if player in player_name:
            return player_ID[player_name.index(player)]
    …“player” est sûrement un str, alors que player_name contient des unicodes, puisque tu n’as pas voulu les ré-encoder en str

    Donc, pour qu’il y ait comparaison, python tente d’encoder “player” en unicode… avec le codec ascii, qui ne supporte aucun accents*! Donc, pas d’encodage unicode de player, donc pas de comparaison possible, donc égalité fausse, point barre…

    Oui, je sais, c’est pénible –*comme le fait très justement remarquer N.tox, c’est un casse-tête…

    Maintenant, la solution*: de deux choses l’une, ou bien tu ré-encodes tous les résultats de tes unquote_plus, comme je te l’ai dit précédemment (attention, la locale “latin9” n’est pas forcément celle qu’il te faut, surtout si tu es sous windows ), ou bien –*plus simple*– tu encode “player” avant de le comparer avec ta liste*:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    def get_player_ID(player):
        player = player.decode('latin9') # ou peut-être 'windows-1252'
        if player in player_name:
            return player_ID[player_name.index(player)]
    comme ça, tu compare de l’unicode avec de l’unicode, plus de problèmes (normalement ).

  5. #25
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2011
    Messages
    148
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2011
    Messages : 148
    Points : 54
    Points
    54
    Par défaut
    toujours aucune amélioration !

    sauf que aucune erreur maintenant avec player

    il affiche toujours à la place des é des Ãet des copyright ^^


  6. #26
    Membre éprouvé

    Homme Profil pro
    Diverses et multiples
    Inscrit en
    Mai 2008
    Messages
    662
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Diverses et multiples

    Informations forums :
    Inscription : Mai 2008
    Messages : 662
    Points : 1 273
    Points
    1 273
    Par défaut
    Ben oui, forcément…

    ’Faut remplacer

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    self.player_listbox.Append(player_name[-1]))
    par

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    self.player_listbox.Append(player_name[-1].decode('utf-8').encode('latin9')))
    Ou quelque chose comme ça…

    Mais je te conseille vraiment fortement les liens de N.tox

  7. #27
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2011
    Messages
    148
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2011
    Messages : 148
    Points : 54
    Points
    54
    Par défaut
    Il y a un avancement

    maintenant, la liste des joueurs chargés automatiquement affiche bien les é et è !

    Saut que dès que je filtre les joueurs d'une ally, sa me remet les à ... sa doit venir de la commande pour filtrer qui doit etre encoder en windows-1252

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    849
    850
    851
    852
    853
    854
    855
    856
    857
    858
    859
    860
    861
    862
    863
    864
    865
    866
    867
    868
    869
    870
    871
    872
    873
    874
    875
    876
    877
    878
    879
    880
    881
    882
    883
    884
    885
    886
    887
    888
    889
    890
    891
    892
    893
    894
    895
    896
    897
    898
    899
    900
    901
    902
    903
    904
    905
    906
    907
    908
    909
    910
    911
    912
    913
    914
    915
    916
    917
    918
    919
    920
    921
    922
    923
    924
    925
    926
    927
    928
    929
    #!/usr/bin/python
    # -*- coding: windows-1252 -*-
    import wx, os, shutil, sys, time, datetime
    import urllib2
    from urllib2 import urlopen
    import urllib
    from urllib import unquote_plus
    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
    #-------------------------------------------------------------------------------
     
    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
            #-----------------------------------------------------------------------
     
            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ête:", (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, "Créer 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)
     
     
            #-----------------------------------------------------------------------
            # Creating the listbox section
            #-----------------------------------------------------------------------
     
            # alliance listbox
     
            box3=wx.StaticBox(panel, -1, 'Alliances', pos=(5, 150), size=(150, 480))
            self.ally_listbox = wx.ListBox(panel, -1, pos=(10, 170), size=(140, 270))
            self.ally_listbox.SetBackgroundColour(WHITE)
            self.ally_filter = wx.TextCtrl(panel, -1, "", pos=(10, 460), size=(140, 20))
            self.filter_ally = wx.Button(panel, -1, "Filtrer les alliances", pos=(10, 480), size=(140, 20))
            self.filter_ally.SetBackgroundColour(WHITE)
            self.draw_ally = wx.Button(panel, -1, "Dessiner l'alliance", pos=(10, 500), size=(140, 20))
            self.draw_ally.SetBackgroundColour(WHITE)
            self.copy_players = wx.Button(panel, -1, "Afficher dans la listebox", pos=(10, 520), size=(140, 20))
            self.copy_players.SetBackgroundColour(WHITE)
            self.copy_players_to_clipboard = wx.Button(panel, -1, "Copier dans le copier/coller", pos=(10, 540), size=(140, 20))
            self.copy_players_to_clipboard.SetBackgroundColour(WHITE)
            self.copy_players_to_clipboard = wx.Button(panel, -1, "Envoyer un message", pos=(10, 560), size=(140, 20))
            self.copy_players_to_clipboard.SetBackgroundColour(WHITE)
     
            self.ally_filter.Bind(wx.EVT_SET_FOCUS, self.OnGetFocus)
            self.ally_filter.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
            self.Bind(wx.EVT_BUTTON, self.OnFilterAlly, self.filter_ally)
            self.Bind(wx.EVT_BUTTON, self.OnDrawAlly, self.draw_ally)
            self.Bind(wx.EVT_BUTTON, self.OnCopyPlayers, self.copy_players)
            self.Bind(wx.EVT_BUTTON, self.OnCopyPlayersToClipboard, self.copy_players_to_clipboard)
     
            # player listbox
     
            box3=wx.StaticBox(panel, -1, 'Joueur', pos=(165, 150), size=(150, 480))        
            self.player_listbox = wx.ListBox(panel, -1, pos=(170, 170), size=(140, 270))
            self.player_listbox.SetBackgroundColour(WHITE)
            self.player_filter = wx.TextCtrl(panel, -1, "", pos=(170, 460), size=(140, 20))
            self.filter_player = wx.Button(panel, -1, "Filtrer les joueurs", pos=(170, 480), size=(140, 20))
            self.filter_player.SetBackgroundColour(WHITE)
            self.draw_player = wx.Button(panel, -1, "Dessiner le joueur", pos=(170, 500), size=(140, 20))
            self.draw_player.SetBackgroundColour(WHITE)
            self.copy_cities = wx.Button(panel, -1, "Afficher dans la listebox", pos=(170, 520), size=(140, 20))
            self.copy_cities.SetBackgroundColour(WHITE)
            self.copy_cities_to_clipboard = wx.Button(panel, -1, "Copier dans le copier/coller", pos=(170, 540), size=(140, 20))
            self.copy_cities_to_clipboard.SetBackgroundColour(WHITE)
     
            self.player_filter.Bind(wx.EVT_SET_FOCUS, self.OnGetFocus)
            self.player_filter.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
            self.Bind(wx.EVT_COMBOBOX, self.OnSelectWorld, self.world_box)
            self.Bind(wx.EVT_BUTTON, self.OnFilterPlayer, self.filter_player)
            self.Bind(wx.EVT_BUTTON, self.OnDrawPlayer, self.draw_player)
            self.Bind(wx.EVT_BUTTON, self.OnCopyCities, self.copy_cities)
            self.Bind(wx.EVT_BUTTON, self.OnCopyCitiesToClipboard, self.copy_cities_to_clipboard)
     
     
            # cities listbox
     
            box3=wx.StaticBox(panel, -1, 'Villes', pos=(325, 150), size=(150, 480))
            self.cities_listbox = wx.ListBox(panel, -1, pos=(330, 170), size=(140, 270))
            self.cities_listbox.SetBackgroundColour(WHITE)
            self.cities_filter = wx.TextCtrl(panel, -1, "", pos=(330, 460), size=(140, 20))
            self.filter_cities = wx.Button(panel, -1, "Filtrer les alliances", pos=(330, 480), size=(140, 20))
            self.filter_cities.SetBackgroundColour(WHITE)
            self.draw_cities = wx.Button(panel, -1, "Dessiner les villes", pos=(330, 500), size=(140, 20))
            self.draw_cities.SetBackgroundColour(WHITE)
     
            self.cities_filter.Bind(wx.EVT_SET_FOCUS, self.OnGetFocus)
            self.cities_filter.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
            self.Bind(wx.EVT_BUTTON, self.OnFilterCities, self.filter_cities)
            self.Bind(wx.EVT_BUTTON, self.OnDrawCity, self.draw_cities)
     
            #self.OnLoadData(self)
     
     
            # Present the window
            self.Show(True)
            self.OnShowMap(True)
     
    #-------------------------------------------------------------------------------
    # The following routines are needed to make pygame and wxpython work together.
    # Pygame has the focus most of the time, but when the user wants to enter data
    # the focus is set to the widget that the player wants to use.
    # By setting the pygame_events_on flag to 0 the pygame event loop is terminated
    # allowing the user to enter data.
    # When the widget loses focus the control is returned to the routine that
    # handles pygame events
    #-------------------------------------------------------------------------------
     
     
     
        def OnGetFocus(self, event):
            global pygame_events_on
            pygame_events_on=0
     
        def OnKillFocus(self, event):
            global pygame_events_on
            pygame_events_on=1
            self.OnShowMap(self)
     
     
    #-------------------------------------------------------------------------------
    # The following routine downloads the world data from internet
    # The data is saved to a \data directory that is created if not exist
    # the filename tells the world and the data stored in it
    # This is done because it is not possible to make subdirectories because
    # of the escape behaviour of the "\" character.
    # the self.aw variable contains the currently selected world (0 = world alfa)
    #-------------------------------------------------------------------------------
     
     
        def OnFetchData(self, event):
     
            self.datadir = "données"
            if not (os.path.isdir(self.datadir)):        
                os.mkdir(self.datadir)
     
            self.players_text.SetLabel("Téléchargement...")
            req = urllib2.urlopen(url_players[self.aw])
            players = req.read()
            fn = r'data\world_' + world[self.aw]+ '_players.txt'
            f = open(fn, 'w')
            f.write(players)
            f.close()
            self.players_text.SetLabel("Fini")
     
            self.alliances_text.SetLabel("Téléchargement...")        
            req = urllib2.urlopen(url_alliances[self.aw])
            alliances = req.read()
            fn = r'data\world_' + world[self.aw]+ '_alliances.txt'
            f = open(fn, 'w')
            f.write(alliances)
            f.close()
            self.alliances_text.SetLabel("Fini")
     
            self.cities_text.SetLabel("Téléchargement...")
            req = urllib2.urlopen(url_towns[self.aw])
            towns = req.read()
            fn = r'data\world_' + world[self.aw]+ '_towns.txt'
            f = open(fn, 'w')
            f.write(towns)
            f.close()
            self.cities_text.SetLabel("Fini")
     
            self.islands_text.SetLabel("Téléchargement...")
            req = urllib2.urlopen(url_islands[self.aw])
            islands = req.read()
            fn = r'data\world_' + world[self.aw]+ '_islands.txt'
            f = open(fn, 'w')
            f.write(islands)
            f.close()
            self.islands_text.SetLabel("Fini")
     
            self.conquers_text.SetLabel("Téléchargement...")
            req = urllib2.urlopen(url_conquers[self.aw])
            conquers = req.read()
            fn = r'data\world_' + world[self.aw]+ '_conquers.txt'
            f = open(fn, 'w')
            f.write(conquers)
            f.close()
            self.conquers_text.SetLabel("Fini")
     
            # now load the data
            self.OnLoadData(0)
    #-------------------------------------------------------------------------------
    # The following routine loads the world data from the data files
    # These data are stored in global arrays which are defined in the routine
    # For players and alliances the data is appended to the respective listbox
    #-------------------------------------------------------------------------------
     
        def OnLoadData(self, event):
     
            #----------------
            # Load player data
            #----------------
     
            global player_ID; player_ID = []
            global player_name; player_name = []
            global player_alliance_ID; player_alliance_ID = []
            global player_points; player_points = []
            global player_rank; player_rank = []
            global player_cities; player_cities = []
     
     
            fn = r'data\world_' + world[self.aw]+ '_players.txt'
            if not (os.path.isfile(fn)):
                dlg = wx.MessageDialog(None, "Aucune données disponible pour ce monde "+ world[self.aw], caption="No Data Available", style = wx.OK) 
                dlg.ShowModal()
                return
     
            with open(fn, 'r') as f:
                self.players_text.SetLabel("Chargement...")
                for player in f:
                   el = player.split(',')
                   player_ID.append(unquote_plus(el[0]))
                   player_name.append(unquote_plus(el[1]))
                   self.player_listbox.Append(player_name[-1].decode('utf-8').encode('latin9'))
                   player_alliance_ID.append(unquote_plus(el[2])) 
                   player_points.append(unquote_plus(el[3])) 
                   player_rank.append(unquote_plus(el[4]))
                   player_cities.append(unquote_plus(el[5]))
                self.players_text.SetLabel(str(len(player_ID)))
     
            #----------------
            # Load alliance data
            #----------------
     
            global alliance_ID; alliance_ID = []
            global alliance_name; alliance_name = []
            global alliance_points; alliance_points = []
            global alliance_rank; alliance_rank = []
            global alliance_cities; alliance_cities = []
            global alliance_members; alliance_members = []
     
            fn = r'data\world_' + world[self.aw]+ '_alliances.txt'
            f = open(fn, 'r')
            x = 0
            alliance = f.readline()
            while (len(alliance) > 0):
                k1 = alliance.find(',')
                k2 = alliance.find(',', k1+1)
                k3 = alliance.find(',', k2+1)
                k4 = alliance.find(',', k3+1)
                k5 = alliance.find(',', k4+1)
                alliance_ID.append(alliance[0:k1])
                alliance_name.append(alliance[k1+1:k2]) 
                alliance_points.append(alliance[k2+1:k3]) 
                alliance_cities.append(alliance[k3+1:k4]) 
                alliance_members.append(alliance[k4+1:k5])
                alliance_rank.append(alliance[k5+1:len(alliance)-1]) 
                x+=1
                alliance = f.readline()
            f.close()
     
            for x in range(0,len(alliance_ID)):
                self.ally_listbox.Append(str(alliance_name[x]))
            self.alliances_text.SetLabel(str(len(alliance_ID)))
     
            #----------------
            # Load city data
            #----------------
     
            global town_ID; town_ID = []
            global town_player; town_player = []
            global town_name; town_name = []
            global town_island_x; town_island_x = []
            global town_island_y; town_island_y = []
            global town_island_number; town_island_number = []
            global town_points; town_points = []
     
            fn = r'data\world_' + world[self.aw]+ '_towns.txt'
            with open(fn, 'r') as f:
                self.cities_text.SetLabel("Chargement...")
                for town in f:
                    el = town.split(',')
                    town_ID.append(unquote_plus(el[0]))
                    town_player.append(unquote_plus(el[1]))
                    town_name.append(unquote_plus(el[2]))
                    town_island_x.append(unquote_plus(el[3]))
                    town_island_y.append(unquote_plus(el[4]))
                    town_island_number.append(unquote_plus(el[5]))
                    town_points.append(unquote_plus(el[6]))
            self.cities_text.SetLabel(str(len(town_ID)))
     
            #----------------
            # Load island data
            #----------------
     
            global island_ID; island_ID = []
            global island_x; island_x = []
            global island_y; island_y = []
            global island_number; island_number = []
            global island_color; island_color = []
     
            fn = r'data\world_' + world[self.aw]+ '_islands.txt'
            f = open(fn, 'r')
            self.islands_text.SetLabel("Chargement...")
            x = 0
            island = f.readline()
            while (len(island) > 0):
                k1 = island.find(',')
                k2 = island.find(',', k1+1)
                k3 = island.find(',', k2+1)
                k4 = island.find(',', k3+1)
                island_ID.append(island[0:k1])
                island_x.append(island[k1+1:k2]) 
                island_y.append(island[k2+1:k3])
                island_number.append(island[k3+1:k4])
                x+=1
                island = f.readline()
            f.close()
            self.islands_text.SetLabel(str(len(island_ID)))
     
            #----------------
            # 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
    #-------------------------------------------------------------------------------
     
        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):
        player = player
        if player in player_name:
            return player_ID[player_name.index(player)]
     
    def get_player_name(player):
        player = 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()

  8. #28
    Membre éclairé
    Homme Profil pro
    heu...
    Inscrit en
    Octobre 2007
    Messages
    648
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : heu...

    Informations forums :
    Inscription : Octobre 2007
    Messages : 648
    Points : 773
    Points
    773
    Par défaut
    hmmm... pluto que de dire manuellement que c'est du cp1252, tu peux connaitre le codage local comme suit:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    >>> import urllib
    >>> import locale
    >>> locale.getdefaultlocale()
    ('fr_FR', 'cp1252')
    >>> loc_encoding=locale.getdefaultlocale()[1]
    >>> print unicode(urllib.unquote_plus('%C3%A8 %C3%A9'),'utf-8').encode(loc_encoding)
    è é
    cause selon le système, le pays ou l'on se trouve le codage n'est pas le même... bon, les gens habitant en grèce dans leur codage locale ne verraient pas é ou è, mais probablement des signes de leur tables equivalent au '?' ou autre signifiant caractère inconnu... mais au moins, il n'y aurait pas d'erreur...

    enfin... en théorie cause, j'ai jamais testé depuis une localisation différente de la notre.

  9. #29
    Membre éprouvé

    Homme Profil pro
    Diverses et multiples
    Inscrit en
    Mai 2008
    Messages
    662
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Diverses et multiples

    Informations forums :
    Inscription : Mai 2008
    Messages : 662
    Points : 1 273
    Points
    1 273
    Par défaut
    Bon, je suppose que tu fais référence à ce morceau de code*:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
        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]))
    Il faut bien comprendre une chose*: unquote_plus renvoie une str encodée en utf-8, qui est le codage unicode sur 8 bits. Donc, player_name et toutes les autres listes contiennent des chaînes utf-8*!

    Avant de les utiliser dans ton interface, il te faut donc systématiquement les transcoder dans ta locale courante (N.tox a a priori raison –*voire [1]*!), en les décodant d’abords vers un vrai objet unicode (fonction decode('utf-8') ), puis en les ré-encodant dans la locale… euh… locale

    Donc, en supposant que tu aies récupéré cette fameuse locale au début de ton code dans la variable “loc_encoding”, comme te l’a montré N.tox, tu dois faire pour OnFilterPlayer, par exemple*:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
        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(player_name[x].decode('utf-8').encode(loc_encoding))
    [1] Ah, par contre, attention, si tu essayes d’encoder des lettres qui n’existent pas dans la locale courante (comme un é ou un è dans la locale 'greek' ou 'hebrew'), python lève une exception… Donc ça vaut peut-être mieux d’en rester à une locale occidentale, c’est toi qui voit…

  10. #30
    Membre éclairé
    Homme Profil pro
    heu...
    Inscrit en
    Octobre 2007
    Messages
    648
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : heu...

    Informations forums :
    Inscription : Octobre 2007
    Messages : 648
    Points : 773
    Points
    773
    Par défaut
    Citation Envoyé par mont29
    [1] Ah, par contre, attention, si tu essayes d’encoder des lettres qui n’existent pas dans la locale courante (comme un é ou un è dans la locale 'greek' ou 'hebrew'), python lève une exception… Donc ça vaut peut-être mieux d’en rester à une locale occidentale, c’est toi qui voit…
    Ah oui, tout à fait, je viens le constater...

    Mais je viens aussi de découvrir une petite astuce.... Bon, le but est de toujours travailler avec de l'unicode, ça ok. Mais on encode dans l'encoding locale uniquement lors des affichage, et de la manière suivante :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    print chaine_unicode.encode(loc_encoding, 'ignore')
    l'encodage omettra simplement les caractères qui lui sont inconus... c'est pas beau, mais c'est pour un affichage console, et ce n'est pas la chaine avec laquelle on travaille...

    ou bien normaliser la chaine en ascii:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    >>> import unicodedata as ud
    >>> ud.normalize('NFKD',u'bête').encode('ascii','ignore')
    'bete'

  11. #31
    Membre éprouvé

    Homme Profil pro
    Diverses et multiples
    Inscrit en
    Mai 2008
    Messages
    662
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Diverses et multiples

    Informations forums :
    Inscription : Mai 2008
    Messages : 662
    Points : 1 273
    Points
    1 273
    Par défaut
    Merci pour ces astuces, N.tox, c’est toujours bon à connaître*!

  12. #32
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2011
    Messages
    148
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2011
    Messages : 148
    Points : 54
    Points
    54
    Par défaut
    désolé pour l'attente, je n'étais pas là les jours précédents !

    Je mets en application les conseils et je vous en donne prochainement les résultats

  13. #33
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2011
    Messages
    148
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2011
    Messages : 148
    Points : 54
    Points
    54
    Par défaut
    quand je mets sa après avoir édité le chapeau,


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    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(player_name[x].decode('utf-8').encode(loc_encoding))
     
    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]))
    il me met sa :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
      def OnFilterAlly(self, event):
          ^
    SyntaxError: invalid syntax
    ERROR: Module: grepomaps could not be imported (file: N:\Users\JBG\Desktop\grepomaps\grepomaps.py).

  14. #34
    Membre éprouvé

    Homme Profil pro
    Diverses et multiples
    Inscrit en
    Mai 2008
    Messages
    662
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Diverses et multiples

    Informations forums :
    Inscription : Mai 2008
    Messages : 662
    Points : 1 273
    Points
    1 273
    Par défaut
    Ben, je ne sais pas, moi… Déjà, si t’essayais d’être plus propre dans ton indentation*? Parce qu’à part un problème d’indentation, je ne vois pas ce qui pourrait générer une erreur de syntaxe là… Et encore… Sinon, donnes plus de code. Et puis c’est quoi, cette erreur d’import, aussi*?

    Au fait, évite d’utiliser range() dans tes boucles for, il y a souvent moyen de faire autrement –*voici un exemple avec une list comprehension en prime

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    def OnFilterPlayer(self, event):
        self.player_listbox.Clear()
        s = self.player_filter.GetValue()
        for pn in (el for el in player_name if s in el):
            self.player_listbox.Append(pn.decode('utf-8').encode(loc_encoding))
     
    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]))

  15. #35
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2011
    Messages
    148
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2011
    Messages : 148
    Points : 54
    Points
    54
    Par défaut
    mdr, on va trouver

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    849
    850
    851
    852
    853
    854
    855
    856
    857
    858
    859
    860
    861
    862
    863
    864
    865
    866
    867
    868
    869
    870
    871
    872
    873
    874
    875
    876
    877
    878
    879
    880
    881
    882
    883
    884
    885
    886
    887
    888
    889
    890
    891
    892
    893
    894
    895
    896
    897
    898
    899
    900
    901
    902
    903
    904
    905
    906
    907
    908
    909
    910
    911
    912
    913
    914
    915
    916
    917
    918
    919
    920
    921
    922
    923
    924
    925
    926
    927
    928
    929
    930
    931
    932
    933
    #!/usr/bin/python
    # -*- coding: windows-1252 -*-
    import wx, os, shutil, sys, time, datetime
    import urllib2
    from urllib2 import urlopen
    import urllib
    from urllib import unquote_plus
    import locale
    locale.getdefaultlocale()
    ('fr_FR', 'cp1252')
    loc_encoding=locale.getdefaultlocale()[1]
    print unicode(urllib.unquote_plus('%C3%A8 %C3%A9'),'utf-8').encode(loc_encoding)
    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
    #-------------------------------------------------------------------------------
     
    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
            #-----------------------------------------------------------------------
     
            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ête:", (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, "Créer 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)
     
     
            #-----------------------------------------------------------------------
            # Creating the listbox section
            #-----------------------------------------------------------------------
     
            # alliance listbox
     
            box3=wx.StaticBox(panel, -1, 'Alliances', pos=(5, 150), size=(150, 480))
            self.ally_listbox = wx.ListBox(panel, -1, pos=(10, 170), size=(140, 270))
            self.ally_listbox.SetBackgroundColour(WHITE)
            self.ally_filter = wx.TextCtrl(panel, -1, "", pos=(10, 460), size=(140, 20))
            self.filter_ally = wx.Button(panel, -1, "Filtrer les alliances", pos=(10, 480), size=(140, 20))
            self.filter_ally.SetBackgroundColour(WHITE)
            self.draw_ally = wx.Button(panel, -1, "Dessiner l'alliance", pos=(10, 500), size=(140, 20))
            self.draw_ally.SetBackgroundColour(WHITE)
            self.copy_players = wx.Button(panel, -1, "Afficher dans la listebox", pos=(10, 520), size=(140, 20))
            self.copy_players.SetBackgroundColour(WHITE)
            self.copy_players_to_clipboard = wx.Button(panel, -1, "Copier dans le copier/coller", pos=(10, 540), size=(140, 20))
            self.copy_players_to_clipboard.SetBackgroundColour(WHITE)
            self.copy_players_to_clipboard = wx.Button(panel, -1, "Envoyer un message", pos=(10, 560), size=(140, 20))
            self.copy_players_to_clipboard.SetBackgroundColour(WHITE)
     
            self.ally_filter.Bind(wx.EVT_SET_FOCUS, self.OnGetFocus)
            self.ally_filter.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
            self.Bind(wx.EVT_BUTTON, self.OnFilterAlly, self.filter_ally)
            self.Bind(wx.EVT_BUTTON, self.OnDrawAlly, self.draw_ally)
            self.Bind(wx.EVT_BUTTON, self.OnCopyPlayers, self.copy_players)
            self.Bind(wx.EVT_BUTTON, self.OnCopyPlayersToClipboard, self.copy_players_to_clipboard)
     
            # player listbox
     
            box3=wx.StaticBox(panel, -1, 'Joueur', pos=(165, 150), size=(150, 480))        
            self.player_listbox = wx.ListBox(panel, -1, pos=(170, 170), size=(140, 270))
            self.player_listbox.SetBackgroundColour(WHITE)
            self.player_filter = wx.TextCtrl(panel, -1, "", pos=(170, 460), size=(140, 20))
            self.filter_player = wx.Button(panel, -1, "Filtrer les joueurs", pos=(170, 480), size=(140, 20))
            self.filter_player.SetBackgroundColour(WHITE)
            self.draw_player = wx.Button(panel, -1, "Dessiner le joueur", pos=(170, 500), size=(140, 20))
            self.draw_player.SetBackgroundColour(WHITE)
            self.copy_cities = wx.Button(panel, -1, "Afficher dans la listebox", pos=(170, 520), size=(140, 20))
            self.copy_cities.SetBackgroundColour(WHITE)
            self.copy_cities_to_clipboard = wx.Button(panel, -1, "Copier dans le copier/coller", pos=(170, 540), size=(140, 20))
            self.copy_cities_to_clipboard.SetBackgroundColour(WHITE)
     
            self.player_filter.Bind(wx.EVT_SET_FOCUS, self.OnGetFocus)
            self.player_filter.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
            self.Bind(wx.EVT_COMBOBOX, self.OnSelectWorld, self.world_box)
            self.Bind(wx.EVT_BUTTON, self.OnFilterPlayer, self.filter_player)
            self.Bind(wx.EVT_BUTTON, self.OnDrawPlayer, self.draw_player)
            self.Bind(wx.EVT_BUTTON, self.OnCopyCities, self.copy_cities)
            self.Bind(wx.EVT_BUTTON, self.OnCopyCitiesToClipboard, self.copy_cities_to_clipboard)
     
     
            # cities listbox
     
            box3=wx.StaticBox(panel, -1, 'Villes', pos=(325, 150), size=(150, 480))
            self.cities_listbox = wx.ListBox(panel, -1, pos=(330, 170), size=(140, 270))
            self.cities_listbox.SetBackgroundColour(WHITE)
            self.cities_filter = wx.TextCtrl(panel, -1, "", pos=(330, 460), size=(140, 20))
            self.filter_cities = wx.Button(panel, -1, "Filtrer les alliances", pos=(330, 480), size=(140, 20))
            self.filter_cities.SetBackgroundColour(WHITE)
            self.draw_cities = wx.Button(panel, -1, "Dessiner les villes", pos=(330, 500), size=(140, 20))
            self.draw_cities.SetBackgroundColour(WHITE)
     
            self.cities_filter.Bind(wx.EVT_SET_FOCUS, self.OnGetFocus)
            self.cities_filter.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
            self.Bind(wx.EVT_BUTTON, self.OnFilterCities, self.filter_cities)
            self.Bind(wx.EVT_BUTTON, self.OnDrawCity, self.draw_cities)
     
            #self.OnLoadData(self)
     
     
            # Present the window
            self.Show(True)
            self.OnShowMap(True)
     
    #-------------------------------------------------------------------------------
    # The following routines are needed to make pygame and wxpython work together.
    # Pygame has the focus most of the time, but when the user wants to enter data
    # the focus is set to the widget that the player wants to use.
    # By setting the pygame_events_on flag to 0 the pygame event loop is terminated
    # allowing the user to enter data.
    # When the widget loses focus the control is returned to the routine that
    # handles pygame events
    #-------------------------------------------------------------------------------
     
     
     
        def OnGetFocus(self, event):
            global pygame_events_on
            pygame_events_on=0
     
        def OnKillFocus(self, event):
            global pygame_events_on
            pygame_events_on=1
            self.OnShowMap(self)
     
     
    #-------------------------------------------------------------------------------
    # The following routine downloads the world data from internet
    # The data is saved to a \data directory that is created if not exist
    # the filename tells the world and the data stored in it
    # This is done because it is not possible to make subdirectories because
    # of the escape behaviour of the "\" character.
    # the self.aw variable contains the currently selected world (0 = world alfa)
    #-------------------------------------------------------------------------------
     
     
        def OnFetchData(self, event):
     
            self.datadir = "données"
            if not (os.path.isdir(self.datadir)):        
                os.mkdir(self.datadir)
     
            self.players_text.SetLabel("Téléchargement...")
            req = urllib2.urlopen(url_players[self.aw])
            players = req.read()
            fn = r'data\world_' + world[self.aw]+ '_players.txt'
            f = open(fn, 'w')
            f.write(players)
            f.close()
            self.players_text.SetLabel("Fini")
     
            self.alliances_text.SetLabel("Téléchargement...")        
            req = urllib2.urlopen(url_alliances[self.aw])
            alliances = req.read()
            fn = r'data\world_' + world[self.aw]+ '_alliances.txt'
            f = open(fn, 'w')
            f.write(alliances)
            f.close()
            self.alliances_text.SetLabel("Fini")
     
            self.cities_text.SetLabel("Téléchargement...")
            req = urllib2.urlopen(url_towns[self.aw])
            towns = req.read()
            fn = r'data\world_' + world[self.aw]+ '_towns.txt'
            f = open(fn, 'w')
            f.write(towns)
            f.close()
            self.cities_text.SetLabel("Fini")
     
            self.islands_text.SetLabel("Téléchargement...")
            req = urllib2.urlopen(url_islands[self.aw])
            islands = req.read()
            fn = r'data\world_' + world[self.aw]+ '_islands.txt'
            f = open(fn, 'w')
            f.write(islands)
            f.close()
            self.islands_text.SetLabel("Fini")
     
            self.conquers_text.SetLabel("Téléchargement...")
            req = urllib2.urlopen(url_conquers[self.aw])
            conquers = req.read()
            fn = r'data\world_' + world[self.aw]+ '_conquers.txt'
            f = open(fn, 'w')
            f.write(conquers)
            f.close()
            self.conquers_text.SetLabel("Fini")
     
            # now load the data
            self.OnLoadData(0)
    #-------------------------------------------------------------------------------
    # The following routine loads the world data from the data files
    # These data are stored in global arrays which are defined in the routine
    # For players and alliances the data is appended to the respective listbox
    #-------------------------------------------------------------------------------
     
        def OnLoadData(self, event):
     
            #----------------
            # Load player data
            #----------------
     
            global player_ID; player_ID = []
            global player_name; player_name = []
            global player_alliance_ID; player_alliance_ID = []
            global player_points; player_points = []
            global player_rank; player_rank = []
            global player_cities; player_cities = []
     
     
            fn = r'data\world_' + world[self.aw]+ '_players.txt'
            if not (os.path.isfile(fn)):
                dlg = wx.MessageDialog(None, "Aucune données disponible pour ce monde "+ world[self.aw], caption="No Data Available", style = wx.OK) 
                dlg.ShowModal()
                return
     
            with open(fn, 'r') as f:
                self.players_text.SetLabel("Chargement...")
                for player in f:
                   el = player.split(',')
                   player_ID.append(unquote_plus(el[0]))
                   player_name.append(unquote_plus(el[1]))
                   self.player_listbox.Append(player_name[-1].decode('utf-8').encode('latin9'))
                   player_alliance_ID.append(unquote_plus(el[2])) 
                   player_points.append(unquote_plus(el[3])) 
                   player_rank.append(unquote_plus(el[4]))
                   player_cities.append(unquote_plus(el[5]))
                self.players_text.SetLabel(str(len(player_ID)))
     
            #----------------
            # Load alliance data
            #----------------
     
            global alliance_ID; alliance_ID = []
            global alliance_name; alliance_name = []
            global alliance_points; alliance_points = []
            global alliance_rank; alliance_rank = []
            global alliance_cities; alliance_cities = []
            global alliance_members; alliance_members = []
     
            fn = r'data\world_' + world[self.aw]+ '_alliances.txt'
            f = open(fn, 'r')
            x = 0
            alliance = f.readline()
            while (len(alliance) > 0):
                k1 = alliance.find(',')
                k2 = alliance.find(',', k1+1)
                k3 = alliance.find(',', k2+1)
                k4 = alliance.find(',', k3+1)
                k5 = alliance.find(',', k4+1)
                alliance_ID.append(alliance[0:k1])
                alliance_name.append(alliance[k1+1:k2]) 
                alliance_points.append(alliance[k2+1:k3]) 
                alliance_cities.append(alliance[k3+1:k4]) 
                alliance_members.append(alliance[k4+1:k5])
                alliance_rank.append(alliance[k5+1:len(alliance)-1]) 
                x+=1
                alliance = f.readline()
            f.close()
     
            for x in range(0,len(alliance_ID)):
                self.ally_listbox.Append(str(alliance_name[x]))
            self.alliances_text.SetLabel(str(len(alliance_ID)))
     
            #----------------
            # Load city data
            #----------------
     
            global town_ID; town_ID = []
            global town_player; town_player = []
            global town_name; town_name = []
            global town_island_x; town_island_x = []
            global town_island_y; town_island_y = []
            global town_island_number; town_island_number = []
            global town_points; town_points = []
     
            fn = r'data\world_' + world[self.aw]+ '_towns.txt'
            with open(fn, 'r') as f:
                self.cities_text.SetLabel("Chargement...")
                for town in f:
                    el = town.split(',')
                    town_ID.append(unquote_plus(el[0]))
                    town_player.append(unquote_plus(el[1]))
                    town_name.append(unquote_plus(el[2]))
                    town_island_x.append(unquote_plus(el[3]))
                    town_island_y.append(unquote_plus(el[4]))
                    town_island_number.append(unquote_plus(el[5]))
                    town_points.append(unquote_plus(el[6]))
            self.cities_text.SetLabel(str(len(town_ID)))
     
            #----------------
            # Load island data
            #----------------
     
            global island_ID; island_ID = []
            global island_x; island_x = []
            global island_y; island_y = []
            global island_number; island_number = []
            global island_color; island_color = []
     
            fn = r'data\world_' + world[self.aw]+ '_islands.txt'
            f = open(fn, 'r')
            self.islands_text.SetLabel("Chargement...")
            x = 0
            island = f.readline()
            while (len(island) > 0):
                k1 = island.find(',')
                k2 = island.find(',', k1+1)
                k3 = island.find(',', k2+1)
                k4 = island.find(',', k3+1)
                island_ID.append(island[0:k1])
                island_x.append(island[k1+1:k2]) 
                island_y.append(island[k2+1:k3])
                island_number.append(island[k3+1:k4])
                x+=1
                island = f.readline()
            f.close()
            self.islands_text.SetLabel(str(len(island_ID)))
     
            #----------------
            # 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
    #-------------------------------------------------------------------------------
     
        def OnFilterPlayer(self, event):
            self.player_listbox.Clear()
            s = self.player_filter.GetValue()
            for pn in (el for el in player_name if s in el):
               self.player_listbox.Append(pn.decode('utf-8').encode(loc_encoding))
     
        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):
        player = player
        if player in player_name:
            return player_ID[player_name.index(player)]
     
    def get_player_name(player):
        player = 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()

    j'ai du faire une erreur ... il affiche bien les é et è sauf quand on filtre ... (je ne parle pas pour les alliances, je ne l'ai pas encore modifier)

    il ne m'affiche plus d'erreur pour def ... l'erreur d'importation et "normale" mais ne gène pas ... (pour le module carte) ...

  16. #36
    Membre éprouvé

    Homme Profil pro
    Diverses et multiples
    Inscrit en
    Mai 2008
    Messages
    662
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Diverses et multiples

    Informations forums :
    Inscription : Mai 2008
    Messages : 662
    Points : 1 273
    Points
    1 273
    Par défaut
    Pour l’erreur de syntaxe, ça devait donc bien être l’indentation…

    Pour le problème de filtre, c’est encore un problème d’encodage… Comme tu récupères probablement ton filtre en str encodé localement, il faut que tes noms soient déjà encodés avant de les filtrer (c’est pas idéal question perf, mais c’est pas non plus la mer à boire…)*:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    def OnFilterPlayer(self, event):
        self.player_listbox.Clear()
        s = self.player_filter.GetValue()
        for pn in player_name:
            pn = pn.decode('utf-8').encode(loc_encoding)
            if s in pn:
                self.player_listbox.Append(pn)
    …Devrait marcher.

    PS*: T’as pas vraiment besoin de tes lignes 9, 10 et 12, si*?

  17. #37
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2011
    Messages
    148
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2011
    Messages : 148
    Points : 54
    Points
    54
    Par défaut
    joie de l'encodage

    toujours le meme problème ^^

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    849
    850
    851
    852
    853
    854
    855
    856
    857
    858
    859
    860
    861
    862
    863
    864
    865
    866
    867
    868
    869
    870
    871
    872
    873
    874
    875
    876
    877
    878
    879
    880
    881
    882
    883
    884
    885
    886
    887
    888
    889
    890
    891
    892
    893
    894
    895
    896
    897
    898
    899
    900
    901
    902
    903
    904
    905
    906
    907
    908
    909
    910
    911
    912
    913
    914
    915
    916
    917
    918
    919
    920
    921
    922
    923
    924
    925
    926
    927
    928
    929
    930
    931
    932
    #!/usr/bin/python
    # -*- coding: windows-1252 -*-
    import wx, os, shutil, sys, time, datetime
    import urllib2
    from urllib2 import urlopen
    import urllib
    from urllib import unquote_plus
    import locale
    loc_encoding=locale.getdefaultlocale()[1]
    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
    #-------------------------------------------------------------------------------
     
    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
            #-----------------------------------------------------------------------
     
            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ête:", (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, "Créer 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)
     
     
            #-----------------------------------------------------------------------
            # Creating the listbox section
            #-----------------------------------------------------------------------
     
            # alliance listbox
     
            box3=wx.StaticBox(panel, -1, 'Alliances', pos=(5, 150), size=(150, 480))
            self.ally_listbox = wx.ListBox(panel, -1, pos=(10, 170), size=(140, 270))
            self.ally_listbox.SetBackgroundColour(WHITE)
            self.ally_filter = wx.TextCtrl(panel, -1, "", pos=(10, 460), size=(140, 20))
            self.filter_ally = wx.Button(panel, -1, "Filtrer les alliances", pos=(10, 480), size=(140, 20))
            self.filter_ally.SetBackgroundColour(WHITE)
            self.draw_ally = wx.Button(panel, -1, "Dessiner l'alliance", pos=(10, 500), size=(140, 20))
            self.draw_ally.SetBackgroundColour(WHITE)
            self.copy_players = wx.Button(panel, -1, "Afficher dans la listebox", pos=(10, 520), size=(140, 20))
            self.copy_players.SetBackgroundColour(WHITE)
            self.copy_players_to_clipboard = wx.Button(panel, -1, "Copier dans le copier/coller", pos=(10, 540), size=(140, 20))
            self.copy_players_to_clipboard.SetBackgroundColour(WHITE)
            self.copy_players_to_clipboard = wx.Button(panel, -1, "Envoyer un message", pos=(10, 560), size=(140, 20))
            self.copy_players_to_clipboard.SetBackgroundColour(WHITE)
     
            self.ally_filter.Bind(wx.EVT_SET_FOCUS, self.OnGetFocus)
            self.ally_filter.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
            self.Bind(wx.EVT_BUTTON, self.OnFilterAlly, self.filter_ally)
            self.Bind(wx.EVT_BUTTON, self.OnDrawAlly, self.draw_ally)
            self.Bind(wx.EVT_BUTTON, self.OnCopyPlayers, self.copy_players)
            self.Bind(wx.EVT_BUTTON, self.OnCopyPlayersToClipboard, self.copy_players_to_clipboard)
     
            # player listbox
     
            box3=wx.StaticBox(panel, -1, 'Joueur', pos=(165, 150), size=(150, 480))        
            self.player_listbox = wx.ListBox(panel, -1, pos=(170, 170), size=(140, 270))
            self.player_listbox.SetBackgroundColour(WHITE)
            self.player_filter = wx.TextCtrl(panel, -1, "", pos=(170, 460), size=(140, 20))
            self.filter_player = wx.Button(panel, -1, "Filtrer les joueurs", pos=(170, 480), size=(140, 20))
            self.filter_player.SetBackgroundColour(WHITE)
            self.draw_player = wx.Button(panel, -1, "Dessiner le joueur", pos=(170, 500), size=(140, 20))
            self.draw_player.SetBackgroundColour(WHITE)
            self.copy_cities = wx.Button(panel, -1, "Afficher dans la listebox", pos=(170, 520), size=(140, 20))
            self.copy_cities.SetBackgroundColour(WHITE)
            self.copy_cities_to_clipboard = wx.Button(panel, -1, "Copier dans le copier/coller", pos=(170, 540), size=(140, 20))
            self.copy_cities_to_clipboard.SetBackgroundColour(WHITE)
     
            self.player_filter.Bind(wx.EVT_SET_FOCUS, self.OnGetFocus)
            self.player_filter.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
            self.Bind(wx.EVT_COMBOBOX, self.OnSelectWorld, self.world_box)
            self.Bind(wx.EVT_BUTTON, self.OnFilterPlayer, self.filter_player)
            self.Bind(wx.EVT_BUTTON, self.OnDrawPlayer, self.draw_player)
            self.Bind(wx.EVT_BUTTON, self.OnCopyCities, self.copy_cities)
            self.Bind(wx.EVT_BUTTON, self.OnCopyCitiesToClipboard, self.copy_cities_to_clipboard)
     
     
            # cities listbox
     
            box3=wx.StaticBox(panel, -1, 'Villes', pos=(325, 150), size=(150, 480))
            self.cities_listbox = wx.ListBox(panel, -1, pos=(330, 170), size=(140, 270))
            self.cities_listbox.SetBackgroundColour(WHITE)
            self.cities_filter = wx.TextCtrl(panel, -1, "", pos=(330, 460), size=(140, 20))
            self.filter_cities = wx.Button(panel, -1, "Filtrer les alliances", pos=(330, 480), size=(140, 20))
            self.filter_cities.SetBackgroundColour(WHITE)
            self.draw_cities = wx.Button(panel, -1, "Dessiner les villes", pos=(330, 500), size=(140, 20))
            self.draw_cities.SetBackgroundColour(WHITE)
     
            self.cities_filter.Bind(wx.EVT_SET_FOCUS, self.OnGetFocus)
            self.cities_filter.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
            self.Bind(wx.EVT_BUTTON, self.OnFilterCities, self.filter_cities)
            self.Bind(wx.EVT_BUTTON, self.OnDrawCity, self.draw_cities)
     
            #self.OnLoadData(self)
     
     
            # Present the window
            self.Show(True)
            self.OnShowMap(True)
     
    #-------------------------------------------------------------------------------
    # The following routines are needed to make pygame and wxpython work together.
    # Pygame has the focus most of the time, but when the user wants to enter data
    # the focus is set to the widget that the player wants to use.
    # By setting the pygame_events_on flag to 0 the pygame event loop is terminated
    # allowing the user to enter data.
    # When the widget loses focus the control is returned to the routine that
    # handles pygame events
    #-------------------------------------------------------------------------------
     
     
     
        def OnGetFocus(self, event):
            global pygame_events_on
            pygame_events_on=0
     
        def OnKillFocus(self, event):
            global pygame_events_on
            pygame_events_on=1
            self.OnShowMap(self)
     
     
    #-------------------------------------------------------------------------------
    # The following routine downloads the world data from internet
    # The data is saved to a \data directory that is created if not exist
    # the filename tells the world and the data stored in it
    # This is done because it is not possible to make subdirectories because
    # of the escape behaviour of the "\" character.
    # the self.aw variable contains the currently selected world (0 = world alfa)
    #-------------------------------------------------------------------------------
     
     
        def OnFetchData(self, event):
     
            self.datadir = "données"
            if not (os.path.isdir(self.datadir)):        
                os.mkdir(self.datadir)
     
            self.players_text.SetLabel("Téléchargement...")
            req = urllib2.urlopen(url_players[self.aw])
            players = req.read()
            fn = r'data\world_' + world[self.aw]+ '_players.txt'
            f = open(fn, 'w')
            f.write(players)
            f.close()
            self.players_text.SetLabel("Fini")
     
            self.alliances_text.SetLabel("Téléchargement...")        
            req = urllib2.urlopen(url_alliances[self.aw])
            alliances = req.read()
            fn = r'data\world_' + world[self.aw]+ '_alliances.txt'
            f = open(fn, 'w')
            f.write(alliances)
            f.close()
            self.alliances_text.SetLabel("Fini")
     
            self.cities_text.SetLabel("Téléchargement...")
            req = urllib2.urlopen(url_towns[self.aw])
            towns = req.read()
            fn = r'data\world_' + world[self.aw]+ '_towns.txt'
            f = open(fn, 'w')
            f.write(towns)
            f.close()
            self.cities_text.SetLabel("Fini")
     
            self.islands_text.SetLabel("Téléchargement...")
            req = urllib2.urlopen(url_islands[self.aw])
            islands = req.read()
            fn = r'data\world_' + world[self.aw]+ '_islands.txt'
            f = open(fn, 'w')
            f.write(islands)
            f.close()
            self.islands_text.SetLabel("Fini")
     
            self.conquers_text.SetLabel("Téléchargement...")
            req = urllib2.urlopen(url_conquers[self.aw])
            conquers = req.read()
            fn = r'data\world_' + world[self.aw]+ '_conquers.txt'
            f = open(fn, 'w')
            f.write(conquers)
            f.close()
            self.conquers_text.SetLabel("Fini")
     
            # now load the data
            self.OnLoadData(0)
    #-------------------------------------------------------------------------------
    # The following routine loads the world data from the data files
    # These data are stored in global arrays which are defined in the routine
    # For players and alliances the data is appended to the respective listbox
    #-------------------------------------------------------------------------------
     
        def OnLoadData(self, event):
     
            #----------------
            # Load player data
            #----------------
     
            global player_ID; player_ID = []
            global player_name; player_name = []
            global player_alliance_ID; player_alliance_ID = []
            global player_points; player_points = []
            global player_rank; player_rank = []
            global player_cities; player_cities = []
     
     
            fn = r'data\world_' + world[self.aw]+ '_players.txt'
            if not (os.path.isfile(fn)):
                dlg = wx.MessageDialog(None, "Aucune données disponible pour ce monde "+ world[self.aw], caption="No Data Available", style = wx.OK) 
                dlg.ShowModal()
                return
     
            with open(fn, 'r') as f:
                self.players_text.SetLabel("Chargement...")
                for player in f:
                   el = player.split(',')
                   player_ID.append(unquote_plus(el[0]))
                   player_name.append(unquote_plus(el[1]))
                   self.player_listbox.Append(player_name[-1].decode('utf-8').encode('latin9'))
                   player_alliance_ID.append(unquote_plus(el[2])) 
                   player_points.append(unquote_plus(el[3])) 
                   player_rank.append(unquote_plus(el[4]))
                   player_cities.append(unquote_plus(el[5]))
                self.players_text.SetLabel(str(len(player_ID)))
     
            #----------------
            # Load alliance data
            #----------------
     
            global alliance_ID; alliance_ID = []
            global alliance_name; alliance_name = []
            global alliance_points; alliance_points = []
            global alliance_rank; alliance_rank = []
            global alliance_cities; alliance_cities = []
            global alliance_members; alliance_members = []
     
            fn = r'data\world_' + world[self.aw]+ '_alliances.txt'
            f = open(fn, 'r')
            x = 0
            alliance = f.readline()
            while (len(alliance) > 0):
                k1 = alliance.find(',')
                k2 = alliance.find(',', k1+1)
                k3 = alliance.find(',', k2+1)
                k4 = alliance.find(',', k3+1)
                k5 = alliance.find(',', k4+1)
                alliance_ID.append(alliance[0:k1])
                alliance_name.append(alliance[k1+1:k2]) 
                alliance_points.append(alliance[k2+1:k3]) 
                alliance_cities.append(alliance[k3+1:k4]) 
                alliance_members.append(alliance[k4+1:k5])
                alliance_rank.append(alliance[k5+1:len(alliance)-1]) 
                x+=1
                alliance = f.readline()
            f.close()
     
            for x in range(0,len(alliance_ID)):
                self.ally_listbox.Append(str(alliance_name[x]))
            self.alliances_text.SetLabel(str(len(alliance_ID)))
     
            #----------------
            # Load city data
            #----------------
     
            global town_ID; town_ID = []
            global town_player; town_player = []
            global town_name; town_name = []
            global town_island_x; town_island_x = []
            global town_island_y; town_island_y = []
            global town_island_number; town_island_number = []
            global town_points; town_points = []
     
            fn = r'data\world_' + world[self.aw]+ '_towns.txt'
            with open(fn, 'r') as f:
                self.cities_text.SetLabel("Chargement...")
                for town in f:
                    el = town.split(',')
                    town_ID.append(unquote_plus(el[0]))
                    town_player.append(unquote_plus(el[1]))
                    town_name.append(unquote_plus(el[2]))
                    town_island_x.append(unquote_plus(el[3]))
                    town_island_y.append(unquote_plus(el[4]))
                    town_island_number.append(unquote_plus(el[5]))
                    town_points.append(unquote_plus(el[6]))
            self.cities_text.SetLabel(str(len(town_ID)))
     
            #----------------
            # Load island data
            #----------------
     
            global island_ID; island_ID = []
            global island_x; island_x = []
            global island_y; island_y = []
            global island_number; island_number = []
            global island_color; island_color = []
     
            fn = r'data\world_' + world[self.aw]+ '_islands.txt'
            f = open(fn, 'r')
            self.islands_text.SetLabel("Chargement...")
            x = 0
            island = f.readline()
            while (len(island) > 0):
                k1 = island.find(',')
                k2 = island.find(',', k1+1)
                k3 = island.find(',', k2+1)
                k4 = island.find(',', k3+1)
                island_ID.append(island[0:k1])
                island_x.append(island[k1+1:k2]) 
                island_y.append(island[k2+1:k3])
                island_number.append(island[k3+1:k4])
                x+=1
                island = f.readline()
            f.close()
            self.islands_text.SetLabel(str(len(island_ID)))
     
            #----------------
            # 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
    #-------------------------------------------------------------------------------
     
        def OnFilterPlayer(self, event):
            self.player_listbox.Clear()
            s = self.player_filter.GetValue()
            for pn in player_name:
                pn = pn.decode('utf-8').encode(loc_encoding)
                if s in pn:
                   self.player_listbox.Append(pn)
     
        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):
        player = player
        if player in player_name:
            return player_ID[player_name.index(player)]
     
    def get_player_name(player):
        player = 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()

  18. #38
    Membre éprouvé

    Homme Profil pro
    Diverses et multiples
    Inscrit en
    Mai 2008
    Messages
    662
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Diverses et multiples

    Informations forums :
    Inscription : Mai 2008
    Messages : 662
    Points : 1 273
    Points
    1 273
    Par défaut
    self.player_filter.GetValue() renvoie quoi, un str ou un unicode*?

    (pour le saoir, un simple print(type(s)) devrait suffire).

  19. #39
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2011
    Messages
    148
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2011
    Messages : 148
    Points : 54
    Points
    54
    Par défaut
    toujours pareil ... il y a un problème de "conversion" lors du filtrage ... alors que sans ceci, les é apparaissent ...

Discussions similaires

  1. Convertir script Python en C
    Par zelegolas2 dans le forum Débuter
    Réponses: 1
    Dernier message: 01/05/2011, 13h19
  2. convertir ces instructions de java vers python
    Par Kikouyou1080 dans le forum Général Python
    Réponses: 4
    Dernier message: 02/06/2010, 14h23
  3. convertir des donnees dans un fichier excel avec Python
    Par uppersheik dans le forum Bibliothèques tierces
    Réponses: 1
    Dernier message: 19/02/2010, 06h40
  4. Réponses: 0
    Dernier message: 12/11/2009, 12h33
  5. python C API: convertir une struct C en Class python
    Par dmichel dans le forum Interfaçage autre langage
    Réponses: 11
    Dernier message: 25/06/2008, 16h30

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo