This file is indexed.

/usr/share/mmass/gui/panel_documents.py is in mmass 4.0.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
# -------------------------------------------------------------------------
#     Copyright (C) 2005-2011 Martin Strohalm <www.mmass.org>

#     This program is free software; you can redistribute it and/or modify
#     it under the terms of the GNU General Public License as published by
#     the Free Software Foundation; either version 3 of the License, or
#     (at your option) any later version.

#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#     GNU General Public License for more details.

#     Complete text of GNU GPL can be found in the file LICENSE.TXT in the
#     main directory of the program
# -------------------------------------------------------------------------

# load libs
import wx

# load modules
from ids import *
import mwx
import images
import config
import mspy
import doc

from dlg_notation import dlgNotation


# DOCUMENTS PANEL
# --------------

class panelDocuments(wx.Panel):
    """Make documents panel."""
    
    def __init__(self, parent, documents):
        wx.Panel.__init__(self, parent, -1, size=(150, -1), style=wx.NO_FULL_REPAINT_ON_RESIZE)
        
        self.parent = parent
        self.documents = documents
        
        # make GUI
        self.makeGUI()
    # ----
    
    
    def makeGUI(self):
        """Make GUI elements."""
        
        # make documents tree
        self.makeDocumentTree()
        
        # init lower toolbar
        toolbar = self.makeToolbar()
        
        # pack gui elements
        self.mainSizer = wx.BoxSizer(wx.VERTICAL)
        self.mainSizer.Add(self.documentTree, 1, wx.EXPAND, 0)
        self.mainSizer.Add(toolbar, 0, wx.EXPAND)
        
        # fit layout
        self.mainSizer.Fit(self)
        self.SetSizer(self.mainSizer)
    # ----
    
    
    def makeToolbar(self):
        """Make bottom toolbar."""
        
        # init toolbar panel
        panel = mwx.bgrPanel(self, -1, images.lib['bgrBottombar'], size=(-1, mwx.BOTTOMBAR_HEIGHT))
        
        self.add_butt = wx.BitmapButton(panel, -1, images.lib['documentsAdd'], size=(mwx.BOTTOMBAR_TOOLSIZE), style=wx.BORDER_NONE)
        self.add_butt.SetToolTip(wx.ToolTip("Add..."))
        self.add_butt.Bind(wx.EVT_BUTTON, self.onAdd)
        
        self.delete_butt = wx.BitmapButton(panel, -1, images.lib['documentsDelete'], size=(mwx.BOTTOMBAR_TOOLSIZE), style=wx.BORDER_NONE)
        self.delete_butt.SetToolTip(wx.ToolTip("Remove..."))
        self.delete_butt.Bind(wx.EVT_BUTTON, self.onDelete)
        
        # pack elements
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.AddSpacer(mwx.BOTTOMBAR_LSPACE)
        sizer.Add(self.add_butt, 0, wx.ALIGN_CENTER_VERTICAL)
        sizer.Add(self.delete_butt, 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT, mwx.BUTTON_SIZE_CORRECTION)
        sizer.AddSpacer(mwx.BOTTOMBAR_RSPACE)
        
        mainSizer = wx.BoxSizer(wx.VERTICAL)
        mainSizer.Add(sizer, 1, wx.EXPAND)
        
        panel.SetSizer(mainSizer)
        mainSizer.Fit(panel)
        
        return panel
    # ----
    
    
    def makeDocumentTree(self):
        """Make documents tree."""
        
        # init tree
        self.documentTree = documentsTree(self, -1, size=(175, -1))
        
        # bind events
        self.documentTree.Bind(wx.EVT_TREE_KEY_DOWN, self.onKey)
        self.documentTree.Bind(wx.EVT_LEFT_DOWN, self.onLMD)
        self.documentTree.Bind(wx.EVT_RIGHT_DOWN, self.onRMD)
        self.documentTree.Bind(wx.EVT_RIGHT_UP, self.onRMU)
        self.documentTree.Bind(wx.EVT_TREE_SEL_CHANGING, self.onItemSelecting)
        self.documentTree.Bind(wx.EVT_TREE_SEL_CHANGED, self.onItemSelected)
        self.documentTree.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.onItemActivated)
        
        # set DnD
        dropTarget = fileDropTarget(self.parent.onDocumentDropped)
        self.documentTree.SetDropTarget(dropTarget)
    # ----
    
    
    def onKey(self, evt):
        """Delete selected item."""
        
        # get key
        key = evt.GetKeyCode()
        keyEvt = evt.GetKeyEvent()
        
        # delete
        if key==wx.WXK_DELETE or (key==wx.WXK_BACK and keyEvt.CmdDown()):
            item = self.documentTree.GetSelection()
            itemType = self.documentTree.getItemType(item)
            
            # close document
            if itemType == 'document':
                self.parent.onDocumentClose()
            
            # delete sequence
            elif itemType == 'sequence':
                self.parent.onSequenceDelete()
            
            # delete annotation or sequence match
            elif itemType in ('annotation', 'match'):
                self.onNotationDelete()
            
            else:
                wx.Bell()
            
        # other keys
        else:
            evt.Skip()
    # ----
    
    
    def onLMD(self, evt):
        """Enable / disable document."""
        
        # get item
        item, flags = self.documentTree.HitTest(evt.GetPosition())
        
        # document solo
        if (evt.AltDown() or evt.ControlDown()) and self.documentTree.getItemIndent(item) == 1:
            docIndex = self._getDocumentIndex(item)
            self.parent.onDocumentSolo(docIndex)
        
        # enable / disable document
        elif (flags & wx.TREE_HITTEST_ONITEMICON) and self.documentTree.getItemIndent(item) == 1:
            docIndex = self._getDocumentIndex(item)
            self.parent.onDocumentEnable(docIndex)
        
        # other
        else:
            evt.Skip()
    # ----
    
    
    def onRMD(self, evt):
        """Right mouse down."""
        
        if wx.Platform == '__WXMAC__':
            evt.Skip()
    # ----
    
    
    def onRMU(self, evt):
        """Show popup menu."""
        
        # get selected item
        item = self.documentTree.GetSelection()
        itemType = self.documentTree.getItemType(item)
        
        # check item
        if not itemType:
            return
        
        # get item data
        itemData = self.documentTree.GetPyData(item)
        
        # get object index
        docIndex = self._getDocumentIndex(item)
        seqIndex = self._getSequenceIndex(item)
        
        # popup menu
        menu = wx.Menu()
        if itemType == 'document':
            menu.Append(ID_sequenceNew, "Add Sequence...")
            menu.AppendSeparator()
            menu.Append(ID_documentInfo, "Notes and Information...")
            menu.Append(ID_documentColour, "Change Colour...")
            menu.Append(ID_documentNotationsDelete, "Delete All Notations")
            menu.AppendSeparator()
            menu.Append(ID_documentFlip, "Flip Spectrum")
            menu.Append(ID_documentOffset, "Offset Spectrum...")
            menu.Append(ID_documentClearOffset, "Clear Offset")
            menu.AppendSeparator()
            menu.Append(ID_documentDuplicate, "Duplicate Document")
            menu.AppendSeparator()
            menu.Append(ID_documentClose, "Close Document")
            menu.Append(ID_documentCloseAll, "Close All Documents")
            
            if config.spectrum['normalize']:
                menu.Enable(ID_documentOffset, False)
            if itemData.offset == [0,0]:
                menu.Enable(ID_documentClearOffset, False)
        
        elif itemType == 'annotations':
            menu.Append(ID_documentAnnotationsCalibrateBy, "Calibrate by Annotations...")
            menu.AppendSeparator()
            menu.Append(ID_documentAnnotationsDelete, "Delete All Annotations")
            
            if not itemData:
                menu.Enable(ID_documentAnnotationsDelete, False)
                menu.Enable(ID_documentAnnotationsCalibrateBy, False)
        
        elif itemType == 'annotation':
            menu.Append(ID_documentAnnotationEdit, "Edit Annotation...")
            menu.AppendSeparator()
            menu.Append(ID_documentAnnotationSendToMassCalculator, "Show Isotopic Pattern...")
            menu.Append(ID_documentAnnotationSendToEnvelopeFit, "Send to Envelope Fit...")
            menu.AppendSeparator()
            menu.Append(ID_documentAnnotationsCalibrateBy, "Calibrate by Annotations...")
            menu.AppendSeparator()
            menu.Append(ID_documentAnnotationDelete, "Delete Annotation")
            menu.Append(ID_documentAnnotationsDelete, "Delete All Annotations")
            
            if not itemData.formula:
                menu.Enable(ID_documentAnnotationSendToMassCalculator, False)
                menu.Enable(ID_documentAnnotationSendToEnvelopeFit, False)
        
        elif itemType == 'sequence':
            menu.Append(ID_sequenceEditor, "Edit Sequence...")
            menu.Append(ID_sequenceModifications, "Edit Modifications...")
            menu.AppendSeparator()
            menu.Append(ID_sequenceDigest, "Digest Protein...")
            menu.Append(ID_sequenceFragment, "Fragment Peptide...")
            menu.Append(ID_sequenceSearch, "Mass Search...")
            menu.AppendSeparator()
            menu.Append(ID_sequenceSendToMassCalculator, "Show Isotopic Pattern...")
            menu.Append(ID_sequenceSendToEnvelopeFit, "Send to Envelope Fit...")
            menu.AppendSeparator()
            menu.Append(ID_sequenceMatchesCalibrateBy, "Calibrate by Matches...")
            menu.AppendSeparator()
            menu.Append(ID_sequenceMatchesDelete, "Delete All Matches")
            menu.Append(ID_sequenceDelete, "Delete Sequence")
            
            if not itemData.matches:
                menu.Enable(ID_sequenceMatchesCalibrateBy, False)
                menu.Enable(ID_sequenceMatchesDelete, False)
        
        elif itemType == 'match':
            menu.Append(ID_sequenceMatchEdit, "Edit Match...")
            menu.AppendSeparator()
            menu.Append(ID_sequenceMatchSendToMassCalculator, "Show Isotopic Pattern...")
            menu.Append(ID_sequenceMatchSendToEnvelopeFit, "Send to Envelope Fit...")
            menu.AppendSeparator()
            menu.Append(ID_sequenceMatchesCalibrateBy, "Calibrate by Matches...")
            menu.AppendSeparator()
            menu.Append(ID_sequenceMatchDelete, "Delete Sequence Match")
            menu.Append(ID_sequenceMatchesDelete, "Delete All Matches")
            
            if not itemData.formula:
                menu.Enable(ID_sequenceMatchSendToMassCalculator, False)
                menu.Enable(ID_sequenceMatchSendToEnvelopeFit, False)
        
        # bind events
        self.Bind(wx.EVT_MENU, self.parent.onDocumentInfo, id=ID_documentInfo)
        self.Bind(wx.EVT_MENU, self.parent.onDocumentColour, id=ID_documentColour)
        self.Bind(wx.EVT_MENU, self.parent.onDocumentFlip, id=ID_documentFlip)
        self.Bind(wx.EVT_MENU, self.parent.onDocumentOffset, id=ID_documentOffset)
        self.Bind(wx.EVT_MENU, self.parent.onDocumentOffset, id=ID_documentClearOffset)
        self.Bind(wx.EVT_MENU, self.parent.onDocumentNotationsDelete, id=ID_documentNotationsDelete)
        self.Bind(wx.EVT_MENU, self.parent.onDocumentDuplicate, id=ID_documentDuplicate)
        self.Bind(wx.EVT_MENU, self.parent.onDocumentClose, id=ID_documentClose)
        self.Bind(wx.EVT_MENU, self.parent.onDocumentCloseAll, id=ID_documentCloseAll)
        
        self.Bind(wx.EVT_MENU, self.onNotationEdit, id=ID_documentAnnotationEdit)
        self.Bind(wx.EVT_MENU, self.onSendToMassCalculator, id=ID_documentAnnotationSendToMassCalculator)
        self.Bind(wx.EVT_MENU, self.onSendToEnvelopeFit, id=ID_documentAnnotationSendToEnvelopeFit)
        self.Bind(wx.EVT_MENU, self.parent.onDocumentAnnotationsCalibrateBy, id=ID_documentAnnotationsCalibrateBy)
        self.Bind(wx.EVT_MENU, self.onNotationDelete, id=ID_documentAnnotationDelete)
        self.Bind(wx.EVT_MENU, self.parent.onDocumentAnnotationsDelete, id=ID_documentAnnotationsDelete)
        
        self.Bind(wx.EVT_MENU, self.parent.onSequenceNew, id=ID_sequenceNew)
        self.Bind(wx.EVT_MENU, self.parent.onToolsSequence, id=ID_sequenceEditor)
        self.Bind(wx.EVT_MENU, self.parent.onToolsSequence, id=ID_sequenceModifications)
        self.Bind(wx.EVT_MENU, self.parent.onToolsSequence, id=ID_sequenceDigest)
        self.Bind(wx.EVT_MENU, self.parent.onToolsSequence, id=ID_sequenceFragment)
        self.Bind(wx.EVT_MENU, self.parent.onToolsSequence, id=ID_sequenceSearch)
        self.Bind(wx.EVT_MENU, self.onSendToMassCalculator, id=ID_sequenceSendToMassCalculator)
        self.Bind(wx.EVT_MENU, self.onSendToEnvelopeFit, id=ID_sequenceSendToEnvelopeFit)
        self.Bind(wx.EVT_MENU, self.parent.onSequenceDelete, id=ID_sequenceDelete)
        
        self.Bind(wx.EVT_MENU, self.onNotationEdit, id=ID_sequenceMatchEdit)
        self.Bind(wx.EVT_MENU, self.onSendToMassCalculator, id=ID_sequenceMatchSendToMassCalculator)
        self.Bind(wx.EVT_MENU, self.onSendToEnvelopeFit, id=ID_sequenceMatchSendToEnvelopeFit)
        self.Bind(wx.EVT_MENU, self.parent.onSequenceMatchesCalibrateBy, id=ID_sequenceMatchesCalibrateBy)
        self.Bind(wx.EVT_MENU, self.onNotationDelete, id=ID_sequenceMatchDelete)
        self.Bind(wx.EVT_MENU, self.parent.onSequenceMatchesDelete, id=ID_sequenceMatchesDelete)
        
        self.PopupMenu(menu)
        menu.Destroy()
        self.SetFocus()
    # ----
    
    
    def onItemSelecting(self, evt):
        """Selecting item."""
        
        # do not allow to select disabled documents
        item = evt.GetItem()
        if self.documentTree.getItemIndent(item):
            docIndex = self._getDocumentIndex(item)
            if not self.documents[docIndex].visible:
                wx.Bell()
                evt.Veto()
    # ----
    
    
    def onItemSelected(self, evt):
        """Selected item."""
        
        # get item
        item = evt.GetItem()
        itemType = self.documentTree.getItemType(item)
        evt.Skip()
        
        # root or bad item selected
        if not itemType:
            self.documentTree.highlightDocument(None)
            self.parent.onDocumentSelected(None)
            self.parent.updateNotationMarks()
            return
        
        # select parent document
        docIndex = self._getDocumentIndex(item)
        self.documentTree.highlightDocument(item)
        self.parent.onDocumentSelected(docIndex)
        
        # select parent sequence
        seqIndex = self._getSequenceIndex(item)
        self.parent.onSequenceSelected(seqIndex)
        
        # update notation marks
        self.parent.updateNotationMarks()
        
        # highlight mass of selected match or annotation
        if itemType in ('annotation', 'match'):
            matchData = self.documentTree.GetPyData(item)
            points = [matchData.mz]
            if matchData.theoretical != None:
                points.append(matchData.theoretical)
            self.parent.updateMassPoints(points)
    # ----
    
    
    def onItemActivated(self, evt):
        """Activated item."""
        
        # get item
        item = evt.GetItem()
        itemType = self.documentTree.getItemType(item)
        
        # do not allow to activate disabled documents
        if itemType:
            docIndex = self._getDocumentIndex(item)
            if not self.documents[docIndex].visible:
                wx.Bell()
                return
        else:
            return
        
        # document info
        if itemType == 'document':
            self.parent.onDocumentInfo()
        
        # sequence editing
        elif itemType == 'sequence':
            self.parent.onToolsSequence()
        
        # edit annotation or sequence match
        elif itemType in ('annotation', 'match'):
            self.onNotationEdit()
    # ----
    
    
    def onAdd(self, evt):
        """Add button pressed."""
        
        # get selected item
        item = self.documentTree.GetSelection()
        indent = self.documentTree.getItemIndent(item)
        
        # popup menu
        menu = wx.Menu()
        menu.Append(ID_sequenceNew, "New Sequence...")
        menu.AppendSeparator()
        menu.Append(ID_documentNew, "New Document")
        menu.Append(ID_documentNewFromClipboard, "New from Clipboard")
        menu.AppendSeparator()
        menu.Append(ID_documentOpen, "Open Document...")
        
        menu.Enable(ID_sequenceNew, bool(indent))
        
        # set events
        self.Bind(wx.EVT_MENU, self.parent.onSequenceNew, id=ID_sequenceNew)
        self.Bind(wx.EVT_MENU, self.parent.onDocumentNew, id=ID_documentNew)
        self.Bind(wx.EVT_MENU, self.parent.onDocumentNewFromClipboard, id=ID_documentNewFromClipboard)
        self.Bind(wx.EVT_MENU, self.parent.onDocumentOpen, id=ID_documentOpen)
        
        self.PopupMenu(menu)
        menu.Destroy()
        self.SetFocus()
    # ----
    
    
    def onDelete(self, evt):
        """Delete button pressed."""
        
        # make menu
        menu = wx.Menu()
        menu.Append(ID_documentAnnotationDelete, "Delete Annotation")
        menu.Append(ID_documentAnnotationsDelete, "Delete All Annotations")
        menu.AppendSeparator()
        menu.Append(ID_sequenceDelete, "Delete Sequence")
        menu.Append(ID_sequenceMatchDelete, "Delete Sequence Match")
        menu.Append(ID_sequenceMatchesDelete, "Delete All Matches")
        menu.AppendSeparator()
        menu.Append(ID_documentNotationsDelete, "Delete All Notations")
        menu.AppendSeparator()
        menu.Append(ID_documentClose, "Close Document")
        menu.Append(ID_documentCloseAll, "Close All Documents")
        
        # disable items
        menu.Enable(ID_documentAnnotationDelete, False)
        menu.Enable(ID_documentAnnotationsDelete, False)
        menu.Enable(ID_sequenceDelete, False)
        menu.Enable(ID_sequenceMatchDelete, False)
        menu.Enable(ID_sequenceMatchesDelete, False)
        menu.Enable(ID_documentNotationsDelete, False)
        menu.Enable(ID_documentClose, False)
        menu.Enable(ID_documentCloseAll, bool(self.documents))
        
        # bind events
        self.Bind(wx.EVT_MENU, self.onNotationDelete, id=ID_documentAnnotationDelete)
        self.Bind(wx.EVT_MENU, self.parent.onDocumentAnnotationsDelete, id=ID_documentAnnotationsDelete)
        
        self.Bind(wx.EVT_MENU, self.parent.onSequenceDelete, id=ID_sequenceDelete)
        self.Bind(wx.EVT_MENU, self.onNotationDelete, id=ID_sequenceMatchDelete)
        self.Bind(wx.EVT_MENU, self.parent.onSequenceMatchesDelete, id=ID_sequenceMatchesDelete)
        
        self.Bind(wx.EVT_MENU, self.parent.onDocumentNotationsDelete, id=ID_documentNotationsDelete)
        self.Bind(wx.EVT_MENU, self.parent.onDocumentClose, id=ID_documentClose)
        self.Bind(wx.EVT_MENU, self.parent.onDocumentCloseAll, id=ID_documentCloseAll)
        
        # get selected item
        item = self.documentTree.GetSelection()
        indent = self.documentTree.getItemIndent(item)
        if indent:
            
            itemType = self.documentTree.getItemType(item)
            docIndex = self._getDocumentIndex(item)
            seqIndex = self._getSequenceIndex(item)
            
            if self.documents[docIndex].annotations:
                menu.Enable(ID_documentAnnotationsDelete, True)
            if itemType == 'annotation':
                menu.Enable(ID_documentAnnotationDelete, True)
                menu.Enable(ID_documentAnnotationsDelete, True)
            if itemType == 'sequence':
                menu.Enable(ID_sequenceDelete, True)
            if itemType == 'sequence' and self.documents[docIndex].sequences[seqIndex].matches:
                menu.Enable(ID_sequenceMatchesDelete, True)
            if itemType == 'match':
                menu.Enable(ID_sequenceMatchDelete, True)
                menu.Enable(ID_sequenceMatchesDelete, True)
            if itemType != None:
                menu.Enable(ID_documentNotationsDelete, True)
                menu.Enable(ID_documentClose, True)
        
        self.PopupMenu(menu)
        menu.Destroy()
        self.SetFocus()
    # ----
    
    
    def onNotationEdit(self, evt=None):
        """Edit selected annotation or sequence match."""
        
        # get selected item
        item = self.documentTree.GetSelection()
        itemType = self.documentTree.getItemType(item)
        itemData = self.documentTree.GetPyData(item)
        
        # show dialog
        dlg = dlgNotation(self.parent, itemData, button='Update')
        if dlg.ShowModal() == wx.ID_OK:
            dlg.Destroy()
            
            if itemType == 'annotation':
                self.parent.onDocumentChanged(('annotations'))
            elif itemType == 'match':
                self.parent.onDocumentChanged(('matches'))
        
        else:
            dlg.Destroy()
    # ----
    
    
    def onNotationDelete(self, evt=None):
        """Delete selected annotation or sequence match."""
        
        # get index
        item = self.documentTree.GetSelection()
        itemType = self.documentTree.getItemType(item)
        
        # delete annotation
        if itemType == 'annotation':
            annotIndex = self._getAnnotationIndex(item)
            if annotIndex != None:
                self.parent.onDocumentAnnotationsDelete(annotIndex=annotIndex)
        
        # delete sequence match
        elif itemType == 'match':
            matchIndex = self._getMatchIndex(item)
            if matchIndex != None:
                self.parent.onSequenceMatchesDelete(matchIndex=matchIndex)
    # ----
    
    
    def onSendToMassCalculator(self, evt=None):
        """Send selected item to Mass Calculator panel."""
        
        # get selected item
        item = self.documentTree.GetSelection()
        itemType = self.documentTree.getItemType(item)
        itemData = self.documentTree.GetPyData(item)
        
        # send data to Mass Calculator
        if itemType == 'sequence':
            self.parent.onToolsMassCalculator(formula=itemData.formula())
        elif itemType in ('annotation', 'match'):
            if itemData.radical:
                self.parent.onToolsMassCalculator(formula=itemData.formula, charge=itemData.charge, agentFormula='e', agentCharge=-1)
            else:
                self.parent.onToolsMassCalculator(formula=itemData.formula, charge=itemData.charge, agentFormula='H', agentCharge=1)
    # ----
    
    
    def onSendToEnvelopeFit(self, evt=None):
        """Send selected item to envelope fit panel."""
        
        # get selected item
        item = self.documentTree.GetSelection()
        itemType = self.documentTree.getItemType(item)
        itemData = self.documentTree.GetPyData(item)
        
        # send data to envelope fit
        if itemType == 'sequence':
            self.parent.onToolsEnvelopeFit(sequence=itemData)
        
        elif itemType == 'annotation':
            self.parent.onToolsEnvelopeFit(formula=itemData.formula, charge=itemData.charge)
        
        elif itemType == 'match':
            
            scale = None
            if itemData.sequenceRange and config.envfit['loss'] == 'H' and config.envfit['gain'] == 'H{2}':
                scale = [0, itemData.sequenceRange[1]-itemData.sequenceRange[0]]
            
            self.parent.onToolsEnvelopeFit(formula=itemData.formula, charge=itemData.charge, scale=scale)
    # ----
    
    
    
    # DOCUMENT
    
    def selectDocument(self, docIndex):
        """Select document"""
        
        # deselect all documents
        if docIndex == None:
            self.documentTree.Unselect()
            self.parent.onDocumentSelected(None)
            return
        
        # get item
        docData = self.documents[docIndex]
        docItem = self.documentTree.getItemByData(docData)
        
        # select document
        self.documentTree.SelectItem(docItem)
    # ----
    
    
    def appendLastDocument(self):
        """Append document."""
        
        # get last document
        docData = self.documents[-1]
        
        # append to tree
        self.documentTree.appendDocument(docData)
    # ----
    
    
    def deleteDocument(self, docIndex):
        """Delete selected document."""
        
        # check document
        if docIndex == None:
            return
        
        # remove from tree
        self.documentTree.deleteItemByData(self.documents[docIndex])
    # ----
    
    
    def enableDocument(self, docIndex, enable):
        """Enable/disable selected document."""
        
        # check document
        if docIndex == None:
            return
        
        # get item
        docData = self.documents[docIndex]
        docItem = self.documentTree.getItemByData(docData)
        
        # update document
        self.documentTree.enableItemTree(docItem, enable)
    # ----
    
    
    def updateDocumentTitle(self, docIndex):
        """Update document title."""
        
        # check document
        if docIndex == None:
            return
        
        # get item
        docData = self.documents[docIndex]
        docItem = self.documentTree.getItemByData(docData)
        
        # get title
        title = docData.title
        if docData.dirty:
            title = '*' + title
        
        # update document title
        self.documentTree.SetItemText(docItem, title)
    # ----
    
    
    def updateDocumentColour(self, docIndex):
        """Update bullet of selected document."""
        
        # check document
        if docIndex == None:
            return
        
        # get document item
        docData = self.documents[docIndex]
        docItem = self.documentTree.getItemByData(docData)
        
        # update colour
        self.documentTree.updateDocumentColour(docItem)
    # ----
    
    
    def updateAnnotations(self, docIndex, expand=None):
        """Set new annotations for document."""
        
        # check document
        if docIndex == None:
            return
        
        # get item
        annotsData = self.documents[docIndex].annotations
        annotsItem = self.documentTree.getItemByData(annotsData)
        
        # expand parent
        if expand:
            parent = self.documentTree.GetItemParent(annotsItem)
            self.documentTree.Expand(parent)
        
        # get expand
        if not expand:
            expand = self.documentTree.IsExpanded(annotsItem)
        
        # remove old annotations
        self.documentTree.Collapse(annotsItem)
        self.documentTree.DeleteChildren(annotsItem)
        
        # add new annotations
        for annotData in annotsData:
            self.documentTree.appendNotation(annotsItem, annotData)
        
        # expand tree
        if expand:
            self.documentTree.Expand(annotsItem)
    # ----
    
    
    
    # SEQUENCE
    
    def selectSequence(self, docIndex, seqIndex):
        """Select sequence"""
        
        # check index
        if docIndex == None or seqIndex == None:
            return
        
        # get item
        seqData = self.documents[docIndex].sequences[seqIndex]
        seqItem = self.documentTree.getItemByData(seqData)
        
        # select sequence
        self.documentTree.SelectItem(seqItem)
    # ----
    
    
    def appendLastSequence(self, docIndex):
        """Append new sequence to the tree."""
        
        # check document
        if docIndex == None:
            return
        
        # get document item
        docData = self.documents[docIndex]
        docItem = self.documentTree.getItemByData(docData)
        
        # get last sequence
        seqData = docData.sequences[-1]
        
        # append to tree
        self.documentTree.appendSequence(docItem, seqData)
    # ----
    
    
    def deleteSequence(self, docIndex, seqIndex):
        """Delete selected sequence."""
        
        # check document
        if docIndex == None or seqIndex == None:
            return
        
        # collapse document first
        docData = self.documents[docIndex]
        docItem = self.documentTree.getItemByData(docData)
        self.documentTree.Collapse(docItem)
        
        # delete sequence
        seqData = self.documents[docIndex].sequences[seqIndex]
        self.documentTree.deleteItemByData(seqData)
        
        # expand tree
        self.documentTree.Expand(docItem)
    # ----
    
    
    def updateSequenceTitle(self, docIndex, seqIndex):
        """Set new label for sequence."""
        
        # check document
        if docIndex == None or seqIndex == None:
            return
        
        # get item
        seqData = self.documents[docIndex].sequences[seqIndex]
        seqItem = self.documentTree.getItemByData(seqData)
        
        # set new label
        self.documentTree.SetItemText(seqItem, seqData.title)
    # ----
    
    
    def updateSequenceMatches(self, docIndex, seqIndex, expand=False):
        """Set new matches for sequence."""
        
        # check document
        if docIndex == None or seqIndex == None:
            return
        
        # get item
        seqData = self.documents[docIndex].sequences[seqIndex]
        seqItem = self.documentTree.getItemByData(seqData)
        
        # expand parent
        if expand:
            parent = self.documentTree.GetItemParent(seqItem)
            self.documentTree.Expand(parent)
        
        # get expand
        if not expand:
            expand = self.documentTree.IsExpanded(seqItem)
        
        # remove old matches
        self.documentTree.Collapse(seqItem)
        self.documentTree.DeleteChildren(seqItem)
        
        # add new matches
        for matchData in seqData.matches:
            self.documentTree.appendNotation(seqItem, matchData)
        
        # expand tree
        if expand:
            self.documentTree.Expand(seqItem)
    # ----
    
    
    def updateSequences(self, docIndex):
        """Set new sequences for current document."""
        
        # check document
        if docIndex == None:
            return
        
        # collapse document first
        docData = self.documents[docIndex]
        docItem = self.documentTree.getItemByData(docData)
        expand = self.documentTree.IsExpanded(docItem)
        self.documentTree.Collapse(docItem)
        
        # delete sequences
        if docItem.IsOk() and self.documentTree.ItemHasChildren(docItem):
            items = []
            
            child, cookie = self.documentTree.GetFirstChild(docItem)
            while child.IsOk():
                if self.documentTree.getItemType(child) == 'sequence':
                    items.append(child)
                child, cookie = self.documentTree.GetNextChild(docItem, cookie)
            
            for item in items:
                self.documentTree.Delete(item)
        
        # set new sequences
        for seqData in self.documents[docIndex].sequences:
            seqItem = self.documentTree.appendSequence(docItem, seqData)
        
        # expand tree
        if expand:
            self.documentTree.Expand(docItem)
    # ----
    
    
    
    # UTILITIES
    
    def getSelectedItemType(self):
        """Get selected item type."""
        
        item = self.documentTree.GetSelection()
        itemType = self.documentTree.getItemType(item)
        
        return itemType
    # ----
    
    
    def _getDocumentIndex(self, item):
        """Get parent document index."""
        
        docItem = self.documentTree.getParentItem(item, 1)
        docData = self.documentTree.GetPyData(docItem)
        
        if docData in self.documents:
            return self.documents.index(docData)
        else:
            return None
    # ----
    
    
    def _getAnnotationIndex(self, item):
        """Get annotation index."""
        
        docIndex = self._getDocumentIndex(item)
        annotData = self.documentTree.GetPyData(item)
        
        if annotData in self.documents[docIndex].annotations:
            return self.documents[docIndex].annotations.index(annotData)
        else:
            return None
    # ----
    
    
    def _getSequenceIndex(self, item):
        """Get parent sequence index."""
        
        docIndex = self._getDocumentIndex(item)
        seqItem = self.documentTree.getParentItem(item, 2)
        seqData = self.documentTree.GetPyData(seqItem)
        
        if seqData in self.documents[docIndex].sequences:
            return self.documents[docIndex].sequences.index(seqData)
        else:
            return None
    # ----
    
    
    def _getMatchIndex(self, item):
        """Get match index."""
        
        docIndex = self._getDocumentIndex(item)
        seqIndex = self._getSequenceIndex(item)
        matchData = self.documentTree.GetPyData(item)
        
        if matchData in self.documents[docIndex].sequences[seqIndex].matches:
            return self.documents[docIndex].sequences[seqIndex].matches.index(matchData)
        else:
            return None
    # ----
    



class documentsTree(wx.TreeCtrl):
    """Documents tree."""
    
    def __init__(self, parent, id, size=(-1,-1), style=mwx.DOCTREE_STYLE):
        wx.TreeCtrl.__init__(self, parent, id, size=size, style=style)
        
        self.parent = parent
        
        # set font and colour
        self.SetFont(wx.SMALL_FONT)
        self.SetOwnBackgroundColour(mwx.DOCTREE_COLOUR)
        
        # init bullets
        self.bullets = wx.ImageList(13, 12)
        self.SetImageList(self.bullets)
        self._resetBullets()
        
        # add root
        root = self.AddRoot("Documents")
        self.SetItemImage(root, 0, wx.TreeItemIcon_Normal)
    # ----
    
    
    def getItemIndent(self, item):
        """Get indent of selected item."""
        
        # check item
        if not item.IsOk():
            return False
        
        # get indent
        indent = 0
        root = self.GetRootItem()
        while item.IsOk():
            if item == root:
                return indent
            else:
                item = self.GetItemParent(item)
                indent += 1
    # ----
    
    
    def getItemType(self, item):
        """Get current item type."""
        
        # check item
        if not item.IsOk() or item is self.GetRootItem():
            return None
        
        # get item type
        data = self.GetPyData(item)
        if isinstance(data, doc.document):
            return 'document'
        elif isinstance(data, list):
            return 'annotations'
        elif isinstance(data, doc.annotation):
            return 'annotation'
        elif isinstance(data, mspy.sequence):
            return 'sequence'
        elif isinstance(data, doc.match):
            return 'match'
        else:
            return None
    # ----
    
    
    def getItemByData(self, data, root=None, cookie=0):
        """Get item by its data."""
        
        # get root
        if root == None:
            root = self.GetRootItem()
        
        # check children
        if self.ItemHasChildren(root):
            firstchild, cookie = self.GetFirstChild(root)
            if self.GetPyData(firstchild) is data:
                return firstchild
            matchedItem = self.getItemByData(data, firstchild, cookie)
            if matchedItem:
                return matchedItem
        
        # check siblings
        child = self.GetNextSibling(root)
        if child:
            if self.GetPyData(child) is data:
                return child
            matchedItem = self.getItemByData(data, child, cookie)
            if matchedItem:
                return matchedItem
        
        # no such item found
        return False
    # ----
    
    
    def getParentItem(self, item, level):
        """Get parent item for selected item and level."""
        
        # get item
        for x in range(level, self.getItemIndent(item)):
            item = self.GetItemParent(item)
        
        return item
    # ----
    
    
    def enableItemTree(self, item, enable=True):
        """Enable/disable all children recursively."""
        
        # enable current item
        self.enableItem(item, enable)
        
        # enable children
        (child, cookie) = self.GetFirstChild(item)
        while child.IsOk():
            
            # enable item
            self.enableItem(child, enable)
            
            # check children
            if self.ItemHasChildren(child):
                self.enableItemTree(child, enable)
            
            # get next
            (child, cookie) = self.GetNextChild(item, cookie)
    # ---
    
    
    def enableItem(self, item, enable=True):
        """Enable document and all children."""
        
        # get item indent
        itemType = self.getItemType(item)
        if not itemType:
            return
        
        # set text colour
        if enable:
            self.SetItemTextColour(item, (0,0,0))
            self.SetItemBold(item, False)
        else:
            self.SetItemTextColour(item, (150,150,150))
            self.SetItemBold(item, False)
        
        # set document bullet
        if itemType == 'document':
            if enable:
                self.SetItemImage(item, self.GetPyData(item).bullet, wx.TreeItemIcon_Normal)
            else:
                self.SetItemImage(item, 1, wx.TreeItemIcon_Normal)
        
        # set annotations bullet
        elif itemType == 'annotations':
            if enable:
                self.SetItemImage(item, 2, wx.TreeItemIcon_Normal)
            else:
                self.SetItemImage(item, 3, wx.TreeItemIcon_Normal)
        
        # set sequence bullet
        elif itemType == 'sequence':
            if enable:
                self.SetItemImage(item, 4, wx.TreeItemIcon_Normal)
            else:
                self.SetItemImage(item, 5, wx.TreeItemIcon_Normal)
        
        # set match / annotation bullet
        elif itemType == 'match' or  itemType == 'annotation':
            if enable:
                self.SetItemImage(item, 6, wx.TreeItemIcon_Normal)
            else:
                self.SetItemImage(item, 7, wx.TreeItemIcon_Normal)
    # ----
    
    
    def appendDocument(self, docData):
        """Append document to tree."""
        
        # add bullet
        docData.bullet = self.bullets.Add(self._makeColourBullet(docData.colour, True))
        
        # get title
        title = docData.title
        if docData.dirty:
            title = '*' + title
        
        # add document
        docItem = self.AppendItem(self.GetRootItem(), title)
        self.SetItemImage(docItem, docData.bullet, wx.TreeItemIcon_Normal)
        self.SetPyData(docItem, docData)
        
        # add annotations
        annotsItem = self.AppendItem(docItem, 'Annotations')
        self.SetItemImage(annotsItem, 2, wx.TreeItemIcon_Normal)
        self.SetPyData(annotsItem, docData.annotations)
        for annotData in docData.annotations:
            self.appendNotation(annotsItem, annotData)
        
        # add sequences
        for seqData in docData.sequences:
            seqItem = self.appendSequence(docItem, seqData)
        
        # enable/disable document and all children
        self.enableItemTree(docItem, docData.visible)
        
        return docItem
    # ----
    
    
    def appendSequence(self, item, seqData):
        """Append sequence to tree."""
        
        # add sequence
        seqItem = self.AppendItem(item, seqData.title)
        self.SetItemImage(seqItem, 4, wx.TreeItemIcon_Normal)
        self.SetPyData(seqItem, seqData)
        
        # add matches
        for matchData in seqData.matches:
            self.appendNotation(seqItem, matchData)
        
        return seqItem
    # ----
    
    
    def appendNotation(self, item, notationData):
        """Append notation to tree."""
        
        # get mz
        mz = round(notationData.mz, config.main['mzDigits'])
        
        # get error
        error = notationData.delta(config.main['errorUnits'])
        if error != None and config.main['errorUnits'] == 'ppm':
            error = round(error, config.main['ppmDigits'])
        elif error != None:
            error = round(error, config.main['mzDigits'])
        
        # make label
        if error != None:
            label = '%s (%s %s) %s' % (mz, error, config.main['errorUnits'], notationData.label)
        else:
            label = '%s %s' % (mz, notationData.label)
        
        # add match
        notationItem = self.AppendItem(item, label)
        self.SetItemImage(notationItem, 6, wx.TreeItemIcon_Normal)
        self.SetPyData(notationItem, notationData)
        
        return notationItem
    # ----
    
    
    def deleteItemByData(self, data):
        """Delete item by data."""
        
        item = self.getItemByData(data)
        if item:
            self.Delete(item)
    # ----
    
    
    def highlightDocument(self, item):
        """Highlight parent document."""
        
        # unbold all documents
        child, cookie = self.GetFirstChild(self.GetRootItem())
        while child.IsOk():
            self.SetItemBold(child, False)
            child, cookie = self.GetNextChild(self.GetRootItem(), cookie)
        
        # select parent document
        if item != None:
            item = self.getParentItem(item, 1)
            self.SetItemBold(item, True)
    # ----
    
    
    def updateDocumentColour(self, item):
        """Set new bullet colour."""
        
        # add bullet
        item = self.getParentItem(item, 1)
        docData = self.GetPyData(item)
        docData.bullet = self.bullets.Add(self._makeColourBullet(docData.colour, True))
        
        # set new bullet
        self.SetItemImage(item, docData.bullet, wx.TreeItemIcon_Normal)
    # ----
    
    
    def _resetBullets(self):
        """Erase all bullets and make defaults."""
        
        self.bullets.RemoveAll()
        self.bullets.Add(images.lib['bulletsDocument'])
        self.bullets.Add(self._makeColourBullet((150,150,150), False))
        self.bullets.Add(images.lib['bulletsAnnotationsOn'])
        self.bullets.Add(images.lib['bulletsAnnotationsOff'])
        self.bullets.Add(images.lib['bulletsSequenceOn'])
        self.bullets.Add(images.lib['bulletsSequenceOff'])
        self.bullets.Add(images.lib['bulletsNotationOn'])
        self.bullets.Add(images.lib['bulletsNotationOff'])
    # ----
    
    
    def _makeColourBullet(self, colour, filled=True):
        """Make bullet bitmap with specified colour."""
        
        # create empty bitmap
        bitmap = wx.EmptyBitmap(13, 12)
        dc = wx.MemoryDC()
        dc.SelectObject(bitmap)
        
        # clear background
        if wx.Platform != '__WXMAC__':
            dc.SetBackground(wx.Brush(mwx.DOCTREE_COLOUR, wx.SOLID))
            dc.Clear()
        
        # set pen and brush
        if filled:
            pencolour = [max(x-70,0) for x in colour]
            dc.SetPen(wx.Pen(pencolour, 1, wx.SOLID))
            dc.SetBrush(wx.Brush(colour, wx.SOLID))
        else:
            dc.SetPen(wx.Pen(colour, 1, wx.SOLID))
            dc.SetBrush(wx.TRANSPARENT_BRUSH)
        
        # draw circle
        dc.DrawCircle(6, 7, mwx.DOCTREE_BULLETSIZE)
        dc.SelectObject(wx.NullBitmap)
        
        return bitmap
    # ----
    



class fileDropTarget(wx.FileDropTarget):
    """Generic drop target for files."""
    
    def __init__(self, fce):
        wx.FileDropTarget.__init__(self)
        self.fce = fce
    # ----
    
    
    def OnDropFiles(self, x, y, paths):
        """Open dropped files."""
        self.fce(paths=paths)
    # ----