-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathemzed.pyw
executable file
·2123 lines (1902 loc) · 92.7 KB
/
emzed.pyw
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 -*-
#
# Copyright © 2009-2011 Pierre Raybaut
# Licensed under the terms of the MIT License
# (see spyderlib/__init__.py for details)
"""
Spyder, the Scientific PYthon Development EnviRonment
=====================================================
Developped and maintained by Pierre Raybaut
Copyright © 2009-2012 Pierre Raybaut
Licensed under the terms of the MIT License
(see spyderlib/__init__.py for details)
"""
import os
import sys
import os.path as osp
import platform
import re
# Keeping a reference to the original sys.exit before patching it
ORIGINAL_SYS_EXIT = sys.exit
import pkg_resources
pkg_resources.require("spyder==2.1.13")
if sys.platform == "win32":
# on windows spyder only unses all features of variable explorer
# for ipython 0.10:
pkg_resources.require("IPython==0.10")
import IPython
print "IPYTHON VERSION=", IPython.__version__
# Test if IPython v0.12+ is installed to eventually switch to PyQt API #2
from spyderlib.utils.programs import is_module_installed
if is_module_installed('IPython.frontend.qt', '>=0.12'):
# Importing IPython will eventually set the QT_API environment variable
import IPython # analysis:ignore
if os.environ.get('QT_API', 'pyqt') == 'pyqt':
# If PyQt is the selected GUI toolkit (at this stage, only the
# bootstrap script has eventually set this option), switch to
# PyQt API #2 by simply importing the IPython qt module
os.environ['QT_API'] = 'pyqt'
try:
from IPython.external import qt #analysis:ignore
except ImportError:
# Avoid raising any error here: the spyderlib.requirements module
# will take care of it, in a user-friendly way (Tkinter message box
# if no GUI toolkit is installed)
pass
#EMZEDADDON
here = os.path.dirname(os.path.abspath(__file__))
os.environ["EMZED_HOME"] = here
import spyderlib
os.environ["SPYDER_PARENT_DIR"] = os.path.abspath(os.path.join(spyderlib.__file__, "../.."))
print os.environ["SPYDER_PARENT_DIR"]
import spyder_app_patches
spyder_app_patches.patch_spyder()
# during first startup the current working directory is used by
# the working directory chooser as default, so not need to apply
# any butch, but only set the workingdirectory directly.
# at later startup spyder chooses last used working dir.
import userConfig
home = userConfig.getDataHome()
if not os.path.exists(home):
os.makedirs(home)
os.chdir(home)
from version import version as emzed_version
try:
import pyopenms
except ImportError:
from spyderlib import requirements
requirements.show_warning("can not load pyopenms. Is it installed ?")
exit(1)
# Check requirements
from spyderlib import requirements
requirements.check_path()
requirements.check_qt()
# Windows platforms only: support for hiding the attached console window
set_attached_console_visible = None
is_attached_console_visible = None
if os.name == 'nt':
from spyderlib.utils.windows import (set_attached_console_visible,
is_attached_console_visible)
# Workaround: importing rope.base.project here, otherwise this module can't
# be imported if Spyder was executed from another folder than spyderlib
try:
import rope.base.project # analysis:ignore
except ImportError:
pass
from spyderlib.qt.QtGui import (QApplication, QMainWindow, QSplashScreen,
QPixmap, QMessageBox, QMenu, QColor, QShortcut,
QKeySequence, QDockWidget, QAction, QLineEdit,
QInputDialog, QDesktopServices)
from spyderlib.qt.QtCore import SIGNAL, QPoint, Qt, QSize, QByteArray, QUrl
from spyderlib.qt.compat import (from_qvariant, getopenfilename,
getsavefilename)
# Avoid a "Cannot mix incompatible Qt library" error on Windows platforms
# when PySide is selected by the QT_API environment variable and when PyQt4
# is also installed (or any other Qt-based application prepending a directory
# containing incompatible Qt DLLs versions in PATH):
if sys.platform == "win32":
from spyderlib.qt import QtSvg # analysis:ignore
# Local imports
from spyderlib import __version__, __project_url__, __forum_url__
from spyderlib.utils import encoding
try:
from spyderlib.utils.environ import WinUserEnvDialog
except ImportError:
WinUserEnvDialog = None # analysis:ignore
from spyderlib.widgets.pathmanager import PathManager
from spyderlib.plugins.configdialog import (ConfigDialog, MainConfigPage,
ColorSchemeConfigPage)
from spyderlib.plugins.shortcuts import ShortcutsConfigPage
from spyderlib.plugins.console import Console
from spyderlib.plugins.workingdirectory import WorkingDirectory
from spyderlib.plugins.editor import Editor
from spyderlib.plugins.history import HistoryLog
from spyderlib.plugins.inspector import ObjectInspector
try:
# Assuming Qt >= v4.4
from spyderlib.plugins.onlinehelp import OnlineHelp
except ImportError:
# Qt < v4.4
OnlineHelp = None # analysis:ignore
from spyderlib.plugins.explorer import Explorer
from spyderlib.plugins.externalconsole import ExternalConsole
from spyderlib.plugins.variableexplorer import VariableExplorer
from spyderlib.plugins.findinfiles import FindInFiles
from spyderlib.plugins.projectexplorer import ProjectExplorer
from spyderlib.plugins.outlineexplorer import OutlineExplorer
from spyderlib.utils.qthelpers import (create_action, add_actions, get_std_icon,
create_module_bookmark_actions,
create_bookmark_action,
create_program_action, DialogManager,
keybinding, qapplication,
create_python_script_action, file_uri)
from spyderlib.baseconfig import (get_conf_path, _, get_module_data_path,
get_module_source_path, STDOUT, STDERR)
from spyderlib.config import (get_icon, get_image_path, CONF, get_shortcut,
EDIT_EXT, IMPORT_EXT)
from spyderlib.otherplugins import get_spyderplugins_mods
from spyderlib.utils.programs import (run_python_script, is_module_installed,
start_file, run_python_script_in_terminal)
from spyderlib.utils.iofuncs import load_session, save_session, reset_session
from spyderlib.userconfig import NoDefault, NoOptionError
from spyderlib.utils.module_completion import modules_db
TEMP_SESSION_PATH = get_conf_path('.temp.session.tar')
def get_python_doc_path():
"""
Return Python documentation path
(Windows: return the PythonXX.chm path if available)
"""
if os.name == 'nt':
doc_path = osp.join(sys.prefix, "Doc")
if not osp.isdir(doc_path):
return
python_chm = [path for path in os.listdir(doc_path)
if re.match(r"(?i)Python[0-9]{3}.chm", path)]
if python_chm:
return file_uri(osp.join(doc_path, python_chm[0]))
else:
vinf = sys.version_info
doc_path = '/usr/share/doc/python%d.%d/html' % (vinf[0], vinf[1])
python_doc = osp.join(doc_path, "index.html")
if osp.isfile(python_doc):
return file_uri(python_doc)
#==============================================================================
# Spyder's main window widgets utilities
#==============================================================================
def get_focus_python_shell():
"""Extract and return Python shell from widget
Return None if *widget* is not a Python shell (e.g. IPython kernel)"""
widget = QApplication.focusWidget()
from spyderlib.widgets.shell import PythonShellWidget
from spyderlib.widgets.externalshell.pythonshell import ExternalPythonShell
if isinstance(widget, PythonShellWidget):
return widget
elif isinstance(widget, ExternalPythonShell):
return widget.shell
def get_focus_widget_properties():
"""Get properties of focus widget
Returns tuple (widget, properties) where properties is a tuple of
booleans: (is_console, not_readonly, readwrite_editor)"""
widget = QApplication.focusWidget()
from spyderlib.widgets.shell import ShellBaseWidget
from spyderlib.widgets.editor import TextEditBaseWidget
textedit_properties = None
if isinstance(widget, (ShellBaseWidget, TextEditBaseWidget)):
console = isinstance(widget, ShellBaseWidget)
not_readonly = not widget.isReadOnly()
readwrite_editor = not_readonly and not console
textedit_properties = (console, not_readonly, readwrite_editor)
return widget, textedit_properties
#TODO: Improve the stylesheet below for separator handles to be visible
# (in Qt, these handles are by default not visible on Windows!)
STYLESHEET="""
QSplitter::handle {
margin-left: 4px;
margin-right: 4px;
}
QSplitter::handle:horizontal {
width: 1px;
border-width: 0px;
background-color: lightgray;
}
QSplitter::handle:vertical {
border-top: 2px ridge lightgray;
border-bottom: 2px;
}
QMainWindow::separator:vertical {
margin-left: 1px;
margin-top: 25px;
margin-bottom: 25px;
border-left: 2px groove lightgray;
border-right: 1px;
}
QMainWindow::separator:horizontal {
margin-top: 1px;
margin-left: 5px;
margin-right: 5px;
border-top: 2px groove lightgray;
border-bottom: 2px;
}
"""
class MainWindow(QMainWindow):
"""Spyder main window"""
DOCKOPTIONS = QMainWindow.AllowTabbedDocks|QMainWindow.AllowNestedDocks
spyder_path = get_conf_path('.path')
BOOKMARKS = (
('PyQt4',
"http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/index.html",
_("PyQt4 Reference Guide"), "qt.png"),
('PyQt4',
"http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/classes.html",
_("PyQt4 API Reference"), "qt.png"),
('xy', "http://www.pythonxy.com",
_("Python(x,y)"), "pythonxy.png"),
('numpy', "http://docs.scipy.org/doc/",
_("Numpy and Scipy documentation"),
"scipy.png"),
('matplotlib', "http://matplotlib.sourceforge.net/contents.html",
_("Matplotlib documentation"),
"matplotlib.png"),
)
def __init__(self, options=None):
QMainWindow.__init__(self)
qapp = QApplication.instance()
self.default_style = str(qapp.style().objectName())
self.dialog_manager = DialogManager()
self.init_workdir = options.working_directory
self.debug = options.debug
self.profile = options.profile
self.multithreaded = options.multithreaded
self.light = options.light
self.debug_print("Start of MainWindow constructor")
self.shortcut_data = []
# Loading Spyder path
self.path = []
self.project_path = []
if osp.isfile(self.spyder_path):
self.path, _x = encoding.readlines(self.spyder_path)
self.path = [name for name in self.path if osp.isdir(name)]
self.remove_path_from_sys_path()
self.add_path_to_sys_path()
self.load_temp_session_action = create_action(self,
_("Reload last session"),
triggered=lambda:
self.load_session(TEMP_SESSION_PATH))
self.load_session_action = create_action(self,
_("Load session..."),
None, 'fileopen.png',
triggered=self.load_session,
tip=_("Load Spyder session"))
self.save_session_action = create_action(self,
_("Save session and quit..."),
None, 'filesaveas.png',
triggered=self.save_session,
tip=_("Save current session "
"and quit application"))
# Plugins
self.console = None
self.workingdirectory = None
self.editor = None
self.explorer = None
self.inspector = None
self.onlinehelp = None
self.projectexplorer = None
self.outlineexplorer = None
self.historylog = None
self.extconsole = None
self.ipython_frontends = []
self.ipython_app = None # Single IPython QtConsole App instance
self.variableexplorer = None
self.findinfiles = None
self.thirdparty_plugins = []
# Preferences
self.general_prefs = [MainConfigPage, ShortcutsConfigPage,
ColorSchemeConfigPage]
self.prefs_index = None
# Actions
self.close_dockwidget_action = None
self.find_action = None
self.find_next_action = None
self.find_previous_action = None
self.replace_action = None
self.undo_action = None
self.redo_action = None
self.copy_action = None
self.cut_action = None
self.paste_action = None
self.delete_action = None
self.selectall_action = None
self.maximize_action = None
self.fullscreen_action = None
# Menu bars
self.file_menu = None
self.file_menu_actions = []
self.edit_menu = None
self.edit_menu_actions = []
self.search_menu = None
self.search_menu_actions = []
self.source_menu = None
self.source_menu_actions = []
self.run_menu = None
self.run_menu_actions = []
self.interact_menu = None
self.interact_menu_actions = []
self.tools_menu = None
self.tools_menu_actions = []
self.external_tools_menu = None # We must keep a reference to this,
# otherwise the external tools menu is lost after leaving setup method
self.external_tools_menu_actions = []
self.view_menu = None
self.windows_toolbars_menu = None
self.help_menu = None
self.help_menu_actions = []
# Toolbars
self.main_toolbar = None
self.main_toolbar_actions = []
self.file_toolbar = None
self.file_toolbar_actions = []
self.edit_toolbar = None
self.edit_toolbar_actions = []
self.search_toolbar = None
self.search_toolbar_actions = []
self.source_toolbar = None
self.source_toolbar_actions = []
self.run_toolbar = None
self.run_toolbar_actions = []
# Set Window title and icon
title = "eMZed"
if self.debug:
title += " (DEBUG MODE)"
self.setWindowTitle(title)
#icon_name = 'spyder_light.svg' if self.light else 'spyder.svg'
icon_name = "emzed.ico"
from spyderlib.qt.QtGui import QIcon
self.setWindowIcon(QIcon(icon_name))
# EMZD MODIFIED: Showing splash screen
splash_path = os.path.join(here, "splash.png")
pixmap = QPixmap(splash_path, "png")
self.splash = QSplashScreen(pixmap)
import time
self.splash_started = time.time()
font = self.splash.font()
font.setPixelSize(14)
self.splash.setFont(font)
# MODIFICATION END
self.set_splash(_("Initializing..."))
if not self.light:
self.splash.show()
self.set_splash(_("Initializing..."))
if CONF.get('main', 'current_version', '') != __version__:
CONF.set('main', 'current_version', __version__)
# Execute here the actions to be performed only once after
# each update (there is nothing there for now, but it could
# be useful some day...)
# List of satellite widgets (registered in add_dockwidget):
self.widgetlist = []
# Flags used if closing() is called by the exit() shell command
self.already_closed = False
self.is_starting_up = True
self.floating_dockwidgets = []
self.window_size = None
self.window_position = None
self.state_before_maximizing = None
self.current_quick_layout = None
self.previous_layout_settings = None
self.last_plugin = None
self.fullscreen_flag = None # isFullscreen does not work as expected
# The following flag remember the maximized state even when
# the window is in fullscreen mode:
self.maximized_flag = None
# Session manager
self.next_session_name = None
self.save_session_name = None
self.apply_settings()
self.debug_print("End of MainWindow constructor")
def debug_print(self, message):
"""Debug prints"""
if self.debug:
print >>STDOUT, message
#---- Window setup
def create_toolbar(self, title, object_name, iconsize=24):
"""Create and return toolbar with *title* and *object_name*"""
toolbar = self.addToolBar(title)
toolbar.setObjectName(object_name)
toolbar.setIconSize( QSize(iconsize, iconsize) )
return toolbar
def setup(self):
"""Setup main window"""
self.debug_print("*** Start of MainWindow setup ***")
if not self.light:
self.close_dockwidget_action = create_action(self,
_("Close current dockwidget"),
triggered=self.close_current_dockwidget,
context=Qt.ApplicationShortcut)
self.register_shortcut(self.close_dockwidget_action,
"_", "Close dockwidget", "Shift+Ctrl+F4")
_text = _("&Find text")
self.find_action = create_action(self, _text, icon='find.png',
tip=_text, triggered=self.find,
context=Qt.WidgetShortcut)
self.register_shortcut(self.find_action, "Editor",
"Find text", "Ctrl+F")
self.find_next_action = create_action(self, _("Find &next"),
icon='findnext.png', triggered=self.find_next,
context=Qt.WidgetShortcut)
self.register_shortcut(self.find_next_action, "Editor",
"Find next", "F3")
self.find_previous_action = create_action(self,
_("Find &previous"),
icon='findprevious.png', triggered=self.find_previous,
context=Qt.WidgetShortcut)
self.register_shortcut(self.find_previous_action, "Editor",
"Find previous", "Shift+F3")
_text = _("&Replace text")
self.replace_action = create_action(self, _text, icon='replace.png',
tip=_text, triggered=self.replace,
context=Qt.WidgetShortcut)
self.register_shortcut(self.replace_action, "Editor",
"Replace text", "Ctrl+H")
def create_edit_action(text, tr_text, icon_name):
textseq = text.split(' ')
method_name = textseq[0].lower()+"".join(textseq[1:])
return create_action(self, tr_text,
shortcut=keybinding(text.replace(' ', '')),
icon=get_icon(icon_name),
triggered=self.global_callback,
data=method_name,
context=Qt.WidgetShortcut)
self.undo_action = create_edit_action("Undo", _("Undo"),
'undo.png')
self.redo_action = create_edit_action("Redo", _("Redo"), 'redo.png')
self.copy_action = create_edit_action("Copy", _("Copy"),
'editcopy.png')
self.cut_action = create_edit_action("Cut", _("Cut"), 'editcut.png')
self.paste_action = create_edit_action("Paste", _("Paste"),
'editpaste.png')
self.delete_action = create_edit_action("Delete", _("Delete"),
'editdelete.png')
self.selectall_action = create_edit_action("Select All",
_("Select All"),
'selectall.png')
self.edit_menu_actions = [self.undo_action, self.redo_action,
None, self.cut_action, self.copy_action,
self.paste_action, self.delete_action,
None, self.selectall_action]
self.search_menu_actions = [self.find_action, self.find_next_action,
self.find_previous_action,
self.replace_action]
self.search_toolbar_actions = [self.find_action,
self.find_next_action,
self.replace_action]
namespace = None
if not self.light:
# Maximize current plugin
self.maximize_action = create_action(self, '',
triggered=self.maximize_dockwidget)
self.register_shortcut(self.maximize_action, "_",
"Maximize dockwidget", "Ctrl+Alt+Shift+M")
self.__update_maximize_action()
# Fullscreen mode
self.fullscreen_action = create_action(self,
_("Fullscreen mode"),
triggered=self.toggle_fullscreen)
self.register_shortcut(self.fullscreen_action, "_",
"Fullscreen mode", "F11")
self.main_toolbar_actions = [self.maximize_action,
self.fullscreen_action, None]
# Main toolbar
self.main_toolbar = self.create_toolbar(_("Main toolbar"),
"main_toolbar")
# File menu/toolbar
self.file_menu = self.menuBar().addMenu(_("&File"))
self.connect(self.file_menu, SIGNAL("aboutToShow()"),
self.update_file_menu)
self.file_toolbar = self.create_toolbar(_("File toolbar"),
"file_toolbar")
# Edit menu/toolbar
self.edit_menu = self.menuBar().addMenu(_("&Edit"))
self.edit_toolbar = self.create_toolbar(_("Edit toolbar"),
"edit_toolbar")
# Search menu/toolbar
self.search_menu = self.menuBar().addMenu(_("&Search"))
self.search_toolbar = self.create_toolbar(_("Search toolbar"),
"search_toolbar")
# Source menu/toolbar
self.source_menu = self.menuBar().addMenu(_("Sour&ce"))
self.source_toolbar = self.create_toolbar(_("Source toolbar"),
"source_toolbar")
# Run menu/toolbar
self.run_menu = self.menuBar().addMenu(_("&Run"))
self.run_toolbar = self.create_toolbar(_("Run toolbar"),
"run_toolbar")
# Interact menu/toolbar
self.interact_menu = self.menuBar().addMenu(_("&Interpreters"))
# Tools menu
self.tools_menu = self.menuBar().addMenu(_("&Tools"))
# View menu
self.view_menu = self.menuBar().addMenu(_("&View"))
# Help menu
self.help_menu = self.menuBar().addMenu("?")
# Status bar
status = self.statusBar()
status.setObjectName("StatusBar")
status.showMessage(_("Welcome to Spyder!"), 5000)
# Tools + External Tools
prefs_action = create_action(self, _("Pre&ferences"),
icon='configure.png',
triggered=self.edit_preferences)
self.register_shortcut(prefs_action, "_", "Preferences",
"Ctrl+Alt+Shift+P")
spyder_path_action = create_action(self,
_("PYTHONPATH manager"),
None, 'pythonpath_mgr.png',
triggered=self.path_manager_callback,
tip=_("Open Spyder path manager"),
menurole=QAction.ApplicationSpecificRole)
update_modules_action = create_action(self,
_("Update module names list"),
None, 'reload.png',
triggered=self.update_modules,
tip=_("Update the list of names of all "
"the modules available in your "
"PYTHONPATH"))
self.tools_menu_actions = [prefs_action, spyder_path_action]
if osp.isfile(get_conf_path('db/rootmodules')):
self.tools_menu_actions += [update_modules_action, None]
else:
self.tools_menu_actions += [None]
self.main_toolbar_actions += [prefs_action, spyder_path_action]
if WinUserEnvDialog is not None:
winenv_action = create_action(self,
_("Current user environment variables..."),
icon='win_env.png',
tip=_("Show and edit current user environment "
"variables in Windows registry "
"(i.e. for all sessions)"),
triggered=self.win_env)
self.tools_menu_actions.append(winenv_action)
# External Tools submenu
self.external_tools_menu = QMenu(_("External Tools"))
self.external_tools_menu_actions = []
# Python(x,y) launcher
self.xy_action = create_action(self,
_("Python(x,y) launcher"),
icon=get_icon('pythonxy.png'),
triggered=lambda:
run_python_script('xy', 'xyhome'))
self.external_tools_menu_actions.append(self.xy_action)
if not is_module_installed('xy'):
self.xy_action.setDisabled(True)
self.xy_action.setToolTip(self.xy_action.toolTip() + \
'\nPlease install Python(x,y) to '
'enable this feature')
# Qt-related tools
additact = [None]
for name in ("designer-qt4", "designer"):
qtdact = create_program_action(self, _("Qt Designer"),
'qtdesigner.png', name)
if qtdact:
break
for name in ("linguist-qt4", "linguist"):
qtlact = create_program_action(self, _("Qt Linguist"),
'qtlinguist.png', "linguist")
if qtlact:
break
args = ['-no-opengl'] if os.name == 'nt' else []
qteact = create_python_script_action(self,
_("Qt examples"), 'qt.png', "PyQt4",
osp.join("examples", "demos",
"qtdemo", "qtdemo"), args)
for act in (qtdact, qtlact, qteact):
if act:
additact.append(act)
if len(additact) > 1:
self.external_tools_menu_actions += additact
# Sift
if is_module_installed('guidata') \
and is_module_installed('guiqwt'):
from guidata import configtools
from guiqwt import config # (loading icons) analysis:ignore
sift_icon = configtools.get_icon('sift.svg')
sift_act = create_python_script_action(self, _("Sift"),
sift_icon, "guiqwt", osp.join("tests", "sift"))
if sift_act:
self.external_tools_menu_actions += [None, sift_act]
# ViTables
vitables_act = create_program_action(self, _("ViTables"),
'vitables.png', "vitables")
if vitables_act:
self.external_tools_menu_actions += [None, vitables_act]
# Internal console plugin
self.console = Console(self, namespace, debug=self.debug,
exitfunc=self.closing, profile=self.profile,
multithreaded=self.multithreaded)
self.console.register_plugin()
# Working directory plugin
self.workingdirectory = WorkingDirectory(self, self.init_workdir)
self.workingdirectory.register_plugin()
# Object inspector plugin
if CONF.get('inspector', 'enable'):
self.set_splash(_("Loading object inspector..."))
self.inspector = ObjectInspector(self)
self.inspector.register_plugin()
# Outline explorer widget
if CONF.get('outline_explorer', 'enable'):
self.set_splash(_("Loading outline explorer..."))
fullpath_sorting = CONF.get('editor', 'fullpath_sorting', True)
self.outlineexplorer = OutlineExplorer(self,
fullpath_sorting=fullpath_sorting)
self.outlineexplorer.register_plugin()
# Editor plugin
self.set_splash(_("Loading editor..."))
self.editor = Editor(self)
self.editor.register_plugin()
# Populating file menu entries
quit_action = create_action(self, _("&Quit"),
icon='exit.png', tip=_("Quit"),
triggered=self.console.quit)
self.register_shortcut(quit_action, "_", "Quit", "Ctrl+Q")
self.file_menu_actions += [self.load_temp_session_action,
self.load_session_action,
self.save_session_action,
None, quit_action]
self.set_splash("")
# Find in files
if CONF.get('find_in_files', 'enable'):
self.findinfiles = FindInFiles(self)
self.findinfiles.register_plugin()
# Explorer
if CONF.get('explorer', 'enable'):
self.set_splash(_("Loading file explorer..."))
self.explorer = Explorer(self)
self.explorer.register_plugin()
# History log widget
if CONF.get('historylog', 'enable'):
self.set_splash(_("Loading history plugin..."))
self.historylog = HistoryLog(self)
self.historylog.register_plugin()
# Online help widget
if CONF.get('onlinehelp', 'enable') and OnlineHelp is not None:
self.set_splash(_("Loading online help..."))
self.onlinehelp = OnlineHelp(self)
self.onlinehelp.register_plugin()
# Project explorer widget
if CONF.get('project_explorer', 'enable'):
self.set_splash(_("Loading project explorer..."))
self.projectexplorer = ProjectExplorer(self)
self.projectexplorer.register_plugin()
# External console
if self.light:
# This is necessary to support the --working-directory option:
if self.init_workdir is not None:
os.chdir(self.init_workdir)
else:
self.set_splash(_("Loading external console..."))
self.extconsole = ExternalConsole(self, light_mode=self.light)
self.extconsole.register_plugin()
# Namespace browser
if not self.light:
# In light mode, namespace browser is opened inside external console
# Here, it is opened as an independent plugin, in its own dockwidget
self.set_splash(_("Loading namespace browser..."))
self.variableexplorer = VariableExplorer(self)
self.variableexplorer.register_plugin()
if not self.light:
nsb = self.variableexplorer.add_shellwidget(self.console.shell)
self.connect(self.console.shell, SIGNAL('refresh()'),
nsb.refresh_table)
nsb.auto_refresh_button.setEnabled(False)
self.set_splash(_("Setting up main window..."))
# ? menu
about_action = create_action(self,
_("About %s...") % "eMZed",
icon=get_std_icon('MessageBoxInformation'),
triggered=self.about)
#report_action = create_action(self,
#_("Report issue..."),
#icon=get_icon('bug.png'),
#triggered=self.report_issue
#)
# Spyder documentation
#doc_path = get_module_data_path('spyderlib', relpath="doc",
#attr_name='DOCPATH')
# * Trying to find the chm doc
#spyder_doc = osp.join(doc_path, "Spyderdoc.chm")
#if not osp.isfile(spyder_doc):
#spyder_doc = osp.join(doc_path, os.pardir, os.pardir,
#"Spyderdoc.chm")
# * Trying to find the html doc
#if not osp.isfile(spyder_doc):
#spyder_doc = osp.join(doc_path, "index.html")
#if not osp.isfile(spyder_doc): # development version
#spyder_doc = osp.join(get_module_source_path('spyderlib'),
#os.pardir, 'build', 'lib',
#'spyderlib', 'doc', "index.html")
#spyder_doc = file_uri(spyder_doc)
#doc_action = create_bookmark_action(self, spyder_doc,
#_("Spyder documentation"), shortcut="F1",
#icon=get_std_icon('DialogHelpButton'))
self.help_menu_actions = [about_action] # , report_action, doc_action]
# Python documentation
if get_python_doc_path() is not None:
pydoc_act = create_action(self, _("Python documentation"),
icon=get_icon('python.png'),
triggered=lambda:
start_file(get_python_doc_path()))
self.help_menu_actions += [None, pydoc_act]
# Qt assistant link
#qta_act = create_program_action(self, _("Qt Assistant"),
#'qtassistant.png', "assistant")
#if qta_act:
#self.help_menu_actions.append(qta_act)
# Windows-only: documentation located in sys.prefix/Doc
def add_doc_action(text, path):
"""Add doc action to help menu"""
ext = osp.splitext(path)[1]
if ext:
icon = get_icon(ext[1:]+".png")
else:
icon = get_std_icon("DirIcon")
path = file_uri(path)
action = create_action(self, text, icon=icon,
triggered=lambda path=path: start_file(path))
self.help_menu_actions.append(action)
if os.name == 'nt':
sysdocpth = osp.join(sys.prefix, 'Doc')
for docfn in os.listdir(sysdocpth):
pt = r'([a-zA-Z\_]*)(doc)?(-dev)?(-ref)?(-user)?.(chm|pdf)'
match = re.match(pt, docfn)
if match is not None:
pname = match.groups()[0]
if pname not in ('Python', ):
add_doc_action(pname, osp.join(sysdocpth, docfn))
# Documentation provided by Python(x,y), if available
try:
from xy.config import DOC_PATH as xy_doc_path
xydoc = osp.join(xy_doc_path, "Libraries")
def add_xydoc(text, pathlist):
for path in pathlist:
if osp.exists(path):
add_doc_action(text, path)
break
self.help_menu_actions.append(None)
add_xydoc(_("Python(x,y) documentation folder"),
[xy_doc_path])
add_xydoc(_("IPython documentation"),
[osp.join(xydoc, "IPython", "ipythondoc.chm")])
add_xydoc(_("guidata documentation"),
[osp.join(xydoc, "guidata", "guidatadoc.chm"),
r"D:\Python\guidata\build\doc_chm\guidatadoc.chm"])
add_xydoc(_("guiqwt documentation"),
[osp.join(xydoc, "guiqwt", "guiqwtdoc.chm"),
r"D:\Python\guiqwt\build\doc_chm\guiqwtdoc.chm"])
add_xydoc(_("Matplotlib documentation"),
[osp.join(xydoc, "matplotlib", "Matplotlibdoc.chm"),
osp.join(xydoc, "matplotlib", "Matplotlib.pdf")])
add_xydoc(_("NumPy documentation"),
[osp.join(xydoc, "NumPy", "numpy.chm")])
add_xydoc(_("NumPy reference guide"),
[osp.join(xydoc, "NumPy", "numpy-ref.pdf")])
add_xydoc(_("NumPy user guide"),
[osp.join(xydoc, "NumPy", "numpy-user.pdf")])
add_xydoc(_("SciPy documentation"),
[osp.join(xydoc, "SciPy", "scipy.chm"),
osp.join(xydoc, "SciPy", "scipy-ref.pdf")])
self.help_menu_actions.append(None)
except (ImportError, KeyError, RuntimeError):
pass
# Online documentation
web_resources = QMenu(_("Web Resources"))
web_resources.setIcon(get_icon("browser.png"))
add_actions(web_resources,
create_module_bookmark_actions(self, self.BOOKMARKS))
self.help_menu_actions.append(web_resources)
# IPython frontend action
if is_module_installed('IPython', '>=0.12'):
ipf_action = create_action(self, _("New IPython frontend..."),
icon="ipython.png",
triggered=self.new_ipython_frontend)
self.interact_menu_actions += [None, ipf_action]
# Third-party plugins
# eMZed: disabled due to version conflicts with winpython
# distribution !
#for mod in get_spyderplugins_mods(prefix='p_', extension='.py'):
#try:
#plugin = mod.PLUGIN_CLASS(self)
#self.thirdparty_plugins.append(plugin)
#plugin.register_plugin()
#except AttributeError, error:
#print >>STDERR, "%s: %s" % (mod, str(error))
# View menu
self.windows_toolbars_menu = QMenu(_("Windows and toolbars"), self)
self.connect(self.windows_toolbars_menu, SIGNAL("aboutToShow()"),
self.update_windows_toolbars_menu)
self.view_menu.addMenu(self.windows_toolbars_menu)
reset_layout_action = create_action(self, _("Reset window layout"),
triggered=self.reset_window_layout)
quick_layout_menu = QMenu(_("Custom window layouts"), self)
ql_actions = []
for index in range(1, 4):
if index > 0:
ql_actions += [None]
qli_act = create_action(self,
_("Switch to/from layout %d") % index,
triggered=lambda i=index:
self.quick_layout_switch(i))
self.register_shortcut(qli_act, "_",
"Switch to/from layout %d" % index,
"Shift+Alt+F%d" % index)
qlsi_act = create_action(self, _("Set layout %d") % index,
triggered=lambda i=index:
self.quick_layout_set(i))
self.register_shortcut(qlsi_act, "_",
"Set layout %d" % index,
"Ctrl+Shift+Alt+F%d" % index)
ql_actions += [qli_act, qlsi_act]
add_actions(quick_layout_menu, ql_actions)
if set_attached_console_visible is not None:
cmd_act = create_action(self,
_("Attached console window (debugging)"),
toggled=set_attached_console_visible)
cmd_act.setChecked(is_attached_console_visible())
add_actions(self.view_menu, (None, cmd_act))
add_actions(self.view_menu, (None, self.maximize_action,
self.fullscreen_action, None,
reset_layout_action, quick_layout_menu,
None, self.close_dockwidget_action))
# EMZED: removed:
# Adding external tools action to "Tools" menu
#external_tools_act = create_action(self, _("External Tools"),
#icon="ext_tools.png")
#external_tools_act.setMenu(self.external_tools_menu)
#self.tools_menu_actions.append(external_tools_act)
#self.main_toolbar_actions.append(external_tools_act)
# Filling out menu/toolbar entries:
add_actions(self.file_menu, self.file_menu_actions)
add_actions(self.edit_menu, self.edit_menu_actions)
add_actions(self.search_menu, self.search_menu_actions)
add_actions(self.source_menu, self.source_menu_actions)
add_actions(self.run_menu, self.run_menu_actions)
add_actions(self.interact_menu, self.interact_menu_actions)
add_actions(self.tools_menu, self.tools_menu_actions)
add_actions(self.external_tools_menu,
self.external_tools_menu_actions)
add_actions(self.help_menu, self.help_menu_actions)
add_actions(self.main_toolbar, self.main_toolbar_actions)
add_actions(self.file_toolbar, self.file_toolbar_actions)
add_actions(self.edit_toolbar, self.edit_toolbar_actions)
add_actions(self.search_toolbar, self.search_toolbar_actions)
add_actions(self.source_toolbar, self.source_toolbar_actions)
add_actions(self.run_toolbar, self.run_toolbar_actions)
# Apply all defined shortcuts (plugins + 3rd-party plugins)
self.apply_shortcuts()
# Emitting the signal notifying plugins that main window menu and
# toolbar actions are all defined:
self.emit(SIGNAL('all_actions_defined()'))
# Window set-up
self.debug_print("Setting up window...")
self.setup_layout(default=False)
# EMZED ADD ON : splash screen occurs at leas for 2 seconds:
import time
while (time.time()-self.splash_started) < 2.0:
time.sleep(0.1)
self.splash.hide()
# Enabling tear off for all menus except help menu
for child in self.menuBar().children():
if isinstance(child, QMenu) and child != self.help_menu:
child.setTearOffEnabled(True)
# Menu about to show
for child in self.menuBar().children():
if isinstance(child, QMenu):
self.connect(child, SIGNAL("aboutToShow()"),