Skip to content

Commit

Permalink
Migrate breakpoint plugin to new API
Browse files Browse the repository at this point in the history
  • Loading branch information
goanpeca committed Apr 14, 2020
1 parent f77be68 commit dc05959
Show file tree
Hide file tree
Showing 4 changed files with 338 additions and 184 deletions.
10 changes: 9 additions & 1 deletion spyder/app/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,15 @@ def create_edit_action(text, tr_text, icon):
# Load other plugins (former external plugins)
# TODO: Use this bucle to load all internall plugins and remove
# duplicated code
other_plugins = ['breakpoints', 'profiler', 'pylint']

# Breakpoints
if CONF.get('breakpoints', 'enable'):
from spyder.plugins.breakpoints.plugin import Breakpoints
self.breakpoints = Breakpoints(self, configuration=CONF)
self.register_plugin(self.breakpoints)
self.thirdparty_plugins.append(self.breakpoints)

other_plugins = ['profiler', 'pylint']
for plugin_name in other_plugins:
if CONF.get(plugin_name, 'enable'):
module = importlib.import_module(
Expand Down
16 changes: 16 additions & 0 deletions spyder/plugins/breakpoints/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2009- Spyder Project Contributors
#
# Distributed under the terms of the MIT License
# (see spyder/__init__.py for details)

# Standard library imports
from enum import Enum

# Local imports
from spyder.plugins.breakpoints.widgets.breakpointsgui import (
BreakpointTableActions)


class PluginActions(Enum):
ListBreakpoints = 'list_breakpoints'
142 changes: 80 additions & 62 deletions spyder/plugins/breakpoints/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,78 +19,96 @@
import os.path as osp

# Third party imports
from qtpy.QtCore import Signal
from qtpy.QtWidgets import QVBoxLayout

# Local imports
from spyder.config.base import _
from spyder.utils import icon_manager as ima
from spyder.utils.qthelpers import create_action
from spyder.api.plugins import SpyderPluginWidget
from spyder.api.translations import get_translation
from spyder.api.plugins import Plugins, SpyderDockablePlugin, ApplicationMenus
from spyder.plugins.breakpoints.api import PluginActions
from spyder.plugins.breakpoints.widgets.breakpointsgui import (
BreakpointWidget)

from .widgets.breakpointsgui import BreakpointWidget

_ = get_translation('spyder')

class Breakpoints(SpyderPluginWidget):
"""Breakpoint list"""
CONF_SECTION = 'breakpoints'
CONF_FILE = False

def __init__(self, parent=None):
"""Initialization."""
super().__init__(parent)

self.breakpoints = BreakpointWidget(self,
options_button=self.options_button)

layout = QVBoxLayout()
layout.addWidget(self.breakpoints)
self.setLayout(layout)

self.breakpoints.set_data()

path = osp.join(self.PLUGIN_PATH, self.IMG_PATH)
self.icon = ima.icon('breakpoints', icon_path=path)
class Breakpoints(SpyderDockablePlugin):
"""
Breakpoint list Plugin.
"""

# ----- SpyderPluginWidget API --------------------------------------------
def get_plugin_title(self):
"""Return widget title"""
NAME = 'breakpoints'
CONF_SECTION = NAME
CONF_FILE = False
REQUIRES = [Plugins.Editor]
TABIFY = Plugins.Help
WIDGET_CLASS = BreakpointWidget

# Signals
sig_clear_all_breakpoints_requested = Signal()
sig_clear_breakpoint_requested = Signal(str, int)
sig_edit_goto_requested = Signal(str, int, str)
sig_set_or_edit_conditional_breakpoint_requested = Signal()

# --- SpyderDockablePlugin API
# ------------------------------------------------------------------------
def get_name(self):
return _("Breakpoints")

def get_plugin_icon(self):
"""Return widget icon"""
return self.icon
def get_icon(self):
path = osp.join(self.get_path(), self.IMG_PATH)
return self.create_icon('breakpoints', path=path)

def register(self):
widget = self.get_widget()
editor = self.get_plugin(Plugins.Editor)

# TODO: change name of this signal
editor.breakpoints_saved.connect(self.set_data)
widget.sig_clear_all_breakpoints_requested.connect(
editor.clear_all_breakpoints)
widget.sig_clear_breakpoint_requested.connect(editor.clear_breakpoint)
widget.sig_edit_goto_requested.connect(editor.load)
widget.sig_set_or_edit_conditional_breakpoint_requested.connect(
editor.set_or_edit_conditional_breakpoint)

widget.sig_clear_all_breakpoints_requested.connect(
self.sig_clear_all_breakpoints_requested)
widget.sig_clear_breakpoint_requested.connect(
self.sig_clear_breakpoint_requested)
widget.sig_edit_goto_requested.connect(self.sig_edit_goto_requested)
widget.sig_set_or_edit_conditional_breakpoint_requested.connect(
self.sig_set_or_edit_conditional_breakpoint_requested)

list_action = self.create_action(
PluginActions.ListBreakpoints,
_("List breakpoints"),
triggered=lambda: self.switch_to_plugin(),
icon=self.get_icon(),
)

# TODO: Fix location once the sections are defined
debug_menu = self.get_application_menu(ApplicationMenus.Debug)
self.add_item_to_application_menu(list_action, debug_menu)
editor.pythonfile_dependent_actions += [list_action]

# --- API
# ------------------------------------------------------------------------
def set_data(self):
"""
Set breakpoint data on widget.
"""
self.get_widget().set_data(self.load_data())

def get_focus_widget(self):
def load_data(self):
"""
Return the widget to give focus to when
this plugin's dockwidget is raised on top-level
Load breakpoint data from configuration file.
"""
return self.breakpoints.dictwidget

def on_first_registration(self):
"""Action to be performed on first plugin registration"""
self.tabify(self.main.help)

def register_plugin(self):
"""Register plugin in Spyder's main window"""
self.breakpoints.edit_goto.connect(self.main.editor.load)
self.breakpoints.clear_all_breakpoints.connect(
self.main.editor.clear_all_breakpoints)
self.breakpoints.clear_breakpoint.connect(
self.main.editor.clear_breakpoint)
self.main.editor.breakpoints_saved.connect(self.breakpoints.set_data)
self.breakpoints.set_or_edit_conditional_breakpoint.connect(
self.main.editor.set_or_edit_conditional_breakpoint)

self.add_dockwidget()

list_action = create_action(self, _("List breakpoints"),
triggered=self.show, icon=self.icon)
list_action.setEnabled(True)
pos = self.main.debug_menu_actions.index('list_breakpoints')
self.main.debug_menu_actions.insert(pos, list_action)
self.main.editor.pythonfile_dependent_actions += [list_action]

def show(self):
"""Show the breakpoints dockwidget"""
self.switch_to_plugin()
breakpoints_dict = self.get_conf_option('breakpoints', default={},
section='run')
for filename in list(breakpoints_dict.keys()):
if not osp.isfile(filename):
breakpoints_dict.pop(filename)

return breakpoints_dict
Loading

0 comments on commit dc05959

Please sign in to comment.