Skip to content

Commit

Permalink
Widgets: Add section of methods that can be overridden to SidebarDialog
Browse files Browse the repository at this point in the history
Also, make another method private.
  • Loading branch information
ccordoba12 committed Jan 26, 2024
1 parent 21fdddb commit bdc913e
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions spyder/widgets/sidebardialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,35 @@ def __init__(self, parent=None):
buttons_box.clicked.connect(self.button_clicked)

# Add pages to the dialog
self.add_pages()
self._add_pages()

# Set index to the initial page
if self.PAGE_CLASSES:
self.set_current_index(0)

# ---- Public API to be overridden by children
# -------------------------------------------------------------------------
def button_clicked(self, button):
"""Actions to perform after one of the dialog's buttons is clicked."""
pass

def current_page_changed(self, index):
"""Actions to perform after the current page in the dialog changes."""
pass

def create_buttons(self):
"""
Create the buttons that will be displayed in the dialog.
Override this method if you want different buttons in it.
"""
bbox = QDialogButtonBox(QDialogButtonBox.Ok)

layout = QHBoxLayout()
layout.addWidget(bbox)

return bbox, layout

# ---- Public API
# -------------------------------------------------------------------------
def get_current_index(self):
Expand All @@ -214,12 +237,6 @@ def get_page(self, index=None) -> Optional[SidebarPage]:
if page and hasattr(page, 'widget'):
return page.widget()

def button_clicked(self, button):
pass

def current_page_changed(self, index):
pass

def add_separator(self):
"""Add a horizontal line to separate different sections."""
# Solution taken from https://stackoverflow.com/a/24819554/438386
Expand Down Expand Up @@ -283,27 +300,6 @@ def add_page(self, page: SidebarPage):
# Set font for items
item.setFont(self.items_font)

def add_pages(self):
"""Add pages to the dialog."""
for PageClass in self.PAGE_CLASSES:
page = PageClass(self)
page.initialize()
self.add_page(page)

def create_buttons(self):
"""
Create buttons to be displayed in the dialog.
You need to override this method if you want different buttons in the
dialog.
"""
bbox = QDialogButtonBox(QDialogButtonBox.Ok)

layout = QHBoxLayout()
layout.addWidget(bbox)

return bbox, layout

# ---- Qt methods
# -------------------------------------------------------------------------
def showEvent(self, event):
Expand Down Expand Up @@ -505,3 +501,10 @@ def _on_resize_event(self):
self._add_tooltips()
self._adjust_items_margin()
self._adjust_separators_width()

def _add_pages(self):
"""Add pages to the dialog."""
for PageClass in self.PAGE_CLASSES:
page = PageClass(self)
page.initialize()
self.add_page(page)

0 comments on commit bdc913e

Please sign in to comment.