-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpyBar.py
3205 lines (2889 loc) · 99.5 KB
/
pyBar.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright 2007 Philippe LAWRENCE
#
# This file is part of pyBar.
# pyBar 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.
#
# pyBar 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 pyBar; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import sys
# revoir sys.platform dans Const !!!!
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gio, Gtk, Gdk, Pango, GObject, GdkPixbuf, GLib
print(Gtk.MAJOR_VERSION, Gtk.MINOR_VERSION, Gtk.MICRO_VERSION)
import cairo
#import gio # debug py2exe windows remettre?
import classEditor
import classDrawing
import classRdm
import classLigneInflu
import classDialog
import Const
import classProfilManager
import classPrefs
import threading
import copy
import os
#import pickle
import function
import file_tools
#from time import sleep
import xml.etree.ElementTree as ET
#import signal
#signal.signal(signal.SIGINT, signal.SIG_DFL)
# -------------
file_tools.set_user_dir()
if Const.SYS == "win32":
path = os.path.join(Const.PATH, "stdout.log")
sys.stdout = open(path, "w")
path = os.path.join(Const.PATH, "stderr.log")
sys.stderr = open(path, "w")
#GObject.threads_init()
__version__ = Const.VERSION
__author__ = Const.AUTHOR
__date__ = "2014-06-01"
__file__ = Const.SOFT # redéfini pour py2exe en attendant mieux
print("%s%s Copyright (C) 2007 %s\nThis program comes with ABSOLUTELY NO WARRANTY\nThis is free software, and you are welcome to redistribute it under certain conditions." % (Const.SOFT, __version__, __author__))
screen = Gdk.Screen.get_default()
css_provider = Gtk.CssProvider()
css_provider.load_from_path('gtk-widgets.css')
context = Gtk.StyleContext()
context.add_provider_for_screen(screen, css_provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
class CombiButton(Gtk.CheckButton):
"""Boutons à cocher des combinaisons"""
def __init__(self, label):
Gtk.CheckButton.__init__(self, label=label)
#self.n_type = n_type
def About():
dialog = Gtk.AboutDialog()
dialog.set_icon_from_file("glade/logo.png")
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size("glade/logo.png", 25, 25)
dialog.set_logo(pixbuf)
dialog.set_program_name(Const.SOFT)
dialog.set_version(Const.VERSION)
dialog.set_authors([Const.AUTHOR])
dialog.set_website(Const.SITE_URL)
dialog.set_comments("%s est un logiciel libre de calcul de structures planes, basé sur la méthode des déplacements, écrit en Python et GTK\n%s" % (Const.SOFT, Const.CONTACT))
dialog.set_license("Vous pouvez modifier et redistribuer ce programme\nsous les conditions énoncées\npar la licence GNU GPL (version 2 ou ultérieure).\nUne copie de la licence GPL\nest dans le fichier « COPYING » fourni avec %s.\nAucune garantie n'est fournie pour l'utilisation de ce programme." % Const.SOFT)
result = dialog.run()
dialog.destroy()
class CombiBox(Gtk.VBox):
# revoir main_win, study
def __init__(self, **kwargs):
Gtk.VBox.__init__(self, **kwargs)
self.set_name("combi")
def fill_box(self, study, main_win):
self.handler_list = []
rdm = study.rdm
#try:/
# status = rdm.status
#except AttributeError: # for EmptyRdm
# status = -1
#if status == -1:
# return
Cases = rdm.Cases
n_cases = len(Cases)
try:
ErrorCases = rdm.char_error
except AttributeError:
ErrorCases = []
CombiCoef = rdm.CombiCoef
combis = function.sortedDictKeys(CombiCoef)
n_combi = len(combis)
# création de la liste des cas de charge
label = Gtk.Label(label="Cas de charge:")
#label.set_alignment(0.2, 0.7)
self.pack_start(label, False, False, 0)
for i, val in enumerate(Cases):
button = CombiButton(val)
id = button.connect("clicked", main_win.event_combi_button, i)
self.handler_list.append(id)
button.set_name(str(i))
if val in ErrorCases:
button.set_sensitive(False)
self.pack_start(button, False, False, 0)
# création de la liste des combinaisons
if not n_combi == 0:
label = Gtk.Label(label="Combinaisons:")
#label.set_alignment(0.2, 0.7)
self.pack_start(label, False, False, 0)
for i, val in enumerate(combis):
button = CombiButton(val)
n = i + n_cases
# numéro pour combinaison négatif à partir de -1
id = button.connect("clicked", main_win.event_combi_button, n)
self.handler_list.append(id)
button.set_name(str(n))
self.pack_start(button, False, False, 0)
self.show_all()
#####################################################################
#
# CLASSE PRINCIPALE
#
#####################################################################
class MainWindow(object):
def __init__(self):
# initialisation de la page d'accueil
builder = self.builder = Gtk.Builder()
builder.add_from_file("glade/main.glade")
# XXX enlever le mapping comme dans Editor
builder.connect_signals(self)
self.window = builder.get_object("window1")
self.main_box = builder.get_object("main_box")
self._ini_first_page()
self.window.show() # après le resize
self._handler_id = {}
self._tabs = []
self.studies = {}
self.message = classDialog.Message()
self.is_press = False # attribut pour le bouton "Clic Gauche"
self.key_press = False # attribut pour la clavier "Control_L"
# XXX enlever dans main.glade
def on_state_event(self, widget, event):
"""Evènement de type passage en plein écran ou retour"""
#print event.type
return
if event.changed_mask & Gdk.WindowState.ICONIFIED:
if event.new_window_state & Gdk.WindowState.ICONIFIED:
print('Window was minimized!')
else:
print('Window was unminimized!')
def on_w1_configure(self, widget, event):
"""Gère les évènements correspondant au redimensionnement de la fenetre"""
#print("Main::_configure_event")
pass
def on_w1_destroy(self, widget, event=None):
"""Closing main window - Save user preferences"""
self.new_version = False
menu_button = self.builder.get_object("menu_cas")
display_combi = menu_button.get_active() == True and 'on' or 'off'
w, h = self.window.get_size()
self.UP.save_w1_config(w, h, display_combi, self.options)
if hasattr(self, "editor"):
changes = self.editor.get_modified_studies()
must_save = self._get_record_id(changes)
if must_save is None:
# must return True to prevent window closing
return True
ed_data = self.editor.data_editors
for id in must_save:
self._set_name(id)
ed_study = ed_data[id]
if not ed_study.path is None:
self.editor.save_study(ed_study)
self.UP.save_w2_config(self.editor._w, self.editor._h)
# sauvegarde des préférences des études
studies = self.studies
for study in studies.values():
self.save_drawing_prefs(study)
Gtk.main_quit()
def expose_first_page(self, widget, cr):
"""Méthode expose-event pour le drawingarea du lancement"""
#print("expose_first_page", cr)
cr.set_source_surface(self.surface, 0, 0)
cr.paint()
#w_alloc = widget.get_allocated_width()
#h_alloc = widget.get_allocated_height()
#widget.move(self.tools, 200, 500)
#self.draw_first_tools(widget, x+20, max(h_alloc-70, 0))
def configure_first_page(self, widget, event):
"""Méthode configure-event pour le drawingarea du lancement"""
#print("configure_first_page")
w_alloc = widget.get_allocated_width()
h_alloc = widget.get_allocated_height()
self.surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w_alloc, h_alloc)
cr = cairo.Context(self.surface)
cr.save()
cr.set_source_rgb(1.0, 1.0, 1.0)
cr.rectangle(0, 0, w_alloc, h_alloc)
cr.fill()
cr.restore()
img = cairo.ImageSurface.create_from_png("glade/home.png")
w, h = img.get_width(), img.get_height()
x, y = (w_alloc-w)/2, (h_alloc-h)/2
cr.set_source_surface(img, x, y)
cr.paint()
cr.save()
cr.set_source_rgb(0.0, 0.0, 1.0)
cr.set_font_size(60)
cr.move_to(x+280, y+180)
cr.show_text(Const.VERSION)
cr.stroke()
cr.restore()
self.draw_first_tools(widget, int(x+20), max(h_alloc-70, 0))
def draw_first_tools(self, layout, x, y):
#print("draw_first_tools", x, y)
if hasattr(self, 'tools'):
layout.move(self.tools, x, y)
return
hbox = Gtk.HBox(homogeneous=False, spacing=10)
b = Gtk.Button.new_from_icon_name('document-open', Gtk.IconSize.DIALOG)
b.set_relief(Gtk.ReliefStyle.NONE)
b.set_tooltip_text("Ouvrir une étude existante")
b.connect('clicked', self.on_open_file)
hbox.pack_start(b, False, False, 0)
b = Gtk.Button.new_from_icon_name('document-new', Gtk.IconSize.DIALOG)
b.set_relief(Gtk.ReliefStyle.NONE)
b.set_tooltip_text("Ouvrir une nouvelle étude")
b.connect('clicked', self.on_new_file)
hbox.pack_start(b, False, False, 0)
layout.put(hbox, x, y)
hbox.show_all()
self.tools = hbox
def _ini_first_page(self):
"""Dessine la page de lancement de l'application
Read size User preferences"""
self.new_version = None
#self._set_user_dir()
self.UP = classPrefs.UserPrefs()
menu_button = self.builder.get_object("menu_cas")
tag = self.UP.get_w1_box()
menu_button.set_active(tag)
menu_button.connect('activate', self._manage_combi_window)
sizes = self.UP.get_w1_size()
if sizes is None:
height = Gdk.Screen.height()
width = Gdk.Screen.width()
self.window.resize(int(0.6*width), int(0.8*height))
else:
w, h = sizes
self.window.resize(w, h)
layout = Gtk.Layout()
layout.connect("size-allocate", self.configure_first_page)
layout.connect("draw", self.expose_first_page)
self.main_box.add(layout)
self.draw_first_tools(layout, 0, 0)
layout.show()
# new version search
opt = self.UP.get_version()
if opt == 0:
try:
GLib.timeout_add(1000, self._get_info_version, opt) # destroy if callback return False
except:
pass
else:
self.UP.save_version(opt-1)
# options d'affichage (à déplacer?)
self.options = self.UP.get_w1_options()
# -----------------------------------------------------------
#
# Méthodes relatives au notebook des drawings
#
# -----------------------------------------------------------
def _ini_application(self):
"""drawings notebook initilisation - button setup
return drawing_book"""
# suppression image accueil
self.main_box.remove(self.main_box.get_children()[0])
self.surface.finish()
del(self.surface)
del(self.tools)
# drawings notebook ini
book = Gtk.Notebook()
book.set_scrollable(True)
#book.set_show_tabs(False)
b = Gtk.Button.new_from_icon_name('list-add', Gtk.IconSize.MENU)
b.set_relief(Gtk.ReliefStyle.NONE)
b.connect('clicked', self.on_new_tab)
page = Gtk.HBox()
book.append_page(page, b)
self.book = book
self._handler_id['book'] = book.connect("switch_page", self.on_switch_page)
# ligne pour les messages
hbox = Gtk.HBox()
hbox.set_size_request(-1, 40)
hbox.set_property('border_width', 4)
self.message.ini_message(hbox) # évite pb avec singleton
self.main_box.pack_start(book, True, True, 0)
self.main_box.pack_start(hbox, False, True, 0)
self.main_box.show_all()
return book
def _ini_drawing_page(self, position):
"""Initialisation d'un onglet de dessin"""
#print "Main::_ini_drawing_page"
book = self.main_box.get_children()[0]
# initialisation
if not isinstance(book, Gtk.Notebook):
book = self._ini_application()
self._set_buttons_ini()
book.disconnect(self._handler_id["book"])
self._add_book_page(book, position)
tab = self.active_tab
# scrolling arrows for notebook
n_pages = book.get_n_pages()
#if n_pages >= 2:
# book.set_show_tabs(True)
self._handler_id['book'] = book.connect("switch_page", self.on_switch_page)
layout = tab.layout
layout.set_can_focus(True)
layout.grab_focus()
layout.connect("size-allocate", tab.configure_event)
# modif
layout.connect("draw", tab.draw_event)
tab.handler_layout = layout.connect("motion-notify-event", self.motion_notify_event)
layout.connect("leave-notify-event", self.leave_notify_event)
layout.connect("button-press-event", self.button_press_event)
layout.connect("button-release-event", self._button_release_event)
layout.connect("key-press-event", self._key_press_event)
layout.connect("key-release-event", self._key_release_event)
def _add_book_page(self, book, position):
"""Ajoute une page au notebook des dessins"""
#print("Main::_add_book_page")
tab = classDrawing.Tab(self)
self.active_tab = tab
vbox = Gtk.VBox(homogeneous=False, spacing=0)
w = self.window.get_allocated_width()-280
hpaned = Gtk.HPaned()
hpaned.set_position(w)
hpaned.add1(tab.sw)
menu_button = self.builder.get_object("menu_cas")
if menu_button.get_active() == True:
sw = self._make_combi_box(tab)
hpaned.pack2(sw, False)
else:
tab.right_menu = None
hpaned.show()
vbox.pack_start(hpaned, True, True, 0)
vbox.show()
tab_box = Gtk.HBox(homogeneous=False, spacing=2)
tab_label = Gtk.Label() # gérer en fonction de la longueur dispo
tab.title = tab_label
close_b = Gtk.Button.new_from_icon_name('window-close', Gtk.IconSize.MENU)
close_b.set_relief(Gtk.ReliefStyle.NONE)
close_b.connect('clicked', self._on_remove_page, book, vbox)
tab_box.pack_start(tab_label, False, True, 0)
tab_box.pack_start(close_b, False, True, 0)
tab_box.show_all()
self._tabs.insert(position, tab)
book.insert_page(vbox, tab_box, position)
# à tester fonctionne pour les widgets mais évidemment pas pour les Tab
#book.set_tab_reorderable(vbox, True)
book.set_current_page(position)
def _remove_page(self, book, n_page):
"""Fonction de suppression de page
Attention le notebook n'est pas actualisé
avant le changement de page qui suit"""
studies = self.studies
tabs = self._tabs
closed_tab = tabs[n_page]
opened_studies = [] # études ouvertes sur une autre page
for tab in tabs:
if tab is closed_tab:
continue
drawings = tab.drawings
for drawing in drawings.values():
id_study = drawing.id_study
if not id_study in opened_studies:
opened_studies.append(id_study)
drawings = closed_tab.drawings
for drawing in drawings.values():
id_study = drawing.id_study
if id_study in opened_studies:
continue
try:
del (studies[id_study])
except KeyError:
continue
if hasattr(self, "editor"):
ed_data = self.editor.data_editors
for id in list(ed_data):
if id in opened_studies:
continue
del(self.editor.data_editors[id])
del(self._tabs[n_page])
frame = book.get_nth_page(n_page)
# on déconnecte le changement de page pour éviter un numéro de page éroné
book.disconnect(self._handler_id["book"])
book.remove(frame)
self._handler_id['book'] = book.connect("switch_page", self.on_switch_page)
n_page = book.get_current_page()
n_pages = book.get_n_pages()
if n_page == n_pages-1:
book.set_current_page(n_page-1)
def _on_remove_page(self, button, book, frame):
"""Méthode de suppression d'une page"""
n_page = book.page_num(frame)
n_pages = self.book.get_n_pages()
if n_pages == 2:
return
tab = self._tabs[n_page]
if hasattr(self, "editor"):
for drawing in tab.drawings.values():
try:
ed_data = self.editor.data_editors[drawing.id_study]
except KeyError:
continue
if ed_data.is_changed:
if file_tools.exit_as_ok_func2("Enregistrer le fichier '%s'?" % ed_data.name):
if ed_data.path is None:
path = file_tools.recursive_file_select(self.UP.get_default_path())
if not path is None:
ed_data.path = path
self.editor.save_study(ed_data)
self._remove_page(book, n_page)
def on_switch_page(self, widget=None, page=None, n=0):
"""Gestionnaire des évènements lors du changement de page du notebook"""
book = self.book
n_pages = book.get_n_pages()
#print ('Main::on_switch_page', n, n_pages)
if n == n_pages-1:
# suppression 15/6/2019 debug -------
# book.stop_emission("switch-page")
#-----------------------------------
return
self.active_tab = tab = self._tabs[n]
drawing = tab.active_drawing
if drawing is None:
rdm_status = 0
errors = []
else:
id_study = drawing.id_study
study = self.studies[id_study]
rdm_status = study.rdm.status
errors = study.rdm.errors
# mise à jour de l'éditeur
if hasattr(self, "editor"):
if self.editor.w2.get_window() is None:
del (self.editor)
else:
self._update_editor()
self._set_buttons_rdm(rdm_status)
self._update_titles()
self._show_message(errors, False)
# -----------------------------------------------------------
#
# Méthodes relatives aux évènements
#
# -----------------------------------------------------------
def _key_release_event(self, widget, event):
tab = self.active_tab
key = Gdk.keyval_name (event.keyval)
if key == 'Control_L':
self.key_press = False
tab.layout_motion_event(tab.layout, event)
# attention si la fenetre de pybar n'a pas le focus, les événements clavier ne sont pas interceptés alors que les évènements souris le sont.
def _key_press_event(self, widget, event):
key = Gdk.keyval_name (event.keyval)
tab = self.active_tab
is_selected = tab.is_selected
if key == 'Control_L':
self.key_press = True
elif key == 'Escape':
tab.is_selected = False
tab.remove_tools_box()
watch = Gdk.Cursor.new_for_display(Gdk.Display.get_default(), Gdk.CursorType.ARROW)
screen = Gdk.Screen.get_default()
window = screen.get_root_window()
window.set_cursor(watch)
tab.set_surface(tab.area_w, tab.area_h)
cr = cairo.Context(tab.surface)
tab.paint_all_struct(cr, None, 1.)
tab.layout.queue_draw()
elif key == 'Return':
if not is_selected:
return
selected = is_selected[0]
if selected == 'draw':
drawing = is_selected[1]
tab.active_drawing = drawing
tab.do_new_drawing(False)
self._update_combi_box()
elif key == 'Delete':
if not is_selected:
return
selected = is_selected[0]
if selected == 'value':
drawing, n_case, legend = is_selected[1:]
self.on_hide_value(None, drawing, n_case, legend)
def _button_release_event(self, widget, event):
#print('_button_release_event')
self.active_tab.finish_dnd(event, self.is_press)
self.is_press = False
def motion_notify_event(self, area, event):
#if Gtk.events_pending():
# return
self.active_tab.start_dnd(area, event, self.is_press)
# mettre une info ici
def leave_notify_event(self, layout, event):
"""événement : le curseur quitte la zone du layout"""
#print("leave_notify_event")
if not self.is_press is False:
return
tab = self.active_tab
tab.set_surface(tab.area_w, tab.area_h)
cr = cairo.Context(tab.surface)
tab.paint_all_struct(cr, None, 1.)
layout.queue_draw()
self.is_press = False
watch = Gdk.Cursor.new_for_display(Gdk.Display.get_default(), Gdk.CursorType.ARROW)
screen = Gdk.Screen.get_default()
window = screen.get_root_window()
window.set_cursor(watch)
# Double clic : génére : press -> release -> press -> press -> 2Button -> release
def button_press_event(self, widget, event):
#print("button_press_event")
tab = self.active_tab
screen = Gdk.Screen.get_default()
window = screen.get_root_window()
try:
obj_selected = tab.is_selected
except AttributeError:
obj_selected = False
if event.type == Gdk.EventType.BUTTON_PRESS:
watch = Gdk.Cursor.new_for_display(Gdk.Display.get_default(), Gdk.CursorType.FLEUR)
if event.get_button()[1] == 1:
self.is_press = (event.x, event.y)
tab.motion = (0, 0) # provisoire, en attendant mieux
if obj_selected is False:
return
drawing = obj_selected[1]
status = drawing.status
if obj_selected[0] == 'entry':
entry = obj_selected[2]
tab.remove_entry_box()
tab.remove_tools_box()
tab.is_selected = ('draw', drawing)
tab.layout_motion_event(tab.layout, event)
return
if obj_selected[0] == 'curve':
self._select_curve(drawing, obj_selected[2])
return
elif obj_selected[0] == 'draw':
window.set_cursor(watch)
self._select_drawing(obj_selected[1])
return
elif obj_selected[0] == 'info':
window.set_cursor(watch)
return
elif obj_selected[0] == 'value':
window.set_cursor(watch)
return
elif obj_selected[0] == 'node':
content = tab.get_message()
self.message.set_message(content)
return
elif obj_selected[0] == 'bar':
content = tab.get_message()
self.message.set_message(content)
return
elif event.get_button()[1] == 3:
#self.is_press = (event.x, event.y)
x, y = event.x, event.y
if obj_selected is False:
self._create_menu5(event)
return True
drawing = obj_selected[1]
if obj_selected[0] == 'value':
self._create_menu7(event, obj_selected[1], obj_selected[2], obj_selected[3])
return
if obj_selected[0] == 'curve':
self._create_menu6(event, obj_selected[1], obj_selected[2], obj_selected[4])
return
if obj_selected[0] == 'node':
watch = Gdk.Cursor.new_for_display(Gdk.Display.get_default(), Gdk.CursorType.ARROW)
window.set_cursor(watch)
node = obj_selected[2]
# ajouter ici les menus pour les noeuds
self._create_menu3(event, drawing, node)
return
if obj_selected[0] == 'bar':
watch = Gdk.Cursor.new_for_display(Gdk.Display.get_default(), Gdk.CursorType.ARROW)
window.set_cursor(watch)
self._create_menu2(event, obj_selected[2])
return
self._create_menu1(event, obj_selected[1])
return
elif event.type == Gdk.EventType._2BUTTON_PRESS:
if obj_selected is False:
return
drawing = obj_selected[1]
status = drawing.status
if obj_selected[0] == 'node':
return
# ajouter ici les menus pour les noeuds
if obj_selected[0] == 'bar':
self.on_bar_select(None, barre=obj_selected[2])
return
if obj_selected[0] == 'curve':
self._select_curve(drawing, obj_selected[2])
return
if obj_selected[0] == 'info':
if not drawing.title_id == obj_selected[2]:
return
self._on_edit_title(drawing, obj_selected[2])
return
if obj_selected[0] == 'value':
self._on_edit_value(drawing, obj_selected[2], obj_selected[3])
return
# double clic
def on_delete_value(self, widget, data):
"""Supprime une valeur sur une courbe"""
drawing, n_curve, legend = data
drawing.delete_value(n_curve, legend)
drawing.s_case = n_curve
drawing.del_patterns()
tab = self.active_tab
#tab.del_surface()
tab.configure_event(tab.layout)
tab.layout.queue_draw()
def on_hide_value(self, widget, data):
"""Cache une valeur sur une courbe"""
drawing, n_curve, legend = data
drawing.set_hide_value(n_curve, legend)
drawing.s_case = n_curve
drawing.del_patterns()
tab = self.active_tab
#tab.del_surface()
tab.configure_event(tab.layout)
tab.layout.queue_draw()
def on_set_anchor(self, widget, data):
"""Ancre une valeur sur le dessin"""
drawing, n_curve, obj = data
user_values = drawing.user_values
tab = self.active_tab
is_selected = tab.is_selected
barre = is_selected[3]
if not drawing.status in user_values:
user_values[drawing.status] = {}
values = user_values[drawing.status]
if not n_curve in values:
values[n_curve] = {}
if not barre in values[n_curve]:
values[n_curve][barre] = {}
value = values[n_curve][barre]
pos = obj.is_selected[2]
if pos is None:
id_study = drawing.id_study
study = self.studies[id_study]
rdm = study.rdm
arc = rdm.struct.Curves[barre]
pos = arc.get_curve_abs(obj.is_selected[1], obj.is_selected[0], rdm.struct.Lengths)
#pos = arc.pos[obj.is_selected[1]]
value[pos] = {0: (0, 0, False)} # dx, dy, hidden
drawing.del_patterns()
#tab.del_surface()
tab.configure_event(tab.layout)
tab.layout.queue_draw()
def on_display_value(self, widget, data):
"""Affiche les valeurs sur la courbe n_curve"""
drawing, n_curve = data
if widget.get_active():
drawing.s_values.append(n_curve)
drawing.restore_values(n_curve)
else:
# provisoire : astuce pour remettre les valeurs de la courbe s_curve
if drawing.s_curve == n_curve:
drawing.restore_values(n_curve)
try:
drawing.s_values.remove(n_curve)
except ValueError:
pass
self._do_new_drawing()
def on_display_char(self, widget, data):
"""Ouvre un dessin du chargement"""
drawing, n_curve, curve = data
tab = self.active_tab
#drawing = tab.active_drawing
drawing.s_case = n_curve
tab.add_char_drawing(drawing)
def on_select_curve(self, widget, data):
"""Sélectionne une courbe sur un dessin depuis un menu"""
drawing, n, curve = data
self._select_curve(drawing, n)
def _select_curve(self, drawing, n_curve):
"""Sélectionne une courbe sur un dessin"""
#print("_select_curve", drawing.id)
tab = self.active_tab
tab.active_drawing = drawing
id_study = drawing.id_study
study = self.studies[id_study]
rdm = study.rdm
if drawing.status == 8:
drawing.s_influ = n_curve
content = drawing.get_influ_message(study, n_curve)
self.message.set_message(content)
return
drawing.s_curve = n_curve
drawing.del_patterns()
#tab.del_surface()
# actualisation dessin de chargement si il existe
#char_drawing = drawing.char_drawing
key = drawing.get_char_drawing()
if not key is None:
child = drawing.childs[key]
child.s_case = n_curve
child.del_patterns()
tab.configure_event(tab.layout)
tab.layout.queue_draw()
content = tab.get_char_message(rdm, n_curve)
self.message.set_message(content)
def _on_edit_value(self, drawing, n_case, legend):
"""Modification de la position en x (sur la barre) de la légende"""
tab = self.active_tab
tab.on_show_value_box(drawing, n_case, legend)
def _on_edit_title(self, drawing, info_id):
"""Action de modification du titre d'un dessin"""
#print "_on_edit_title", info_id
tab = self.active_tab
tab.on_show_title_box(drawing)
def on_select_drawing(self, widget, drawing):
"""Sélectionne le diagramme"""
#print "on_select_drawing"
drawing.options['Select'] = widget.get_active()
self._select_drawing(drawing)
def _select_drawing(self, drawing):
#print('_select_drawing remettre')
tab = self.active_tab
prec_drawing = tab.active_drawing
id_study = drawing.id_study
study = self.studies[id_study]
rdm = study.rdm
if drawing.get_is_char_drawing():
tab.do_new_drawing(False)
content = tab.get_char_message(rdm, drawing.s_case)
self.message.set_message(content)
return
tab.active_drawing = drawing
tab.paint_drawings()
self._fill_right_menu()
self._update_combi_box()
# maj de l'éditeur
if hasattr(self, "editor") and not (prec_drawing is drawing):
self._update_editor()
self._update_titles()
self._show_message(rdm.errors, False)
self._set_buttons_rdm(rdm.status)
def on_select_bars(self, widget, drawing):
"""Lance l'ouverture de la fenetre de choix des barres et remplace l'set s_influ_bars"""
#tab = self.active_tab
#drawing = tab.active_drawing
id_study = drawing.id_study
study = self.studies[id_study]
rdm = study.rdm
bars = rdm.struct.GetBarsNames()
# trier barre ?? XXX
#bars.sort()
try:
s_influ_bars = drawing.s_influ_bars
except AttributeError:
s_influ_bars = []
bars = file_tools.open_dialog_bars(bars, s_influ_bars)
if bars is False or bars == []:
return
drawing.s_influ_bars = bars
self._fill_right_menu()
self._do_new_drawing()
def on_node_display(self, widget, drawing):
"""Relance un affichage en fonction de l'état de l'option"""
tab = self.active_tab
tab.active_drawing = drawing
drawing.options['Node'] = widget.get_active()
self._do_new_drawing()
def on_barre_display(self, widget, drawing):
"""Relance un affichage en fonction de l'état de l'option"""
tab = self.active_tab
tab.active_drawing = drawing
drawing.options['Barre'] = widget.get_active()
self._do_new_drawing()
def on_axis_display(self, widget, drawing):
"""Relance un affichage en fonction de l'état de l'option"""
tab = self.active_tab
tab.active_drawing = drawing
drawing.options['Axis'] = widget.get_active()
self._do_new_drawing()
def on_title_display(self, widget, drawing):
"""Affichage du titre du dessin"""
tab = self.active_tab
tab.active_drawing = drawing
drawing.set_title_visibility(widget.get_active())
drawing.options['Title'] = widget.get_active()
self._do_new_drawing()
def on_series_display(self, widget, drawing):
"""Affiche les légendes des courbes"""
tab = self.active_tab
tab.active_drawing = drawing
drawing.set_series_visibility(widget.get_active())
drawing.options['Series'] = widget.get_active()
self._do_new_drawing()
def on_synchronise(self, widget, drawing):
drawing.options['Sync'] = widget.get_active()
if widget.get_active():
drawing.s_cases = drawing.parent.s_cases
drawing.s_case = drawing.parent.s_case
else:
drawing.s_cases = copy.copy(drawing.parent.s_cases)
self._do_new_drawing()
self._fill_right_menu()
self._update_combi_box()
def on_add_sigma_drawing(self, widget, drawing):
"""Ajoute un dessin des contraintes normales"""
tab = self.active_tab
id_study = drawing.id_study
study = self.studies[id_study]
tab.add_sigma_drawing(drawing, study)
def on_add_drawing(self, widget, drawing):
"""Ajoute un diagramme à partir du diagramme sélectionné"""
#print "on_add_drawing"
tab = self.active_tab
id_study = drawing.id_study
study = self.studies[id_study]
tab.add_drawing(drawing, study)
self._fill_right_menu()
self._update_combi_box()
def save_drawing_prefs(self, study):
""""Sauve les préférences du dessin de l'étude study"""
#print "save_drawing_prefs"
id_study = study.id
tab = self.active_tab
rdm = study.rdm
if isinstance(rdm, classRdm.EmptyRdm):
return
xml = rdm.struct.XML
root = xml.getroot()
node = xml.find('draw')
if not node is None:
root.remove(node)
drawing_pref = ET.SubElement(root, "draw", {"id": "prefs"})
for id in tab.drawings:
drawing = tab.drawings[id]
if not drawing.id_study == id_study:
continue
if not drawing.get_is_parent():
continue
node1 = drawing.get_xml_prefs(drawing_pref)
for key in drawing.childs:
d = drawing.childs[key]
node2 = d.get_xml_prefs(node1)
path = study.path
if path is None:
return
function.indent(root)
#print ET.tostring(root)
#return
try:
xml.write(path, encoding="UTF-8", xml_declaration=True)
except IOError:
print("Ecriture impossible dans %s" % path)
def on_save_drawings(self, widget, drawing):
"""Enregistre l'état de l'étude (graphes et préférences)"""
tab = self.active_tab
id_study = drawing.id_study
study = self.studies[id_study]
self.save_drawing_prefs(study)
tab.remove_drawings_by_study(drawing)
self._fill_right_menu()
self._update_combi_box()
if hasattr(self, "editor"):
try:
del(self.editor.data_editors[id_study])
except KeyError:
pass
self._update_editor()
self._update_titles()
drawing = tab.active_drawing