-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
plugin.py
124 lines (101 loc) · 3.69 KB
/
plugin.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
# -*- coding: utf-8 -*-
#
# Copyright © Spyder Project Contributors
# Licensed under the terms of the MIT License
# (see spyder/__init__.py for details)
"""
Console History Plugin.
"""
# Third party imports
from qtpy.QtCore import Signal
# Local imports
from spyder.api.plugins import Plugins, SpyderDockablePlugin
from spyder.api.plugin_registration.decorators import (
on_plugin_available, on_plugin_teardown)
from spyder.api.translations import get_translation
from spyder.config.base import get_conf_path
from spyder.plugins.history.confpage import HistoryConfigPage
from spyder.plugins.history.widgets import HistoryWidget
# Localization
_ = get_translation('spyder')
class HistoryLog(SpyderDockablePlugin):
"""
History log plugin.
"""
NAME = 'historylog'
REQUIRES = [Plugins.Preferences, Plugins.Editor, Plugins.Console]
TABIFY = Plugins.IPythonConsole
WIDGET_CLASS = HistoryWidget
CONF_SECTION = NAME
CONF_WIDGET_CLASS = HistoryConfigPage
CONF_FILE = False
# --- Signals
# ------------------------------------------------------------------------
sig_focus_changed = Signal()
"""
This signal is emitted when the focus of the code editor storing history
changes.
"""
def __init__(self, parent=None, configuration=None):
"""Initialization."""
super().__init__(parent, configuration)
self.add_history(get_conf_path('history.py'))
# --- SpyderDockablePlugin API
# ------------------------------------------------------------------------
@staticmethod
def get_name():
return _('History')
def get_description(self):
return _('Provide command history for IPython Consoles')
def get_icon(self):
return self.create_icon('history')
def on_initialize(self):
widget = self.get_widget()
widget.sig_focus_changed.connect(self.sig_focus_changed)
@on_plugin_available(plugin=Plugins.Preferences)
def on_preferences_available(self):
preferences = self.get_plugin(Plugins.Preferences)
preferences.register_plugin_preferences(self)
@on_plugin_available(plugin=Plugins.Console)
def on_console_available(self):
console = self.get_plugin(Plugins.Console)
console.sig_refreshed.connect(self.refresh)
@on_plugin_teardown(plugin=Plugins.Preferences)
def on_preferences_teardown(self):
preferences = self.get_plugin(Plugins.Preferences)
preferences.deregister_plugin_preferences(self)
@on_plugin_teardown(plugin=Plugins.Console)
def on_console_teardown(self):
console = self.get_plugin(Plugins.Console)
console.sig_refreshed.disconnect(self.refresh)
def update_font(self):
color_scheme = self.get_color_scheme()
font = self.get_font()
self.get_widget().update_font(font, color_scheme)
# --- Plubic API
# ------------------------------------------------------------------------
def refresh(self):
"""
Refresh main widget.
"""
self.get_widget().refresh()
def add_history(self, filename):
"""
Create history file.
Parameters
----------
filename: str
History file.
"""
self.get_widget().add_history(filename)
def append_to_history(self, filename, command):
"""
Append command to history file.
Parameters
----------
filename: str
History file.
command: str
Command to append to history file.
"""
self.get_widget().append_to_history(filename, command)