forked from giuspen/cherrytree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.py
5243 lines (4914 loc) · 271 KB
/
core.py
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
# -*- coding: UTF-8 -*-
#
# core.py
#
# Copyright 2009-2020
# Giuseppe Penone <[email protected]>
# Evgenii Gurianov <https://github.com/txe>
#
# 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 Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
import gtk
import pango
import gtksourceview2
import gobject
import sys
import os
import re
import glob
import subprocess
import webbrowser
import base64
import cgi
import urllib2
import shutil
import time
import pgsc_spellcheck
import cons
import menus
import support
import config
import machines
import clipboard
import imports
import exports
import printing
import tablez
import lists
import findreplace
import codeboxes
import ctdb
#import screenshot
if cons.HAS_APPINDICATOR: import appindicator
class CherryTree:
"""Application's GUI"""
def __init__(self, lang_str, open_with_file, node_name, boss, is_startup, is_arg, export_mode):
"""GUI Startup"""
self.boss = boss
self.filetype = ""
self.user_active = True
self.ctrl_down = False
self.dead_key = ""
self.window = gtk.Window()
self.window.set_title("CherryTree")
self.window.set_default_size(963, 630)
self.window.set_icon_from_file(os.path.join(cons.GLADE_PATH, "cherrytree.png"))
# instantiate external handlers
self.clipboard_handler = clipboard.ClipboardHandler(self)
self.lists_handler = lists.ListsHandler(self)
self.tables_handler = tablez.TablesHandler(self)
self.codeboxes_handler = codeboxes.CodeBoxesHandler(self)
self.state_machine = machines.StateMachine(self)
self.xml_handler = machines.XMLHandler(self)
self.html_handler = exports.Export2Html(self)
self.ctdb_handler = ctdb.CTDBHandler(self)
self.print_handler = printing.PrintHandler(self)
# icon factory
factory = gtk.IconFactory()
for stock_name in cons.STOCKS_N_FILES:
filename = stock_name + ".png"
filepath = os.path.join(cons.GLADE_PATH, filename)
pixbuf = gtk.gdk.pixbuf_new_from_file(filepath)
iconset = gtk.IconSet(pixbuf)
factory.add(stock_name, iconset)
factory.add_default()
# system settings
try:
gtk_settings = gtk.settings_get_default()
gtk_settings.set_property("gtk-button-images", True)
gtk_settings.set_property("gtk-menu-images", True)
except: pass # older gtk do not have the property "gtk-menu-images"
vbox_main = gtk.VBox()
self.window.add(vbox_main)
self.country_lang = lang_str
self.cursor_position = 0
config.config_file_load(self)
if not cons.HAS_APPINDICATOR: self.use_appind = False
elif not cons.HAS_SYSTRAY: self.use_appind = True
# ui manager
actions = gtk.ActionGroup("Actions")
actions.add_actions(menus.get_entries(self))
self.ui = gtk.UIManager()
self.ui.insert_action_group(actions, 0)
self.window.add_accel_group(self.ui.get_accel_group())
self.ui.add_ui_from_string(menus.UI_INFO)
self.ui.add_ui_from_string(config.get_toolbar_ui_str(self))
# menubar add
vbox_main.pack_start(self.ui.get_widget("/MenuBar"), False, False)
# toolbar add
vbox_main.pack_start(self.ui.get_widget("/ToolBar"), False, False)
# hpaned add
self.hpaned = gtk.HPaned()
self.scrolledwindow_tree = gtk.ScrolledWindow()
self.scrolledwindow_tree.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.scrolledwindow_text = gtk.ScrolledWindow()
self.scrolledwindow_text.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.scrolledwindow_text.get_hscrollbar().connect('value-changed', self.on_hscrollbar_text_value_changed)
self.vbox_text = gtk.VBox()
self.header_node_name_eventbox = self.instantiate_node_name_header()
self.vbox_text.pack_start(self.header_node_name_eventbox, False, False)
self.vbox_text.pack_start(self.scrolledwindow_text)
if self.tree_right_side:
self.hpaned.add1(self.vbox_text)
self.hpaned.add2(self.scrolledwindow_tree)
else:
self.hpaned.add1(self.scrolledwindow_tree)
self.hpaned.add2(self.vbox_text)
vbox_main.pack_start(self.hpaned)
# statusbar add
self.statusbar = gtk.Statusbar()
self.statusbar_context_id = self.statusbar.get_context_id('')
self.latest_statusbar_update_time = {}
self.progressbar = gtk.ProgressBar()
progress_frame = gtk.Frame()
progress_frame.set_shadow_type(gtk.SHADOW_NONE)
progress_frame.set_border_width(1)
progress_frame.add(self.progressbar)
self.progresstop = gtk.Button()
self.progresstop.set_image(gtk.image_new_from_stock("gtk-stop", gtk.ICON_SIZE_MENU))
self.progresstop.connect('clicked', self.on_button_progresstop_clicked)
hbox_statusbar = gtk.HBox()
hbox_statusbar.pack_start(self.statusbar, True, True)
hbox_statusbar.pack_start(progress_frame, False, True)
hbox_statusbar.pack_start(self.progresstop, False, True)
vbox_main.pack_start(hbox_statusbar, False, False)
# ROW: 0-icon_stock_id, 1-name, 2-buffer, 3-unique_id, 4-syntax_highlighting, 5-node_sequence, 6-tags, 7-readonly, 8-aux_icon_stock_id, 9-custom_icon_id, 10-weight, 11-foreground, 12-ts_creation, 13-ts_lastsave
self.treestore = gtk.TreeStore(str, str, gobject.TYPE_PYOBJECT, long, str, int, str, gobject.TYPE_BOOLEAN, str, int, int, str, float, float)
self.treeview = gtk.TreeView(self.treestore)
self.treeview.set_headers_visible(False)
self.treeview.drag_source_set(gtk.gdk.BUTTON1_MASK,
[('CT_DND', gtk.TARGET_SAME_WIDGET, 0)],
gtk.gdk.ACTION_MOVE)
self.treeview.drag_dest_set(gtk.DEST_DEFAULT_ALL,
[('CT_DND', gtk.TARGET_SAME_WIDGET, 0)],
gtk.gdk.ACTION_MOVE)
self.renderer_pixbuf = gtk.CellRendererPixbuf()
self.renderer_text = gtk.CellRendererText()
self.renderer_text.set_property('wrap-mode', pango.WRAP_WORD_CHAR)
self.aux_renderer_pixbuf = gtk.CellRendererPixbuf()
self.column = gtk.TreeViewColumn()
self.column.pack_start(self.renderer_pixbuf, False)
self.column.pack_start(self.renderer_text, True)
self.column.pack_start(self.aux_renderer_pixbuf, False)
self.column.set_attributes(self.renderer_pixbuf, stock_id=0)
self.column.set_attributes(self.renderer_text, text=1, weight=10, foreground=11)
self.column.set_attributes(self.aux_renderer_pixbuf, stock_id=8)
self.treeview.append_column(self.column)
self.treeview.set_search_column(1)
self.treeviewselection = self.treeview.get_selection()
self.treeview.connect('cursor-changed', self.on_node_changed)
self.treeview.connect('event-after', self.on_event_after_tree)
self.tree_just_auto_expanded = False
self.treeview.connect('test-collapse-row', self.on_test_collapse_row_tree)
self.treeview.connect('button-press-event', self.on_mouse_button_clicked_tree)
self.treeview.connect('key_press_event', self.on_key_press_cherrytree)
self.treeview.connect('drag-motion', self.on_drag_motion_cherrytree)
self.treeview.connect('drag-data-received', self.on_drag_data_recv_cherrytree)
self.treeview.connect('drag-data-get', self.on_drag_data_get_cherrytree)
self.scrolledwindow_tree.add(self.treeview)
self.orphan_accel_group = gtk.AccelGroup()
self.menu_tree_create()
self.window.connect('delete-event', self.on_window_delete_event)
self.window.connect("focus-out-event", self.on_window_focus_out_event)
self.window.connect('window-state-event', self.on_window_state_event)
self.window.connect("size-allocate", self.on_window_n_tree_size_allocate_event)
self.window.connect('key_press_event', self.on_key_press_window)
self.window.connect("destroy", self.boss.on_window_destroy_event)
self.scrolledwindow_tree.connect("size-allocate", self.on_window_n_tree_size_allocate_event)
self.sourcestyleschememanager = gtksourceview2.StyleSchemeManager()
self.sourceview = gtksourceview2.View()
self.sourceview.set_sensitive(False)
self.sourceview.set_smart_home_end(gtksourceview2.SMART_HOME_END_AFTER)
self.sourceview.connect('populate-popup', self.on_sourceview_populate_popup)
self.sourceview.connect("event", self.on_sourceview_event)
self.sourceview.connect("motion-notify-event", self.on_sourceview_motion_notify_event)
self.sourceview.connect("visibility-notify-event", self.on_sourceview_visibility_notify_event)
self.sourceview.connect("event-after", self.on_sourceview_event_after)
self.sourceview.connect("copy-clipboard", self.clipboard_handler.copy, False)
self.sourceview.connect("cut-clipboard", self.clipboard_handler.cut, False)
self.sourceview.connect("paste-clipboard", self.clipboard_handler.paste)
self.sourceview.set_left_margin(7)
self.sourceview.set_right_margin(7)
self.sourcebuffers = {}
self.hovering_link_iter_offset = -1
self.tag_table = gtk.TextTagTable()
self.scrolledwindow_text.add(self.sourceview)
self.progress_stop = False
self.go_bk_fw_click = False
self.highlighted_obj = None
self.embfiles_opened = {}
self.embfiles_sentinel_id = None
self.codebox_sentinel_id = None
self.bookmarks = []
self.bookmarks_menu_items = []
self.nodes_names_dict = {}
self.password = None
self.export_single = False
self.last_include_node_name = True
self.last_index_in_page = True
self.last_new_node_page = False
self.curr_tree_iter = None
self.curr_window_n_tree_width = None
self.curr_buffer = None
self.node_add_is_duplication = False
self.nodes_cursor_pos = {}
self.links_entries = {'webs':'', 'file':'', 'fold':'', 'anch':'', 'node':None}
self.tags_set = set()
self.file_update = False
self.anchor_size_mod = False
self.embfile_size_mod = False
self.embfile_show_filename_mod = False
self.cursor_key_press = None
self.autosave_timer_id = None
self.spell_check_init = False
self.writing_to_disk = False
self.export_overwrite = False
self.mod_time_sentinel_id = None
self.mod_time_val = 0
self.prefpage = 0
support.set_menu_items_recent_documents(self)
support.set_menu_items_special_chars(self)
self.find_handler = findreplace.FindReplace(self)
if not export_mode:
self.window.show_all() # this before the config_file_apply that could hide something
self.window.present()
config.config_file_apply(self)
self.combobox_prog_lang_init()
if is_arg or not is_startup or self.reload_doc_last:
self.file_startup_load(open_with_file, node_name)
else: self.file_name = ""
if self.tree_is_empty(): self.update_node_name_header()
if self.systray:
if not self.boss.systray_active:
self.status_icon_enable()
if self.start_on_systray: self.window.hide_all()
else: self.ui.get_widget("/MenuBar/FileMenu/exit_app").set_property(cons.STR_VISIBLE, False)
if self.check_version: self.check_for_newer_version()
def on_button_progresstop_clicked(self, *args):
"""Progress Stop Button Clicked"""
self.progress_stop = True
self.progresstop.hide()
def check_for_newer_version(self, *args):
"""Check for a Newer Version"""
self.statusbar.pop(self.statusbar_context_id)
self.statusbar.push(self.statusbar_context_id, _("Checking for Newer Version..."))
while gtk.events_pending(): gtk.main_iteration()
try:
fd = urllib2.urlopen(cons.NEWER_VERSION_URL, timeout=3)
latest_version = fd.read().replace(cons.CHAR_NEWLINE, "")
if len(latest_version) > 10:
# html error page
raise
splitted_latest_v = [int(i) for i in latest_version.split(".")]
splitted_local_v = [int(i) for i in cons.VERSION.split(".")]
weighted_latest_v = splitted_latest_v[0]*10000 + splitted_latest_v[1]*100 + splitted_latest_v[2]
weighted_local_v = splitted_local_v[0]*10000 + splitted_local_v[1]*100 + splitted_local_v[2]
if weighted_latest_v > weighted_local_v:
support.dialog_info(_("A Newer Version Is Available!") + " (%s)" % latest_version, self.window)
self.statusbar.pop(self.statusbar_context_id)
self.update_selected_node_statusbar_info()
else:
self.statusbar.pop(self.statusbar_context_id)
if weighted_latest_v == weighted_local_v:
msg_txt = _("You Are Using the Latest Version Available") + " (%s)" % latest_version
else:
msg_txt = _("You Are Using a Development Version")
self.statusbar.push(self.statusbar_context_id, msg_txt)
except:
self.statusbar.pop(self.statusbar_context_id)
self.statusbar.push(self.statusbar_context_id, _("Failed to Retrieve Latest Version Information - Try Again Later"))
def get_node_icon(self, node_level, node_code, custom_icon_id):
"""Returns the Stock Id given the Node Level"""
if custom_icon_id:
# overridden icon
try: stock_id = cons.NODES_STOCKS[custom_icon_id]
except: stock_id = cons.NODES_STOCKS[cons.NODE_ICON_NO_ICON_ID]
elif node_code in [cons.RICH_TEXT_ID, cons.PLAIN_TEXT_ID]:
# text node
if self.nodes_icons == "c":
if node_level in cons.NODES_ICONS:
stock_id = cons.NODES_ICONS[node_level]
else:
stock_id = cons.NODES_ICONS[-1]
elif self.nodes_icons == "b":
stock_id = cons.NODES_STOCKS[self.default_icon_text]
else:
stock_id = cons.NODES_STOCKS[cons.NODE_ICON_NO_ICON_ID]
else:
# code node
if self.nodes_icons in ["c", "b"]:
stock_id = config.get_stock_id_for_code_type(node_code)
else:
stock_id = cons.NODES_STOCKS[cons.NODE_ICON_NO_ICON_ID]
return stock_id
def text_selection_change_case(self, change_type):
"""Change the Case of the Selected Text/the Underlying Word"""
text_view, text_buffer, syntax_highl, from_codebox = self.get_text_view_n_buffer_codebox_proof()
if not text_buffer: return
if not self.is_curr_node_not_read_only_or_error(): return
if not text_buffer.get_has_selection() and not support.apply_tag_try_automatic_bounds(self, text_buffer=text_buffer):
support.dialog_warning(_("No Text is Selected"), self.window)
return
iter_start, iter_end = text_buffer.get_selection_bounds()
if from_codebox or self.syntax_highlighting != cons.RICH_TEXT_ID:
text_to_change_case = text_buffer.get_text(iter_start, iter_end)
if change_type == "l": text_to_change_case = text_to_change_case.lower()
elif change_type == "u": text_to_change_case = text_to_change_case.upper()
elif change_type == "t": text_to_change_case = text_to_change_case.swapcase()
else:
rich_text = self.clipboard_handler.rich_text_get_from_text_buffer_selection(text_buffer,
iter_start,
iter_end,
change_case=change_type)
start_offset = iter_start.get_offset()
end_offset = iter_end.get_offset()
text_buffer.delete(iter_start, iter_end)
iter_insert = text_buffer.get_iter_at_offset(start_offset)
if from_codebox or self.syntax_highlighting != cons.RICH_TEXT_ID:
text_buffer.insert(iter_insert, text_to_change_case)
else:
text_buffer.move_mark(text_buffer.get_insert(), iter_insert)
self.clipboard_handler.from_xml_string_to_buffer(rich_text)
text_buffer.select_range(text_buffer.get_iter_at_offset(start_offset),
text_buffer.get_iter_at_offset(end_offset))
def text_selection_toggle_case(self, *args):
"""Toggles the Case of the Selected Text/the Underlying Word"""
self.text_selection_change_case("t")
def text_selection_upper_case(self, *args):
"""Uppers the Case of the Selected Text/the Underlying Word"""
self.text_selection_change_case("u")
def text_selection_lower_case(self, *args):
"""Lowers the Case of the Selected Text/the Underlying Word"""
self.text_selection_change_case("l")
def text_row_selection_duplicate(self, *args):
"""Duplicates the Whole Row or a Selection"""
text_view, text_buffer, syntax_highl, from_codebox = self.get_text_view_n_buffer_codebox_proof()
if not text_buffer: return
if not self.is_curr_node_not_read_only_or_error(): return
if text_buffer.get_has_selection():
iter_start, iter_end = text_buffer.get_selection_bounds() # there's a selection
sel_start_offset = iter_start.get_offset()
sel_end_offset = iter_end.get_offset()
if from_codebox or self.syntax_highlighting != cons.RICH_TEXT_ID:
text_to_duplicate = text_buffer.get_text(iter_start, iter_end)
if cons.CHAR_NEWLINE in text_to_duplicate:
text_to_duplicate = cons.CHAR_NEWLINE + text_to_duplicate
text_buffer.insert(iter_end, text_to_duplicate)
else:
rich_text = self.clipboard_handler.rich_text_get_from_text_buffer_selection(text_buffer, iter_start, iter_end)
if cons.CHAR_NEWLINE in rich_text:
text_buffer.insert(iter_end, cons.CHAR_NEWLINE)
iter_end = text_buffer.get_iter_at_offset(sel_end_offset+1)
text_buffer.move_mark(text_buffer.get_insert(), iter_end)
self.clipboard_handler.from_xml_string_to_buffer(rich_text)
text_buffer.select_range(text_buffer.get_iter_at_offset(sel_start_offset),
text_buffer.get_iter_at_offset(sel_end_offset))
else:
cursor_offset = text_buffer.get_iter_at_mark(text_buffer.get_insert()).get_offset()
iter_start, iter_end = self.lists_handler.get_paragraph_iters(text_buffer=text_buffer)
if iter_start == None:
iter_start = text_buffer.get_iter_at_mark(text_buffer.get_insert())
text_buffer.insert(iter_start, cons.CHAR_NEWLINE)
else:
if from_codebox or self.syntax_highlighting != cons.RICH_TEXT_ID:
text_to_duplicate = text_buffer.get_text(iter_start, iter_end)
text_buffer.insert(iter_end, cons.CHAR_NEWLINE + text_to_duplicate)
else:
rich_text = self.clipboard_handler.rich_text_get_from_text_buffer_selection(text_buffer, iter_start, iter_end)
sel_end_offset = iter_end.get_offset()
text_buffer.insert(iter_end, cons.CHAR_NEWLINE)
iter_end = text_buffer.get_iter_at_offset(sel_end_offset+1)
text_buffer.move_mark(text_buffer.get_insert(), iter_end)
self.clipboard_handler.from_xml_string_to_buffer(rich_text)
text_buffer.place_cursor(text_buffer.get_iter_at_offset(cursor_offset))
self.state_machine.update_state()
def text_row_up(self, *args):
"""Moves Up the Current Row/Selected Rows"""
text_view, text_buffer, syntax_highl, from_codebox = self.get_text_view_n_buffer_codebox_proof()
if not text_buffer: return
if not self.is_curr_node_not_read_only_or_error(): return
iter_start, iter_end = self.lists_handler.get_paragraph_iters(text_buffer=text_buffer)
if iter_start == None:
iter_start = text_buffer.get_iter_at_mark(text_buffer.get_insert())
iter_end = iter_start.copy()
last_line_situation = False
iter_end.forward_char()
missing_leading_newline = False
destination_iter = iter_start.copy()
if not destination_iter.backward_char(): return
if not destination_iter.backward_char(): missing_leading_newline = True
else:
while destination_iter.get_char() != cons.CHAR_NEWLINE:
if not destination_iter.backward_char():
missing_leading_newline = True
break
if not missing_leading_newline: destination_iter.forward_char()
destination_offset = destination_iter.get_offset()
start_offset = iter_start.get_offset()
end_offset = iter_end.get_offset()
#print "iter_start %s %s '%s'" % (start_offset, ord(iter_start.get_char()), iter_start.get_char())
#print "iter_end %s %s '%s'" % (end_offset, ord(iter_end.get_char()), iter_end.get_char())
#print "destination_iter %s %s '%s'" % (destination_offset, ord(destination_iter.get_char()), destination_iter.get_char())
text_to_move = text_buffer.get_text(iter_start, iter_end)
diff_offsets = end_offset - start_offset
if from_codebox or self.syntax_highlighting != cons.RICH_TEXT_ID:
text_buffer.delete(iter_start, iter_end)
destination_iter = text_buffer.get_iter_at_offset(destination_offset)
if not text_to_move or text_to_move[-1] != cons.CHAR_NEWLINE:
diff_offsets += 1
text_to_move += cons.CHAR_NEWLINE
text_buffer.move_mark(text_buffer.get_insert(), destination_iter)
text_buffer.insert(destination_iter, text_to_move)
self.set_selection_at_offset_n_delta(destination_offset, diff_offsets-1, text_buffer=text_buffer)
else:
rich_text = self.clipboard_handler.rich_text_get_from_text_buffer_selection(text_buffer, iter_start,
iter_end, exclude_iter_sel_end=True)
text_buffer.delete(iter_start, iter_end)
destination_iter = text_buffer.get_iter_at_offset(destination_offset)
if destination_offset > 0:
# clear the newline from any tag
clr_start_iter = text_buffer.get_iter_at_offset(destination_offset-1)
text_buffer.remove_all_tags(clr_start_iter, destination_iter)
if not text_to_move or text_to_move[-1] != cons.CHAR_NEWLINE:
diff_offsets += 1
append_newline = True
else: append_newline = False
text_buffer.move_mark(text_buffer.get_insert(), destination_iter)
# trick of space to prevent subsequent text to take pasted text tag(s)
text_buffer.insert_at_cursor(cons.CHAR_SPACE)
destination_iter = text_buffer.get_iter_at_offset(destination_offset)
text_buffer.move_mark(text_buffer.get_insert(), destination_iter)
# write moved line
self.clipboard_handler.from_xml_string_to_buffer(rich_text)
if append_newline: text_buffer.insert_at_cursor(cons.CHAR_NEWLINE)
# clear space trick
cursor_iter = text_buffer.get_iter_at_mark(text_buffer.get_insert())
text_buffer.delete(cursor_iter, text_buffer.get_iter_at_offset(cursor_iter.get_offset()+1))
# selection
self.set_selection_at_offset_n_delta(destination_offset, diff_offsets-1, text_buffer=text_buffer)
self.state_machine.update_state()
def text_row_down(self, *args):
"""Moves Down the Current Row/Selected Rows"""
text_view, text_buffer, syntax_highl, from_codebox = self.get_text_view_n_buffer_codebox_proof()
if not text_buffer: return
if not self.is_curr_node_not_read_only_or_error(): return
iter_start, iter_end = self.lists_handler.get_paragraph_iters(text_buffer=text_buffer)
if iter_start == None:
iter_start = text_buffer.get_iter_at_mark(text_buffer.get_insert())
iter_end = iter_start.copy()
if not iter_end.forward_char(): return
missing_leading_newline = False
destination_iter = iter_end.copy()
while destination_iter.get_char() != cons.CHAR_NEWLINE:
if not destination_iter.forward_char():
missing_leading_newline = True
break
destination_iter.forward_char()
destination_offset = destination_iter.get_offset()
start_offset = iter_start.get_offset()
end_offset = iter_end.get_offset()
#print "iter_start %s %s '%s'" % (start_offset, ord(iter_start.get_char()), iter_start.get_char())
#print "iter_end %s %s '%s'" % (end_offset, ord(iter_end.get_char()), iter_end.get_char())
#print "destination_iter %s %s '%s'" % (destination_offset, ord(destination_iter.get_char()), destination_iter.get_char())
text_to_move = text_buffer.get_text(iter_start, iter_end)
diff_offsets = end_offset - start_offset
if from_codebox or self.syntax_highlighting != cons.RICH_TEXT_ID:
text_buffer.delete(iter_start, iter_end)
destination_offset -= diff_offsets
destination_iter = text_buffer.get_iter_at_offset(destination_offset)
if not text_to_move or text_to_move[-1] != cons.CHAR_NEWLINE:
diff_offsets += 1
text_to_move += cons.CHAR_NEWLINE
if missing_leading_newline:
diff_offsets += 1
text_to_move = cons.CHAR_NEWLINE + text_to_move
text_buffer.insert(destination_iter, text_to_move)
if not missing_leading_newline:
self.set_selection_at_offset_n_delta(destination_offset, diff_offsets-1, text_buffer=text_buffer)
else:
self.set_selection_at_offset_n_delta(destination_offset+1, diff_offsets-2, text_buffer=text_buffer)
else:
rich_text = self.clipboard_handler.rich_text_get_from_text_buffer_selection(text_buffer, iter_start, iter_end, exclude_iter_sel_end=True)
text_buffer.delete(iter_start, iter_end)
destination_offset -= diff_offsets
destination_iter = text_buffer.get_iter_at_offset(destination_offset)
if destination_offset > 0:
# clear the newline from any tag
clr_start_iter = text_buffer.get_iter_at_offset(destination_offset-1)
text_buffer.remove_all_tags(clr_start_iter, destination_iter)
if not text_to_move or text_to_move[-1] != cons.CHAR_NEWLINE:
diff_offsets += 1
append_newline = True
else: append_newline = False
text_buffer.move_mark(text_buffer.get_insert(), destination_iter)
if missing_leading_newline:
diff_offsets += 1
text_buffer.insert_at_cursor(cons.CHAR_NEWLINE)
# trick of space to prevent subsequent text to take pasted text tag(s)
text_buffer.insert_at_cursor(cons.CHAR_SPACE)
destination_iter = text_buffer.get_iter_at_offset(destination_offset)
text_buffer.move_mark(text_buffer.get_insert(), destination_iter)
# write moved line
self.clipboard_handler.from_xml_string_to_buffer(rich_text)
if append_newline: text_buffer.insert_at_cursor(cons.CHAR_NEWLINE)
# clear space trick
cursor_iter = text_buffer.get_iter_at_mark(text_buffer.get_insert())
text_buffer.delete(cursor_iter, text_buffer.get_iter_at_offset(cursor_iter.get_offset()+1))
# selection
if not missing_leading_newline:
self.set_selection_at_offset_n_delta(destination_offset, diff_offsets-1, text_buffer=text_buffer)
else:
self.set_selection_at_offset_n_delta(destination_offset+1, diff_offsets-2, text_buffer=text_buffer)
self.state_machine.update_state()
def get_text_view_n_buffer_codebox_proof(self):
"""Returns Tuple TextView, TextBuffer, Boolean checking if CodeBox in Use"""
anchor = self.codeboxes_handler.codebox_in_use_get_anchor()
if anchor is not None:
text_view = anchor.sourceview
text_buffer = text_view.get_buffer()
syntax_highl = anchor.syntax_highlighting
from_codebox = True
else:
text_buffer = self.curr_buffer
text_view = self.sourceview
syntax_highl = self.syntax_highlighting
from_codebox = False
return text_view, text_buffer, syntax_highl, from_codebox
def text_row_delete(self, *args):
"""Deletes the Whole Row"""
text_view, text_buffer, syntax_highl, from_codebox = self.get_text_view_n_buffer_codebox_proof()
if not text_buffer: return
if not self.is_curr_node_not_read_only_or_error(): return
iter_start, iter_end = self.lists_handler.get_paragraph_iters(text_buffer=text_buffer)
if iter_start == None:
iter_start = text_buffer.get_iter_at_mark(text_buffer.get_insert())
iter_end = iter_start.copy()
if not iter_end.forward_char() and not iter_start.backward_char(): return
text_buffer.delete(iter_start, iter_end)
self.state_machine.update_state()
def text_row_cut(self, *args):
"""Cut a Whole Row"""
text_view, text_buffer, syntax_highl, from_codebox = self.get_text_view_n_buffer_codebox_proof()
if not text_buffer: return
if not self.is_curr_node_not_read_only_or_error(): return
iter_start, iter_end = self.lists_handler.get_paragraph_iters(text_buffer=text_buffer)
if iter_start == None:
iter_start = text_buffer.get_iter_at_mark(text_buffer.get_insert())
iter_end = iter_start.copy()
if not iter_end.forward_char() and not iter_start.backward_char(): return
text_buffer.select_range(iter_start, iter_end)
text_view.emit("cut-clipboard")
def text_row_copy(self, *args):
"""Copy a Whole Row"""
text_view, text_buffer, syntax_highl, from_codebox = self.get_text_view_n_buffer_codebox_proof()
if not text_buffer: return
iter_start, iter_end = self.lists_handler.get_paragraph_iters(text_buffer=text_buffer)
if iter_start == None:
iter_start = text_buffer.get_iter_at_mark(text_buffer.get_insert())
iter_end = iter_start.copy()
if not iter_end.forward_char() and not iter_start.backward_char(): return
text_buffer.select_range(iter_start, iter_end)
text_view.emit("copy-clipboard")
def on_hscrollbar_text_value_changed(self, hscrollbar):
"""Catches Text Horizontal Scrollbar Movements"""
curr_val = hscrollbar.get_value()
#print curr_val
if curr_val == 7:
hscrollbar.set_value(0)
def on_key_press_window(self, widget, event):
"""Catches Window key presses"""
if not self.curr_tree_iter: return
keyname = gtk.gdk.keyval_name(event.keyval)
if event.state & gtk.gdk.MOD1_MASK:
if keyname == cons.STR_KEY_LEFT:
self.go_back()
return True
elif keyname == cons.STR_KEY_RIGHT:
self.go_forward()
return True
elif (event.state & gtk.gdk.CONTROL_MASK):
if keyname == cons.STR_KEY_TAB:
self.toggle_tree_text()
return True
elif keyname in ["plus", "KP_Add"]:
if self.treeview.is_focus(): self.zoom_tree(True)
else: self.zoom_text(True)
return True
elif keyname in ["minus", "KP_Subtract"]:
if self.treeview.is_focus(): self.zoom_tree(False)
else: self.zoom_text(False)
return True
return False
def on_key_press_cherrytree(self, widget, event):
"""Catches Tree key presses"""
if not self.curr_tree_iter: return False
keyname = gtk.gdk.keyval_name(event.keyval)
if event.state & gtk.gdk.SHIFT_MASK:
if event.state & gtk.gdk.CONTROL_MASK:
if keyname == cons.STR_KEY_RIGHT:
self.node_change_father()
return True
elif keyname == cons.STR_KEY_UP:
self.node_up()
return True
elif keyname == cons.STR_KEY_DOWN:
self.node_down()
return True
elif keyname == cons.STR_KEY_LEFT:
self.node_left()
return True
elif keyname == cons.STR_KEY_RIGHT:
self.node_right()
return True
elif event.state & gtk.gdk.MOD1_MASK:
pass
elif event.state & gtk.gdk.CONTROL_MASK:
if keyname == cons.STR_KEY_UP:
prev_iter = self.get_tree_iter_prev_sibling(self.treestore, self.curr_tree_iter)
if prev_iter:
while prev_iter:
move_iter = prev_iter
prev_iter = self.get_tree_iter_prev_sibling(self.treestore, prev_iter)
self.treeview_safe_set_cursor(move_iter)
return True
elif keyname == cons.STR_KEY_DOWN:
next_iter = self.treestore.iter_next(self.curr_tree_iter)
if next_iter:
while next_iter:
move_iter = next_iter
next_iter = self.treestore.iter_next(next_iter)
self.treeview_safe_set_cursor(move_iter)
return True
elif keyname == cons.STR_KEY_LEFT:
father_iter = self.treestore.iter_parent(self.curr_tree_iter)
if father_iter:
while father_iter:
move_iter = father_iter
father_iter = self.treestore.iter_parent(father_iter)
self.treeview_safe_set_cursor(move_iter)
return True
elif keyname == cons.STR_KEY_RIGHT:
child_iter = self.treestore.iter_children(self.curr_tree_iter)
if child_iter:
while child_iter:
move_iter = child_iter
child_iter = self.treestore.iter_children(child_iter)
self.treeview_safe_set_cursor(move_iter)
return True
elif keyname in ["plus", "KP_Add"]:
self.zoom_tree(True)
return True
elif keyname in ["minus", "KP_Subtract"]:
self.zoom_tree(False)
return True
else:
if keyname == cons.STR_KEY_LEFT:
if self.treeview.row_expanded(self.treestore.get_path(self.curr_tree_iter)):
self.treeview.collapse_row(self.treestore.get_path(self.curr_tree_iter))
elif self.treestore.iter_parent(self.curr_tree_iter) is not None:
self.treeview_safe_set_cursor(self.treestore.iter_parent(self.curr_tree_iter))
return True
elif keyname == cons.STR_KEY_RIGHT:
self.treeview.expand_row(self.treestore.get_path(self.curr_tree_iter), open_all=False)
return True
elif keyname == cons.STR_KEY_RETURN:
self.toggle_tree_node_expanded_collapsed()
return True
elif keyname == cons.STR_KEY_DELETE:
self.node_delete()
return True
elif keyname == cons.STR_KEY_MENU:
self.node_menu_tree.popup(None, None, None, 0, event.time)
return True
elif keyname == cons.STR_KEY_TAB:
self.toggle_tree_text()
return True
return False
def zoom_tree(self, is_increase):
"""Increase or Decrease Tree Font"""
font_vec = self.tree_font.split(cons.CHAR_SPACE)
font_num = int(font_vec[-1])
if is_increase is True:
font_vec[-1] = str(font_num+1)
else:
if font_num <= 6: return # do not go under 6
font_vec[-1] = str(font_num-1)
self.tree_font = cons.CHAR_SPACE.join(font_vec)
self.set_treeview_font()
def zoom_text(self, is_increase):
"""Increase or Decrease Text Font"""
text_view, text_buffer, syntax_highl, from_codebox = self.get_text_view_n_buffer_codebox_proof()
if not text_buffer: return
from_table = False
if syntax_highl == cons.RICH_TEXT_ID:
anchor_table = self.tables_handler.table_in_use_get_anchor()
if not (anchor_table is None):
from_table = True
syntax_highl = cons.PLAIN_TEXT_ID
if syntax_highl == cons.RICH_TEXT_ID:
font_vec = self.rt_font.split(cons.CHAR_SPACE)
elif syntax_highl == cons.PLAIN_TEXT_ID:
font_vec = self.pt_font.split(cons.CHAR_SPACE)
else:
font_vec = self.code_font.split(cons.CHAR_SPACE)
font_num = int(font_vec[-1])
if is_increase is True:
font_vec[-1] = str(font_num+1)
else:
if font_num <= 6: return # do not go under 6
font_vec[-1] = str(font_num-1)
if syntax_highl == cons.RICH_TEXT_ID:
self.rt_font = cons.CHAR_SPACE.join(font_vec)
target_font = self.rt_font
elif syntax_highl == cons.PLAIN_TEXT_ID:
self.pt_font = cons.CHAR_SPACE.join(font_vec)
target_font = self.pt_font
else:
self.code_font = cons.CHAR_SPACE.join(font_vec)
target_font = self.code_font
if from_codebox is True:
support.rich_text_node_modify_codeboxes_font(self.curr_buffer.get_start_iter(), self)
elif from_table is True:
support.rich_text_node_modify_tables_font(self.curr_buffer.get_start_iter(), self)
else:
self.sourceview.modify_font(pango.FontDescription(target_font))
def fullscreen_toggle(self, *args):
"""Toggle Fullscreen State"""
if (self.window.window.get_state() & gtk.gdk.WINDOW_STATE_FULLSCREEN):
self.window.window.unfullscreen()
else:
self.window.window.fullscreen()
def toggle_tree_node_expanded_collapsed(self, *args):
"""Toggle Selected Tree Node Expanded/Collapsed"""
if not self.is_there_selected_node_or_error(): return
if self.treeview.row_expanded(self.treestore.get_path(self.curr_tree_iter)):
self.treeview.collapse_row(self.treestore.get_path(self.curr_tree_iter))
else:
self.treeview.expand_row(self.treestore.get_path(self.curr_tree_iter), open_all=False)
def toggle_ena_dis_spellcheck(self, *args):
"""Toggle Enable/Disable Spell Check"""
self.enable_spell_check = not self.enable_spell_check
if self.enable_spell_check: self.spell_check_set_on()
else: self.spell_check_set_off(True)
def toggle_tree_text(self, *args):
"""Toggle Focus Between Tree and Text"""
if self.treeview.is_focus():
self.sourceview.grab_focus()
else: self.treeview.grab_focus()
def on_drag_motion_cherrytree(self, widget, drag_context, x, y, timestamp):
"""Cherry Tree drag motion"""
if y < cons.TREE_DRAG_EDGE_PROX or y > (widget.get_allocation().height - cons.TREE_DRAG_EDGE_PROX):
delta = -cons.TREE_DRAG_EDGE_SCROLL if y < cons.TREE_DRAG_EDGE_PROX else cons.TREE_DRAG_EDGE_SCROLL
vscroll_obj = self.scrolledwindow_tree.get_vscrollbar()
vscroll_obj.set_value(vscroll_obj.get_value() + delta)
if x < cons.TREE_DRAG_EDGE_PROX or x > (widget.get_allocation().width - cons.TREE_DRAG_EDGE_PROX):
delta = -cons.TREE_DRAG_EDGE_SCROLL if x < cons.TREE_DRAG_EDGE_PROX else cons.TREE_DRAG_EDGE_SCROLL
hscroll_obj = self.scrolledwindow_tree.get_hscrollbar()
hscroll_obj.set_value(hscroll_obj.get_value() + delta)
drop_info = self.treeview.get_dest_row_at_pos(x, y)
if drop_info:
drop_path, drop_pos = drop_info
widget.set_drag_dest_row(drop_path, drop_pos)
return True
def on_drag_data_recv_cherrytree(self, widget, drag_context, x, y, selection_data, info, timestamp):
"""Cherry Tree drag data received"""
drop_info = self.treeview.get_dest_row_at_pos(x, y)
if drop_info:
drop_path, drop_pos = drop_info
if not drop_pos: drop_pos = gtk.TREE_VIEW_DROP_BEFORE
drop_iter = self.treestore.get_iter(drop_path)
# check for bad drop
if not self.drag_iter: return False
drag_node_id = self.treestore[self.drag_iter][3]
if self.treestore[drop_iter][3] == drag_node_id:
print "drag node and drop node are the same"
return False
move_towards_top_iter = self.treestore.iter_parent(drop_iter)
while move_towards_top_iter:
if self.treestore[move_towards_top_iter][3] == drag_node_id:
support.dialog_error(_("The new parent can't be one of his children!"), self.window)
return False
move_towards_top_iter = self.treestore.iter_parent(move_towards_top_iter)
if drop_pos == gtk.TREE_VIEW_DROP_BEFORE:
prev_iter = self.get_tree_iter_prev_sibling(self.treestore, drop_iter)
# note: prev_iter could be None, use drop_iter to retrieve the parent
self.node_move_after(self.drag_iter, self.treestore.iter_parent(drop_iter), prev_iter, True)
elif drop_pos == gtk.TREE_VIEW_DROP_AFTER:
self.node_move_after(self.drag_iter, self.treestore.iter_parent(drop_iter), drop_iter)
else: # drop in
self.node_move_after(self.drag_iter, drop_iter)
if self.nodes_icons == "c": self.treeview_refresh(change_icon=True)
return True
def on_drag_data_get_cherrytree(self, widget, drag_context, selection_data, info, timestamp):
"""Cherry Tree drag data received"""
tree_model, tree_iter = self.treeviewselection.get_selected()
self.drag_iter = tree_iter
selection_data.set("UTF8_STRING", 8, "fake") # without this, the drag_data_recv will not be called
return True
def nodes_add_from_cherrytree_file(self, action):
"""Appends Nodes at the Bottom of the Current Ones, Importing from a CherryTree File"""
filepath = support.dialog_file_select(filter_pattern=["*.ct*"],
filter_name=_("CherryTree Document"),
curr_folder=self.pick_dir_import,
parent=self.window)
if not filepath: return
self.pick_dir_import = os.path.dirname(filepath)
document_loaded_ok = False
if filepath[-1] in ["d", "z"]:
# xml
cherrytree_string = self.file_get_cherrytree_data(filepath, False)
if cherrytree_string: document_loaded_ok = True
elif cherrytree_string == None: return # no error exit
elif filepath[-1] in ["b", "x"]:
# db
source_db = self.file_get_cherrytree_data(filepath, False)
if source_db: document_loaded_ok = True
elif source_db == None: return # no error exit
if document_loaded_ok:
try:
if filepath[-1] in ["d", "z"]:
self.nodes_add_from_cherrytree_data(cherrytree_string)
else: self.nodes_add_from_cherrytree_data("", source_db)
document_loaded_ok = True
except: document_loaded_ok = False
if not document_loaded_ok:
support.dialog_error(_('"%s" is Not a CherryTree Document') % filepath, self.window)
return
def nodes_add_from_notecase_file(self, action):
"""Add Nodes Parsing a NoteCase File"""
filepath = support.dialog_file_select(filter_pattern=["*.ncd"],
filter_name=_("NoteCase Document"),
curr_folder=self.pick_dir_import,
parent=self.window)
if not filepath: return
self.pick_dir_import = os.path.dirname(filepath)
try:
file_descriptor = open(filepath, 'r')
notecase_string = file_descriptor.read()
file_descriptor.close()
except:
support.dialog_error("Error importing the file %s" % filepath, self.window)
raise
return
notecase = imports.NotecaseHandler(self)
cherrytree_string = notecase.get_cherrytree_xml(notecase_string)
self.nodes_add_from_cherrytree_data(cherrytree_string)
def nodes_add_from_tuxcards_file(self, action):
"""Add Nodes Parsing a TuxCards File"""
filepath = support.dialog_file_select(curr_folder=self.pick_dir_import, parent=self.window)
if not filepath: return
self.pick_dir_import = os.path.dirname(filepath)
try:
file_descriptor = open(filepath, 'r')
tuxcards_string = re.sub(cons.BAD_CHARS, "", file_descriptor.read())
file_descriptor.close()
except:
support.dialog_error("Error importing the file %s" % filepath, self.window)
raise
return
tuxcards = imports.TuxCardsHandler(self)
cherrytree_string = tuxcards.get_cherrytree_xml(tuxcards_string)
self.nodes_add_from_cherrytree_data(cherrytree_string)
def nodes_add_from_keepnote_folder(self, action):
"""Add Nodes Parsing a KeepNote Folder"""
folderpath = support.dialog_folder_select(curr_folder=self.pick_dir_import, parent=self.window)
if not folderpath: return
self.pick_dir_import = os.path.dirname(folderpath)
keepnote = imports.KeepnoteHandler(self, folderpath)
cherrytree_string = keepnote.get_cherrytree_xml()
self.nodes_add_from_cherrytree_data(cherrytree_string)
def nodes_add_from_zim_folder(self, action):
"""Add Nodes Parsing a Zim Folder"""
start_folder = os.path.join(os.path.expanduser('~'), "Notebooks", "Notes")
folderpath = support.dialog_folder_select(curr_folder=start_folder, parent=self.window)
if not folderpath: return
zim = imports.ZimHandler(self, folderpath)
cherrytree_string = zim.get_cherrytree_xml()
self.nodes_add_from_cherrytree_data(cherrytree_string)
zim.set_links_to_nodes(self)
def nodes_add_from_gnote_folder(self, action):
"""Add Nodes Parsing a Gnote Folder"""
start_folder = os.path.join(os.path.expanduser('~'), ".local", "share", "gnote")
folderpath = support.dialog_folder_select(curr_folder=start_folder, parent=self.window)
if not folderpath: return
gnote = imports.TomboyHandler(self, folderpath)
cherrytree_string = gnote.get_cherrytree_xml()
self.nodes_add_from_cherrytree_data(cherrytree_string)
gnote.set_links_to_nodes(self)
def nodes_add_from_rednotebook_folder(self, action):
"""Add Nodes Parsing a RedNotebook Folder"""
start_folder = os.path.join(os.path.expanduser('~'), ".rednotebook", "data")
folderpath = support.dialog_folder_select(curr_folder=start_folder, parent=self.window)
if not folderpath: return
rednotebook = imports.RedNotebookHandler(self, folderpath)
cherrytree_string = rednotebook.get_cherrytree_xml()
self.nodes_add_from_cherrytree_data(cherrytree_string)
def nodes_add_from_tomboy_folder(self, action):
"""Add Nodes Parsing a Tomboy Folder"""
start_folder = os.path.join(os.path.expanduser('~'), ".local", "share", "tomboy")
folderpath = support.dialog_folder_select(curr_folder=start_folder, parent=self.window)
if not folderpath: return
tomboy = imports.TomboyHandler(self, folderpath)
cherrytree_string = tomboy.get_cherrytree_xml()
self.nodes_add_from_cherrytree_data(cherrytree_string)
tomboy.set_links_to_nodes(self)
def nodes_add_from_basket_folder(self, action):
"""Add Nodes Parsing a Basket Folder"""
start_folder = os.path.join(os.path.expanduser('~'), ".kde", "share", "apps", "basket", "baskets")
folderpath = support.dialog_folder_select(curr_folder=start_folder, parent=self.window)
if not folderpath: return
basket = imports.BasketHandler(self, folderpath)
if basket.check_basket_structure():
cherrytree_string = basket.get_cherrytree_xml()
self.nodes_add_from_cherrytree_data(cherrytree_string)
else: support.dialog_error("%s is not a basket folder" % folderpath, self.window)
def nodes_add_from_epim_html_file(self, action):
"""Add Nodes from Selected EPIM HTML File"""
filepath = support.dialog_file_select(filter_pattern=["*.html", "*.HTML", "*.htm", "*.HTM"] if cons.IS_WIN_OS else [],
filter_mime=["text/html"] if not cons.IS_WIN_OS else [],
filter_name=_("EPIM HTML Document"),
curr_folder=self.pick_dir_import, parent=self.window)
if not filepath: return
self.pick_dir_import = os.path.dirname(filepath)
html_folder = imports.epim_html_file_to_hier_files(filepath)
if not html_folder: return
html = imports.HTMLHandler(self)
cherrytree_string = html.get_cherrytree_xml(folderpath=html_folder)
self.nodes_add_from_cherrytree_data(cherrytree_string)
def nodes_add_from_html_file(self, action):
"""Add Nodes from Selected HTML File"""
filepath = support.dialog_file_select(filter_pattern=["*.html", "*.HTML", "*.htm", "*.HTM"] if cons.IS_WIN_OS else [],
filter_mime=["text/html"] if not cons.IS_WIN_OS else [],
filter_name=_("HTML Document"),
curr_folder=self.pick_dir_import, parent=self.window)
if not filepath: return
self.pick_dir_import = os.path.dirname(filepath)
html = imports.HTMLHandler(self)