Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/ka_importer.py
blob: 86e40c16d1222a92f5ec281a56382d43c12abc3a (plain)
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
# coding: UTF-8
# Copyright 2009, 2010 Thomas Jourdan
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
import cairo

import os
import sys
import traceback
import ka_debug
import ka_extensionpoint

_marker = 'v' + str(ka_extensionpoint.revision_number)
_populated = False
_themes = []
_rgb_image_list = []
_alpha_image_list = []
_svg_image_list = []

def _populate_theme_list(import_path):
    """
    pre: import_path.startswith('/')
    """
    for theme in os.listdir(import_path):
        abs_name = os.path.join(import_path, theme)
        if os.path.isdir(abs_name):
            _themes.append(theme)
            _populate_imports(abs_name, theme)
    _populate_imports(import_path, '')

def _populate_imports(import_path, theme):
    """
    pre: import_path.startswith('/')
    """
    for element in os.listdir(import_path):
        abs_name = os.path.join(import_path, element)
        if os.path.isfile(abs_name):
            if element.lower().endswith('.png'):
                if element.find('.alpha.') == -1:
                    _rgb_image_list.append( (theme, abs_name) )
                else:
                    _alpha_image_list.append( (theme, abs_name) )
            elif element.lower().endswith('.svg'):
                _svg_image_list.append( (theme, abs_name) )

def _populate():
    global _populated
    if _populated:
        return
    _populated = True
    _populate_theme_list(get_import_path())

def get_import_path():
    """
    post: os.path.exists(__return__)
    """
    import_path = ka_debug.DEBUG_PROFILE_PATH # default path for debugging
    if 'SUGAR_BUNDLE_PATH' in os.environ:
        import sugar.env
        ka_debug.info('profile_path    ' + sugar.env.get_profile_path())
        import_path = sugar.env.get_profile_path()
    import_path = os.path.join(import_path,
                               'net.sourceforge.kandid/data/collection')
    if not os.path.exists(import_path):
        try:
            os.makedirs(import_path)
        except:
            print 'failed writing [%s] [%s] [%s]' % \
                       (import_path, sys.exc_info()[0], sys.exc_info()[1])
            traceback.print_exc(file=sys.__stderr__)
    ka_debug.info('import_path     ' + import_path)
    return import_path

def get_tmp_path():
    """
    post: os.path.exists(__return__)
    """
    tmp_path = ka_debug.DEBUG_PROFILE_PATH # default path for debugging
    if 'SUGAR_BUNDLE_PATH' in os.environ:
        import sugar.env
        ka_debug.info('profile_path    ' + sugar.env.get_profile_path())
        tmp_path = sugar.env.get_profile_path()
    tmp_path = os.path.join(tmp_path, 'net.sourceforge.kandid/tmp')
    ka_debug.info('import_path     ' + tmp_path)
    return tmp_path

def get_theme_list():
    _populate()
    return _themes

def get_rgb_image_list(theme):
    _populate()
    return [x[1] for x in _rgb_image_list if x[0] == theme]

def get_alpha_image_list(theme):
    """
    post: forall(__return__, lambda x: x.lower().endswith('.alpha.png'))
    """
    _populate()
    return [x[1] for x in _alpha_image_list if x[0] == theme]

def get_svg_image_list(theme):
    """
    post: forall(__return__, lambda x: x.lower().endswith('.svg'))
    """
    _populate()
    return [x[1] for x in _svg_image_list if x[0] == theme]

def _make_path(target_path, theme):
    """Create output folder
    pre: os.path.exists(target_path)
    post: os.path.exists(__return__)
    """
    ip = os.path.join(target_path, theme) if len(theme) else target_path
    if not os.path.exists(ip):
        os.makedirs(ip)
    return ip

def _write_file(target_path, theme, file_name, content):
    """Write textual content to the file system.
    """
    out_file = None
    fn = ''
    try:
        fn = os.path.join(_make_path(target_path, theme), file_name)
        if not os.path.exists(fn):
            out_file = open(fn, 'w')
            out_file.write(content)
    except:
        ka_debug.err('failed writing [%s] [%s] [%s]' % \
                   (fn, sys.exc_info()[0], sys.exc_info()[1]))
        traceback.print_exc(file=sys.__stderr__)
    finally:
        if out_file:
            out_file.close()

def _write_surface_file(target_path, theme, file_name, surface):
    """Write graphical content to the file system.
    """
    fn = ''
    try:
        fn = os.path.join(_make_path(target_path, theme), file_name)
        if not os.path.exists(fn):
            surface.write_to_png(fn)
    except:
        ka_debug.err('failed writing [%s] [%s] [%s]' % \
                   (fn, sys.exc_info()[0], sys.exc_info()[1]))
        traceback.print_exc(file=sys.__stderr__)

def _create_icon(is_plus_sign):
    width, height = 16, 16  
    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
    ctx = cairo.Context(surface)
    ctx.scale(float(width), float(height))
#    ka_debug.matrix(ctx.get_matrix())
    # paint background
    ctx.set_operator(cairo.OPERATOR_OVER)
    ctx.set_source_rgb(1.0, 1.0, 1.0)
    ctx.paint()
    ctx.set_line_width(0.1)
    ctx.set_source_rgb(0.5, 0.5, 0.5)
    ctx.move_to(0.0, 0.0)
    ctx.line_to(1.0, 0.0)
    ctx.line_to(1.0, 1.0)
    ctx.line_to(0.0, 1.0)
    ctx.line_to(0.0, 0.0)
    ctx.stroke()
    ctx.set_source_rgb(0.0, 0.0, 0.0)
    ctx.move_to(0.2, 0.5)
    ctx.line_to(0.8, 0.5)
    if is_plus_sign:
        ctx.move_to(0.5, 0.2)
        ctx.line_to(0.5, 0.8)
    ctx.stroke()
    return surface

def _post_install():
    """
    pre: len(_marker) >= 2 and int(_marker[1]) > 2
    """
    try:
        tmp_path = get_tmp_path()
        import_path = get_import_path()
        install_marker = os.path.join(import_path, 'install.inf')
        reinstall = not os.path.exists(install_marker)
        if not reinstall:
            in_file = None
            try:
                in_file = open(install_marker, 'r')
                marker = in_file.read()
                reinstall = not marker == _marker
            except:
                reinstall = True
                ka_debug.err('failed reading [%s] [%s] [%s]' % \
                        (install_marker, sys.exc_info()[0], sys.exc_info()[1]))
                traceback.print_exc(file=sys.__stderr__)
            finally:
                if in_file:
                    in_file.close()
        if not reinstall:
            return

        ka_debug.info('running post installation [%s]' % import_path)
        _write_file(import_path, 'segment_of_a_circle', 'stamp_circle.svg',
'''<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg version="1.1"
     xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink"
     width="100" height="100" >

    <circle cx ="50" cy ="50" r ="50" style="fill:#000000"/>

</svg>
''' 
        )
        _write_file(import_path, 'segment_of_a_circle', 'stamp_halfcircle_bottom.svg',
'''<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg version="1.1"
     xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink"
     width="100" height="100" >

    <path
       d="M 0,100 A 50 50 180 0 1 100,100"
       style="fill:#000000;"/>

</svg>
''' 
        )
        _write_file(import_path, 'segment_of_a_circle', 'stamp_halfcircle_left.svg',
'''<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg version="1.1"
     xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink"
     width="100" height="100" >

    <path
       d="M 50,100 A 50 50 180 0 1 50,0"
       style="fill:#000000;"/>

</svg>
''' 
        )
        _write_file(import_path, 'segment_of_a_circle', 'stamp_halfcircle_right.svg',
'''<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg version="1.1"
     xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink"
     width="100" height="100" >

    <path
       d="M 50,100 A 50 50 180 0 0 50,0"
       style="fill:#000000;"/>

</svg>
''' 
        )
        _write_file(import_path, 'segment_of_a_circle', 'stamp_halfcircle_top.svg',
'''<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg version="1.1"
     xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink"
     width="100" height="100" >

    <path
       d="M 0,0 A 50 50 180 0 0 100,0"
       style="fill:#000000;"/>

</svg>
''' 
        )

#---- cybernetic_serendipity
        _write_file(import_path, 'cybernetic_serendipity', 'stamp_ascending_path.svg',
'''<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg version="1.1"
     xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink"
     width="100" height="100" >

    <line x1="16.666666667" y1="83.333333333320" x2="83.333333333320" y2="16.666666667"
          style="fill:none; stroke-width:3%; stroke:#000000;"/>

</svg>
''' 
        )
        _write_file(import_path, 'cybernetic_serendipity', 'stamp_circle_path.svg',
'''<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg version="1.1"
     xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink"
     width="100" height="100" >

    <circle cx ="50" cy ="50" r ="33.333333333"
            style="fill:none; stroke-width:3%; stroke:#000000;"/>

</svg>
''' 
        )
        _write_file(import_path, 'cybernetic_serendipity', 'stamp_descending_path.svg',
'''<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg version="1.1"
     xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink"
     width="100" height="100" >

    <line x1="16.666666667" y1="16.666666667" x2="83.333333333320" y2="83.333333333320"
          style="fill:none; stroke-width:3%; stroke:#000000;"/>

</svg>
''' 
        )
        _write_file(import_path, 'cybernetic_serendipity', 'stamp_horizontal_path.svg',
'''<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg version="1.1"
     xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink"
     width="100" height="100" >

    <line x1="20" y1="55" x2="80" y2="55"
          style="fill:none; stroke-dasharray:19.166666667,3.3333333333; stroke-width:3%; stroke:#000000;"/>
</svg>
''' 
        )
        _write_file(import_path, 'cybernetic_serendipity', 'stamp_sawtooth_path.svg',
'''<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg version="1.1"
     xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink"
     width="100" height="100" >

    <polyline points="20 50, 30 40, 40 50, 50 40, 60 50, 70 40, 80 50"
          style="fill:none; stroke-width:3%; stroke:#000000;"/>
</svg>
''' 
        )
        _write_file(import_path, 'cybernetic_serendipity', 'stamp_square_path.svg',
'''<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg version="1.1"
     xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink"
     width="100" height="100" >

    <rect x="26.42977396" y="26.42977396"
          width="47.140452079" height="47.140452079"
          style="fill:none; stroke-width:3%; stroke:#000000;"/>
</svg>
''' 
        )
        _write_file(import_path, 'cybernetic_serendipity', 'stamp_vertical_path.svg',
'''<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg version="1.1"
     xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink"
     width="100" height="100" >

    <line x1="50" y1="16.666666667" x2="50" y2="83.333333333320"
          style="fill:none; stroke-width:3%; stroke:#000000;"/>

</svg>
''' 
        )
        
#---- marktree
        _write_file(tmp_path, '', 'marktree.js',
'''
/* MarkTree JavaScript code
 * 
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 * 
 * Miika Nurminen, 12.7.2004.
 */

/* cross-browser (tested with ie5, mozilla 1 and opera 5) keypress detection */
function get_keycode(evt) {
  // IE
    code = document.layers ? evt.which
           : document.all ? event.keyCode // event.keyCode!=evt.keyCode!
           : evt.keyCode;

  if (code==0) 
    code=evt.which; // for NS
  return code;
}

var lastnode=null;
var listnodes = null;
var list_index=1;
var lastnodetype=''; // determines if node is a link, input or text;

// up, left, down, right, keypress codes
//ijkl
//var keys = new Array(105,106,107,108);
//num arrows
//var keys = new Array(56,52,50,54);
//wasd
// var press2 = new Array(119,97,115,100);
 var press = new Array(47,45,42,43);

// keydown codes
  //  var keys2=new Array(87,65,83,68);
  var keys= new Array(38,37,40,39);

  // keyset 1 = keydown, otherwise press
function checkup(keyset,n) {
  if (keyset==1) return (n==keys[0]);
  return ((n==press[0]) /*|| (n==press2[0])*/)
}

function checkdn(keyset,n) {
  if (keyset==1) return (n==keys[2]);
  return ((n==press[2]) /*|| (n==press2[2])*/)
}

function checkl(keyset,n) {
  if (keyset==1) return (n==keys[1]);
  return ((n==press[1]) /*|| (n==press2[1])*/)
}

function checkr(keyset,n) {
  if (keyset==1) return (n==keys[3]);
  return ((n==press[3]) /*|| (n==press2[3])*/)
}





function is_exp(n) {
  if (n==null) return false;
  return ((n.className=='exp') || (n.className=='exp_active'));
}

function is_col(n) {
  if (n==null) return false;
  return ((n.className=='col') || (n.className=='col_active'));
}

function is_basic(n) {
  if (n==null) return false;
  return ((n.className=='basic') || (n.className=='basic_active'));
}



/* returns i>=0 if true */
function is_active(node) {
  if (node.className==null) return false
  return node.className.indexOf('_active');
}

function toggle_class(node) {
  if ((node==null) || (node.className==null)) return;
  str=node.className;
  result="";
  i = str.indexOf('_active');
  if (i>0)
    result= str.substr(0,i);
  else
    result= str+"_active";
  node.className=result; 
  return node;
}

function activate(node) {
  node.style.backgroundColor='#eeeeff';
}

function deactivate(node) {
   node.style.backgroundColor='#ffffff';
}

function is_list_node(n) {
  if (n==null) return false;
  if (n.className==null) return false;
  if ( (is_exp(n)) || 
       (is_col(n)) ||
       (is_basic(n)) )
   return true; else return false;
}


function get_href(n) {
  alist=n.attributes;
  if (alist!=null) {
    hr = alist.getNamedItem('href');
    if (hr!=null) return hr.nodeValue;
  }
  if (n.childNodes.length==0) return '';
  for (var i=0; i<n.childNodes.length; i++) {
    s = get_href(n.childNodes[i]);
    if (s!='') return s;
  }
  return '';
}

function get_link(n) {
  if (n==null) return null;
  if (n.style==null) return null;

 // disabling uncontrolled recursion to prevent error messages on IE
 // when trying to focus to invisible links (readonly mode)
//    alert(n.nodeName+' '+n.className);
  if ((n.nodeName=='UL') && (n.className=='sub')) return null;

  if (n.nodeName=='A') return n;
  if (n.childNodes.length==0) return null;
  for (var i=0; i<n.childNodes.length; i++) {
    s = get_link(n.childNodes[i]);
    if (s!=null) return s;
  }
  return null;
}

function set_lastnode(n) {
/*var d = new Date();
var t_mil = d.getMilliseconds();*/
// testattu nopeuksia explorerilla, ei merkittäviä eroja
  if (lastnode==n) return; 
/*  deactivate(lastnode)
  lastnode=n;
  activate(lastnode);*/

  if (is_active(lastnode)>=0)
    toggle_class(lastnode);
  lastnode=n;
  if (!(is_active(lastnode)>=0))
    toggle_class(lastnode);


/*var d2 = new Date();
var t_mil2 = d2.getMilliseconds();
  window.alert(t_mil2-t_mil);*/
}

function next_list_node() {
  tempIndex = list_index;
  while (tempIndex<listnodes.length-1) {
    tempIndex++;
    var x = listnodes[tempIndex];
    if (is_list_node(x)) {
      list_index=tempIndex;
      return;
    }
  }
}

function prev_list_node() {
  tempIndex = list_index;
  while (tempIndex>0) {
    tempIndex--;
    var x = listnodes[tempIndex];
    if (is_list_node(x)) {
      list_index=tempIndex;
      return;
    }
  }
}



function getsub (li) {
  if (li.childNodes.length==0) return null;
  for (var c = 0; c < li.childNodes.length; c++)
    if ( (li.childNodes[c].className == 'sub') || (li.childNodes[c].className == 'subexp') ) 
      return li.childNodes[c];
}

function find_listnode_recursive (li) {
  if (is_list_node(li)) return li; 
  if (li.childNodes.length==0) return null;
  result=null;
  for (var c = 0; c < li.childNodes.length; c++) {
    result=find_listnode_recursive(li.childNodes[c]);
    if (result!=null) return result;
  }
  return null;
}

function next_child_listnode(li) {
  var result=null;
  for (var i=0; i<li.childNodes.length; i++) {
    result=find_listnode_recursive(li.childNodes[i]);
    if (result!=null) return result;
  }
  return null;  
}

function next_actual_sibling_listnode(li) {
  if (li==null) return null;
  var temp=li;
  while (1) { 
    var n = temp.nextSibling;
    if (n==null) {
      n=parent_listnode(temp);
      return next_actual_sibling_listnode(n);
    }
    if (is_list_node(n)) return n;
    temp=n;
  }
}

function next_sibling_listnode(li) {
if (li==null) return null; 
 var result=null;
  var temp=li;
  if (is_col(temp)) return next_child_listnode(temp);
  while (1) { 
    var n = temp.nextSibling;
    if (n==null) {
      n=parent_listnode(temp);
      return next_actual_sibling_listnode(n);
    }
    if (is_list_node(n)) return n;
    temp=n;
  }
}

function last_sibling_listnode(li) {
  if (li==null) return null;
  var temp=li;
  var last=null;
  while(1) {
    var n = temp.nextSibling;
    if (is_list_node(temp)) 
      last = temp;
    if (n==null) {
      if (is_col(last)) return last_sibling_listnode(next_child_listnode(last));
      else return last;
    }
    temp = n;
  }
}

function prev_sibling_listnode(li) { 
  if (li==null) return null;
  var temp=li;
  var n = null;
  while (1) { 
    n = temp.previousSibling;
    if (n==null) {
      return parent_listnode(li);
    }
    if (is_list_node(n)) {
      if (is_col(n)) { 
        return last_sibling_listnode(next_child_listnode(n));
      }
      else {
        return n;
      }
    }
    temp=n;
  }
}


function parent_listnode(li) {
  // added 12.7.2004 to prevent IE error when readonly mode==true
  if (li==null) return null;
  n=li;
  while (1) {
    n=n.parentNode;
    if (n==null) return null;
    if (is_list_node(n)) return n;
  }
}

function getVisibleParents(id) {
  var n = document.getElementById(id);
  while(1) {
    expand(n);
    n = parent_listnode(n);
    if (n==null) return;
  }
}

function onClickHandler (evt) {
if (lastnode==null) 
{
listnodes = document.getElementsByTagName('li');
lastnode=listnodes[1];
temp=listnodes[1];
}


  var target = evt ? evt.target : event.srcElement;
  if (!is_list_node(target)) return;
  toggle(target);
  set_lastnode(target);
}


function expand(node) {
    if (!is_exp(node)) return;
    if (node.className=='exp_active') 
      node.className='col_active';
    else 
        node.className='col';
    setSubClass(node,'subexp');
    //    getsub(node).className='subexp';
}

function collapse(node) {
  if (!is_col(node)) return;
  
if (node.className=='col_active')
    node.className='exp_active'
  else 
    node.className='exp';

 setSubClass(node,'sub');
//  getsub(node).className='sub';

}

function setSubClass(node,name) {
  sub = getsub(node);
  if (sub==null) return;
  sub.className=name;  
}

function toggle(target) {
  if (!is_list_node(target)) return;
    if (is_col(target)) {
      target.className='exp';
      setSubClass(target,'sub');
      //      getsub(target).className='sub';
    }
    else if (is_exp(target)) {
      target.className='col';
      setSubClass(target,'subexp');
      //      getsub(target).className='subexp';
    }
 
}

function expandAll(node) {
    if (node.className=='exp') {
        node.className='col';
        setSubClass(node,'subexp');
//        getsub(node).className='subexp';
    }
    var i;
    if (node.childNodes!=null) 
//    if (node.hasChildNodes()) 
        for ( i = 0; i<node.childNodes.length; i++)
            expandAll(node.childNodes[i]);
}

function collapseAll(node) {
    if  (node.className=='col') {
        node.className='exp';
        setSubClass(node,'sub');
//        getsub(node).className='sub';
    }
    var i;        
    if (node.childNodes!=null) 
// for opera   if (node.hasChildNodes()) 
        for ( i = 0; i<node.childNodes.length; i++)
            collapseAll(node.childNodes[i]);
}



function unFocus(node) {
     // unfocuses potential link that is to be hidden (if a==null there is no link so it should not be blurred).
     // tested with mozilla 1.7, 12.7.2004. /mn (
      intemp=parent_listnode(node);  
      a = get_link(intemp);     // added 6.4. to get keyboard working with
      // moved before collapse to prevent an error message with IE when readonly==true      
      if (a!=null) a.blur(); // netscape after collapsing a focused node
      return intemp;
}

// mode: 0==keypress, 1==keyup
function keyfunc(evt,mode) {
 var c = get_keycode(evt);
 var temp = null;
 var a = null;

  if (lastnode==null) {
    listnodes = document.getElementsByTagName('li');
    lastnode=listnodes[1];
    temp=listnodes[1];
  }

  //window.alert(c);
  if (checkup(mode,c)) { // i 
   temp=prev_sibling_listnode(lastnode);
  }
  else if (checkdn(mode,c)) { // k
    temp=next_sibling_listnode(lastnode);
  }
  else if (checkr(mode,c)) { // l
    expand(lastnode);
    //  temp=next_child_listnode(lastnode);
    // if (temp==null) {
      a = get_link(lastnode);
        if (a!=null) a.focus(); else self.focus(); 
      //}
  }
  else if (checkl(mode,c)) { // j
    if (is_col(lastnode)) {
      unFocus(lastnode);
      collapse(lastnode);
    }
    else {
      temp=unFocus(lastnode);
      collapse(temp);
    }
   //    if (temp==null) lastnode.focus(); // forces focus to correct div (try mozilla typesearch) (doesn't seem to work -mn/6.4.2004)
  }
  else return;
  if (temp!=null) set_lastnode(temp);

  // alert('pressed ' + String.fromCharCode(c) + '(' + c + ')');
  return true;
}


function keytest (evt) {
  return keyfunc(evt,1);
};


function presstest (evt) {
  return keyfunc(evt,0);
};


  document.onclick = onClickHandler;
  document.onkeypress = presstest;
  document.onkeyup = keytest;
'''
        )
        
        _write_file(tmp_path, '', 'treestyles.css',
'''
body {
    background-color: #eeeeee;
      color: #000000;
    font-family : 'DejaVu Sans', 'Sans Serif', sans-serif;
}

:link { color: #0000ff; text-decoration:none;}
:visited { color: #6666ff; text-decoration:none; }
a:active { color: #0000ff; text-decoration:none;}
a:hover {color: #0000ff; text-decoration:underline; }

div.basetext {
    background-color:#ffffff;
        margin-top:11px;
        margin-bottom:11px;
    margin-left:1%;
    margin-right:1%;
    padding-top:11px;
    padding-left:11px;
    padding-right:11px;
    padding-bottom:11px;
    text-align:left;
    font-weight:normal;
  border-width:thin;
  border-style:solid;
  border-color:#dddddd;
}

div.basetop {
  position: fixed;
  width:auto;
  height:auto;
  right:0em;
  top:0em;
  left:auto; 
  top:0;
    background-color:#ffffff;
        margin-top:0;
        margin-bottom:0;
    margin-left:1%;
    margin-right:1%;
    padding-top:2px;
    padding-left:11px;
    padding-right:11px;
    padding-bottom:2px;
    text-align:left;
    font-weight:normal;
text-align:right;
  border-width:thin;
  border-style:solid;
  border-color:#dddddd;
}

h1 {
    text-align:center;
}

span.h2 {
    font-family : 'DejaVu Sans', 'Sans Serif', sans-serif;
    font-weight:bold;
}

div.year {
    margin-right:2%;
    background-color:#eeeeee;
}

div.form {
}

span.cpt {
    color:#005500;
    font-weight:bold;
}

span.cm {
    color:#666666;
}

.fl {
    color:#0000FF;    
    font-style:italic;
}

ul {
    margin-top:1px;
        margin-bottom:1px;
    margin-left:0px;
    padding-left:3%;
}

li {
    list-style:outside;
  margin-top:10px;   
  margin-bottom:10px;
}

ul li {
    list-style:square;
    font-family : 'DejaVu Sans', 'Sans Serif', sans-serif;
    font-weight:normal;
}

li.basic {
    list-style:square;
    list-style-image:none;
  margin-top:2px;
  margin-bottom:2px;
}

span.links {
}




.sub { display: none; }
.subexp {display: block; }
.sub { display: none; } 

.subexp {display: block; } 

li.exp {
  list-style-image:url("plus.png");
  margin-top:10px;
  margin-bottom:10px;
  cursor:pointer;
}

li.col {
  list-style-image:url("minus.png");
  margin-top:10px;
  margin-bottom:10px;
  cursor:pointer;
}

li.exp_active {
  list-style-image:url("plus.png");
  margin-top:10px;  
  margin-bottom:10px;
  background-color:#eeeeff;
  cursor:pointer;
}

li.col_active {
  list-style-image:url("minus.png");
  margin-top:10px;
  margin-bottom:10px;
  background-color:#eeeeff;
  cursor:pointer; /* if not included, bullets are not shown right in moz*/
}


li.basic_active {
  list-style:square;
  list-style-image:none;
  background-color:#eeeeff;
  margin-top:2px;
  margin-bottom:2px;
}
'''
        )
        
#---- icons used by marktree
        #Calculate an '+' and a '-' icon.
        _write_surface_file(tmp_path, '', 'minus.png', _create_icon(False))
        _write_surface_file(tmp_path, '', 'plus.png', _create_icon(True))

#---- write version marker
        _write_file(import_path, '', 'install.inf', _marker)
    except:
        print 'post install failed [%s] [%s]' % \
                   (sys.exc_info()[0], sys.exc_info()[1])
        traceback.print_exc(file=sys.__stderr__)

_post_install()