| 12
 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
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 
 | #!/usr/bin/python
# -*- coding: iso-8859-1 -*-
import wx, os, shutil, sys, time, datetime
import urllib2
from  urllib2 import urlopen
import pygame
from pygame.locals import *
from pygame.font import *
from datetime import datetime, date
 
# The following line is a solution to the problem
# "pygame.error: No available video device"
# but might cause problems for other users
os.environ['SDL_VIDEODRIVER'] = 'windib'
 
 
global pics_hor; pics_hor = 500
global pics_ver; pics_ver = 500
global BLACK; BLACK = (0, 0, 0)
global WHITE; WHITE = (255, 255, 255)
global RED; RED = (255, 0, 0)
global GREEN; GREEN = (0, 255, 0)
global BLUE; BLUE = (0, 0, 255)
global GREY; GREY = (100, 100, 100)
global G_BROWN_1; G_BROWN_1 = (193, 153, 57)
global G_BROWN_2; G_BROWN_2 = (255, 224, 155)
 
global pygame_events_on
global px, py, xpos, ypos, zoom, pxz, pyz
px=500 # map x-size in pixels
py=500 # map y-size in pixels
xpos=0 # x-offset for drawing the map
ypos=0 # y-offset for drawing the map
zoom=1
pxz = px/zoom
pyz = py/zoom
 
 
#-------------------------------------------------------------------------------
# Here the main user interface window is created
#-------------------------------------------------------------------------------
#!/usr/bin/python
# -*- coding: utf-8 -*- 
class Menu(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title='Grepolis Toolkit', pos = (0,0), size=(1020, 720))
 
        #-----------------------------------------------------------------------
        # Creating the menu
        #-----------------------------------------------------------------------
 
        # load the URLs from the config file
        LoadConfigData()
        self.MakeWorldMap()
 
        # Create the panel to put the widgets on
        panel = wx.Panel(self)
        panel.SetBackgroundColour(WHITE)
 
        # Create a menu bar with a file menu and a map menu
        menubar = wx.MenuBar()
        file = wx.Menu()
        map = wx.Menu()
 
        # Define the choices for the file menu
        Fetch_data = wx.MenuItem(file, 1, '&Télécharger les données de ce monde\tCtrl+F')
        file.AppendItem(Fetch_data)
        Load_data = wx.MenuItem(file, 2, '&Charger les données existantes de ce monde\tCtrl+L')
        file.AppendItem(Load_data)
        quit = wx.MenuItem(file, 3, '&Quitter\tCtrl+Q')
        file.AppendItem(quit)
 
        # Define the choices for the map menu
        Show_map = wx.MenuItem(map, 4, '&Montrer/recharger la carte\tCtrl+M')
        map.AppendItem(Show_map)
        Draw_cities = wx.MenuItem(map, 6, '&Dessiner les villes\tCtrl+C')
        map.AppendItem(Draw_cities)
        Draw_conquers = wx.MenuItem(map, 9, '&Montrer les conquérants\tCtrl+C')
        map.AppendItem(Draw_conquers)
        Save_Map = wx.MenuItem(map, 8, '&Sauvegarder la carte\tCtrl+S')
        map.AppendItem(Save_Map)
        testbutton = wx.MenuItem(map, 7, '&Bouton Test\tCtrl+C')
        map.AppendItem(testbutton)
 
        # Link the choices to the def routines
        self.Bind(wx.EVT_MENU, self.OnFetchData, id=1)
        self.Bind(wx.EVT_MENU, self.OnLoadData, id=2)
        self.Bind(wx.EVT_MENU, self.OnQuit, id=3)
        self.Bind(wx.EVT_MENU, self.OnShowMap, id=4)
        self.Bind(wx.EVT_MENU, self.OnDrawCities, id=6)
        self.Bind(wx.EVT_MENU, Ontestbutton, id=7)
        self.Bind(wx.EVT_MENU, self.OnSaveMap, id=8)
        self.Bind(wx.EVT_MENU, self.OnShowConquers, id=9)
 
        # Add the menus to the menu bar
        menubar.Append(file, '&Fichier')
        menubar.Append(map, '&Carte')
 
        # add the menu bar to the window
        self.SetMenuBar(menubar)
        self.statusbar = self.CreateStatusBar()
 
        #-----------------------------------------------------------------------
        # Creating player data section
        #-----------------------------------------------------------------------
        #!/usr/bin/python
# -*- coding: iso-8859-1 -*-
        box1=wx.StaticBox(panel, -1, 'Données du monde', pos=(5, 3), size=(170, 140))
 
        # Create the text labels and widgets on the interface window
        self.aw = aw
        world_label = wx.StaticText(panel, -1, 'Monde: ', (10, 20))
        self.world_box = wx.ComboBox(panel, -1, str(world[aw]), pos=(50, 17), size=(100, 10), name = 'World')
        self.world_box.SetBackgroundColour(WHITE)
        for w in range(0, len(world)):
            self.world_box.Append(world[w])
 
        players = "Pas de données"
        self.players_text = wx.StaticText(panel, -1, players, (80, 40), (90,60))
        self.players_label = wx.StaticText(panel, -1, "Joueurs:", (10, 40))
 
        alliances = "Pas de données"
        self.alliances_text = wx.StaticText(panel, -1, alliances, (80, 60), (90,20))
        self.alliances_label = wx.StaticText(panel, -1, "Alliances:", (10, 60))
 
        cities = "Pas de données"
        self.cities_text = wx.StaticText(panel, -1, cities, (80, 80), (90,20))
        self.cities_label = wx.StaticText(panel, -1, "Villes:", (10, 80))
 
        islands = "Pas de données"
        self.islands_text = wx.StaticText(panel, -1, islands, (80, 100), (90,20))
        self.islands_label = wx.StaticText(panel, -1, "Iles:", (10, 100))
 
        conquers = "Pas de données"
        self.conquers_text = wx.StaticText(panel, -1, conquers, (80, 120), (90,20))
        self.conquers_label = wx.StaticText(panel, -1, "Conquiert:", (10, 120))
 
        #-----------------------------------------------------------------------
        # Creating the conquer map section
        #-----------------------------------------------------------------------
 
        box2=wx.StaticBox(panel, -1, 'Conquiert Carte', 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, "Montrer les conquérants", 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)
#-------------------------------------------------------------------------------
 
#!/usr/bin/python
# -*- coding: iso-8859-1 -*-
    def OnFetchData(self, event):
 
        self.datadir = "données"
        if not (os.path.isdir(self.datadir)):        
            os.mkdir(self.datadir)
        #!/usr/bin/python
# -*- coding: iso-8859-1 -*-
        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
 
        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)))
 
        #----------------
        # 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'
        f = open(fn, 'r')
        self.cities_text.SetLabel("Chargement...")
        x = 0
        town = f.readline()
        while (len(town) > 0):
            k1 = town.find(',')
            k2 = town.find(',', k1+1)
            k3 = town.find(',', k2+1)
            k4 = town.find(',', k3+1)
            k5 = town.find(',', k4+1)
            k6 = town.find(',', k5+1)
            town_ID.append(town[0:k1])
            town_player.append(town[k1+1:k2])
            town_name.append(town[k2+1:k3]) 
            town_island_x.append(town[k3+1:k4]) 
            town_island_y.append(town[k4+1:k5])
            town_island_number.append(town[k5+1:k6])
            town_points.append(town[k6+1:len(town)-1]) 
            x+=1
            town = f.readline()
        f.close()
        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
#-------------------------------------------------------------------------------
#!/usr/bin/python
# -*- coding: iso-8859-1 -*-
    def OnFilterPlayer(self, event):
        self.player_listbox.Clear()
        s = self.player_filter.GetValue()
        for x in range (0, len(player_ID)):
            if s in player_name[x]:
                self.player_listbox.Append(str(player_name[x]))
 
    def OnFilterAlly(self, event):
        self.ally_listbox.Clear()
        s = self.ally_filter.GetValue()
        for x in range (0, len(alliance_ID)):
            if s in alliance_name[x]:
                self.ally_listbox.Append(str(alliance_name[x]))
 
    def OnFilterCities(self, event):
        self.cities_listbox.Clear()
        s = self.cities_filter.GetValue()
        for x in range (0, len(town_ID)):
            if s in town_name[x]:
                self.cities_listbox.Append(str(town_name[x]))
 
    def OnCopyPlayers(self, event):
        alliance_name =  self.ally_listbox.GetStringSelection()
        alliance = get_alliance_ID(alliance_name)
        self.player_listbox.Clear()
        for player in range(0, len(player_ID)):
            if (str(player_alliance_ID[player]) == str(alliance)):
                self.player_listbox.Append(str(player_name[player]))
 
    def OnCopyCities(self, event):
        player_name =  self.player_listbox.GetStringSelection()
        player = get_player_ID(player_name)
        self.cities_listbox.Clear()
        for city in range(0, len(town_ID)):
          #  print str(town_player[city]), str(player)
            if (str(town_player[city]) == str(player)):
                self.cities_listbox.Append(str(town_name[city]))
 
 
    def OnCopyPlayersToClipboard(self, event):
        alliance_name =  self.ally_listbox.GetStringSelection()
        alliance = get_alliance_ID(alliance_name)
        ct=''
        for player in range(0, len(player_ID)):
            if (str(player_alliance_ID[player]) == str(alliance)):
                ct=ct + '[player]'+(str(player_name[player]))+'[/player]\n'
        CopyToClipboard(ct)
 
 
    def OnCopyCitiesToClipboard(self, event):
        player_name =  self.player_listbox.GetStringSelection()
        player = get_player_ID(player_name)
        ct=''
        for city in range(0, len(town_ID)):
            if (str(town_player[city]) == str(player)):
                ct=ct + '[town]'+(str(town_ID[city]))+'[/town]\n'
        CopyToClipboard(ct)
 
 
#-------------------------------------------------------------------------------
# The following toutines are initiated by pressing the draw button
# The selected name is collected, then the corresponding ID is searched for
# For one player the towns are checked and drawn if belonging to the player
# For an alliance the players are checked and drawn if belonging to the alliance
#-------------------------------------------------------------------------------
 
    def OnDrawCity(self, event):
        city_name = self.cities_listbox.GetStringSelection()
        t = town_name.index(city_name)
        color = choose_colour()
        x = int(town_island_x[t])
        y = int(town_island_y[t])
        self.draw_town(x, y, color, 'big')
 
        # Done drawing, now handle control to pygame        
        pygame_events_on=1
        self.Handle_Pygame_Events(self)
 
    def OnDrawPlayer(self, event):
        player_name = self.player_listbox.GetStringSelection()
        player = get_player_ID(player_name)
        color = choose_colour()
        for town in range(0, len(town_ID)):
            if (town_player[town] == player):
                x = int(town_island_x[town])
                y = int(town_island_y[town])
                self.draw_town(x, y, color, 'big')
 
        # Done drawing, now handle control to pygame        
        pygame_events_on=1
        self.Handle_Pygame_Events(self)
 
 
    def OnDrawAlly(self, event):
        alliance_name =  self.ally_listbox.GetStringSelection()
        alliance = get_alliance_ID(alliance_name)
        color = choose_colour()
        for player in range(0, len(player_ID)):
            if (str(player_alliance_ID[player]) == str(alliance)):
                for town in range(0, len(town_ID)):
                    if (town_player[town] == player_ID[player]):
                        x = int(town_island_x[town])
                        y = int(town_island_y[town])
                        self.draw_town(x, y, color, 'big')
 
        # Done drawing, now handle control to pygame        
        pygame_events_on=1
        self.Handle_Pygame_Events(self)
 
 
    def OnShowConquers(self, event):
 
        date_start = get_date(self.start_date.GetValue())
        date_end = get_date(self.end_date.GetValue())
 
        mark = pygame.image.load("mark2.tga").convert_alpha()
        print 'start date' + str(date_start)
        print 'end date' + str(date_end)
        for i in range(0, len(conquer_town_ID)):
            d=datetime.fromtimestamp(float(conquer_time[i]))
            date = d.date()
            if (date > date_start and date < date_end and len(conquer_old_player_ID[i])>1):
                c = conquer_town_ID[i]
                if c in town_ID:
                    t = town_ID.index(c)
                    x = int(town_island_x[t])
                    y = int(town_island_y[t])
                    name = town_name[t]
                    player = get_player_name(town_player[t])
                    self.worldmap.blit(mark, (x-5, y-5))
 
        # Done drawing, now handle control to pygame        
        pygame_events_on=1
        self.Handle_Pygame_Events(self)
 
 
 
 
#-------------------------------------------------------------------------------
# This routine is initiated when another world is selected in the drop-down box
#-------------------------------------------------------------------------------
 
    def OnSelectWorld(self, event):
        self.aw = self.world_box.GetSelection()
 
#-------------------------------------------------------------------------------
# This routine is selected when quit is selected from the menu bar
#-------------------------------------------------------------------------------
 
    def OnQuit(self, event):
        pygame.quit()
        self.Close()        
 
#-------------------------------------------------------------------------------
# This routine is selected when the show map is selected from the menu bar
# A pygame surface withis created which opens in a new window
#-------------------------------------------------------------------------------
 
    def OnShowMap(self, event):
 
#    os.environ['SDL_VIDEO_WINDOW_POS'] = ('5,20') # this positions the map screen top left.
        self.windowSurface = pygame.display.set_mode((px, py), RESIZABLE, 32)
        pygame.display.set_caption('Carte du monde de Grepolis')
        self.windowSurface.fill(BLACK)
        self.windowSurface.blit(self.worldmap, dest=(0,0) , area=(xpos, ypos, px, py))
        pygame.display.update()
        self.Handle_Pygame_Events(self)
 
    def Handle_Pygame_Events(self, event):
        global pygame_events_on
        global px, py, xpos, ypos, zoom, pxz, pyz
        pygame_events_on = 1 # handle pygame events
        move_screen=0        # dont move the screen
        redraw=1             # redraw the screen on first pass
        self.statusbar.SetStatusText('Handling pygame events on')
        while pygame_events_on:
            pygame.time.wait(10) # snooze a little to spare processor time
            for action in  pygame.event.get():
 
                if action.type == QUIT:    # User want to leave pygame control
                    pygame.display.quit()
                    pygame_events_on=0
 
                if action.type== VIDEORESIZE:  # window screen was resized
                    px = action.w
                    py = action.h
                    zoom = 1
                    redraw=1
 
                if action.type == MOUSEMOTION:  # mouse movenemt detected
                    if move_screen==1:          # map movement required?
                        mouse_x = action.rel[0]
                        mouse_y = action.rel[1]
                        xpos=xpos-mouse_x       # calculate new position
                        ypos=ypos-mouse_y
                        pxz = int(px/zoom)
                        pyz = int(py/zoom)
                        if (xpos<0):            # dont leave the map area
                            xpos=0
                        if (ypos<0):
                            ypos=0
                        if (xpos+pxz>1000):
                            xpos=1000-pxz
                        if (ypos+pyz>1000):
                            ypos=1000-pyz
 
                    # In order to zoom the part of the worldmap the user wants to see
                    # is copied to a temporary surface, next the surface is scaled
                    # and copied to the window surface
 
                    self.tempmap=pygame.Surface((px/zoom, py/zoom))
                    self.tempmap.blit(self.worldmap, dest=(0,0) , area=(xpos, ypos, int(px/zoom), int(py/zoom)))
                    pygame.transform.smoothscale(self.tempmap, (px, py), self.windowSurface)
                    pygame.display.update()
                    redraw=0
 
                if action.type == MOUSEBUTTONDOWN:  # left mouse button pressed
                    mouse_button = action.button
                    if mouse_button == 1:
                        move_screen=1
 
                if action.type == MOUSEBUTTONUP:    # finished pressing left mouse button
                    move_screen=0
 
                if action.type == KEYDOWN:
 
                    if (action.key == K_UP):     # Calculate new zoom factor
                        zoom = zoom + 0.05
                        redraw=1    
 
                    if (action.key == K_DOWN):
                        zoom = zoom - 0.05
                        redraw=1
 
                # Dont redraw the window surface when not needed because
                # the display_set_mode command causes a mouse-up event
                # which messes-up the scrolling of the window.
 
                if(redraw==1):
                    self.windowSurface = pygame.display.set_mode((px, py), RESIZABLE)
                    self.tempmap=pygame.Surface((px/zoom, py/zoom))
                    self.tempmap.blit(self.worldmap, dest=(0,0) , area=(xpos, ypos, int(px/zoom), int(py/zoom)))
                    pygame.transform.smoothscale(self.tempmap, (px, py), self.windowSurface)
                    pygame.display.update()
                    redraw=0
        self.statusbar.SetStatusText('Handling pygame events off')
 
 
#-------------------------------------------------------------------------------
# This routine makes a 1000x1000 world map that is NOT presented to the user
# This is the original world-size map
# It also draws the grid and places ocean numbers on the map
#-------------------------------------------------------------------------------
 
    def MakeWorldMap(self):
        f=pygame.font.init()
        self.worldmap = pygame.Surface((1000, 1000))
 
        for i in range(1,11):
            pygame.draw.line(self.worldmap, (125, 125, 125), (100*i, 0), (100*i, 1000), 1)
            pygame.draw.line(self.worldmap, (125, 125, 125), (0, 100*i), (1000, 100*i), 1)
            self.show_text(str((i*10)-10), 100*(i-1)+2, 2, WHITE)
            self.show_text(str(i-1), 990, 100*(i-1)+2, WHITE)
 
#-------------------------------------------------------------------------------
# The following routine displays a text on the world map
#-------------------------------------------------------------------------------
 
    def show_text(self, t, x, y, color):
 
        basicFont = pygame.font.Font("freesansbold.ttf", 20)
        text = basicFont.render(t, True, color, BLACK)
        textRect = text.get_rect()
        textRect.top = y
        textRect.left = x
        self.worldmap.blit(text, textRect)
 
#-------------------------------------------------------------------------------
# This routine draws all cities in the towns array
#-------------------------------------------------------------------------------
 
    def OnDrawCities(self, event):
        for i in range(0, len(town_ID)):
            x = int(town_island_x[i])
            y = int(town_island_y[i])
            self.draw_town(x, y, GREY, 'small')
 
        # Done drawing, now handle control to pygame        
 
        pygame_events_on=1
        self.Handle_Pygame_Events(self)
 
 
#-------------------------------------------------------------------------------
# The following routine draws one single town on the map
# The town is made of 4 (small) or 8 (big) pixels
#-------------------------------------------------------------------------------
 
    def draw_town(self, x, y, c, size):                  
 
        self.worldmap.set_at((x, y), c)
        self.worldmap.set_at((x+1, y), c)
        self.worldmap.set_at((x-1, y), c)
        self.worldmap.set_at((x, y+1), c)
        self.worldmap.set_at((x, y-1), c)
 
        if (size == 'big'):
            self.worldmap.set_at((x+1, y+1), c)
            self.worldmap.set_at((x+1, y-1), c)
            self.worldmap.set_at((x-1, y+1), c)
            self.worldmap.set_at((x-1, y-1), c)
 
#-------------------------------------------------------------------------------
# This routine saves the map as presented on the windowsurface
#-------------------------------------------------------------------------------
 
    def OnSaveMap(self, event):
        dialog = wx.FileDialog(None, "Entrer le nom d'un fichier", style=wx.FD_SAVE)
        if dialog.ShowModal() == wx.ID_OK:
            filename = dialog.GetPath()
        dialog.Destroy()
        pygame.image.save(self.windowSurface, filename)
 
 
 
#-------------------------------------------------------------------------------
# Here the creation of the main user interface window ends
# The following routines are not part of the user interface
#-------------------------------------------------------------------------------
 
 
#-------------------------------------------------------------------------------
# This routine is used for testing purposes
#-------------------------------------------------------------------------------
 
def Ontestbutton(event):
    pass
    #print 'This is the test button allright'
 
 
#-------------------------------------------------------------------------------
# This routine loads the URLs of all worlds from the file grepomaps.cfg
#-------------------------------------------------------------------------------
 
def LoadConfigData():
 
    global aw;aw = 0
    global world; world = []
    global url_players; url_players = []
    global url_conquers; url_conquers = []
    global url_alliances; url_alliances = []
    global url_towns; url_towns = []
    global url_islands; url_islands = []
 
    f = open (r"grepomaps.cfg", 'r')
    line = f.readline()
    count = int(line[9:len(line)-1])
 
    for w in range(0,count):
        line = f.readline()
        world.append(line[8:len(line)-1])
        line = f.readline()
        url_players.append(line[14:len(line)-1])
        line = f.readline()
        url_conquers.append(line[15:len(line)-1])
        line = f.readline()
        url_alliances.append(line[16:len(line)-1])
        line = f.readline()
        url_towns.append(line[12:len(line)-1])
        line = f.readline()
        url_islands.append(line[14:len(line)-1])
 
 
#-------------------------------------------------------------------------------
# The following routines transfer IDs in names and vice versa
#-------------------------------------------------------------------------------
 
def get_player_ID(player):
    if player in player_name:
        return player_ID[player_name.index(player)]
 
def get_player_name(player):
    if player in player_ID:
        return player_name[player_ID.index(player)]
 
def get_alliance_ID(alliance):
    if alliance in alliance_name:
        return alliance_ID[alliance_name.index(alliance)]
 
def get_alliance_name(alliance):
    if alliance in alliance_ID:
        return alliance_name[alliance_ID.index(alliance)]
 
def get_date(datestring):
    yy=datestring.GetYear()
    mm=datestring.GetMonth()+1
    dd=datestring.GetDay()
    return date(yy, mm, dd)
 
#-------------------------------------------------------------------------------
# The following routine presents the colour chooser window and returns a colour
#-------------------------------------------------------------------------------
 
def choose_colour():
    dialog = wx.ColourDialog(None)
    dialog.GetColourData().SetChooseFull(True)
    if dialog.ShowModal() == wx.ID_OK:
        data = dialog.GetColourData()
        color = data.GetColour().Get()
    dialog.Destroy()
    return color
 
def CopyToClipboard(text):
    text2=text.replace('+', ' ')
    clipdata = wx.TextDataObject()
    clipdata.SetText(text2)
    wx.TheClipboard.Open()
    wx.TheClipboard.SetData(clipdata)
    wx.TheClipboard.Close()
 
#-------------------------------------------------------------------------------
# At this point we're done with defining routines
# The actual program (application) is initiated
# 
# First the application that wxpython needs is defined
# Next the menu window is generated and presented to the user
# After that pygame is initiated
# Then the application loop is entered waiting for user generated events
#-------------------------------------------------------------------------------
 
app = wx.App()
Menu(None, -1, '')
pygame.init()   # initialise the pygame engine
app.MainLoop() | 
Partager