Convert gui.views to use abstract base classes
This commit is contained in:
parent
534eafef83
commit
620d43a544
@ -26,6 +26,7 @@
|
||||
# Standard python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from io import StringIO
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
@ -74,7 +75,7 @@ BTM = '''</menu></menubar></ui>'''
|
||||
|
||||
DISABLED = -1
|
||||
|
||||
class Bookmarks:
|
||||
class Bookmarks(metaclass=ABCMeta):
|
||||
"Handle the bookmarks interface for Gramps."
|
||||
|
||||
def __init__(self, dbstate, uistate, callback=None):
|
||||
@ -113,17 +114,17 @@ class Bookmarks:
|
||||
self.connect_signals()
|
||||
self.update_bookmarks()
|
||||
|
||||
@abstractmethod
|
||||
def connect_signals(self):
|
||||
"""
|
||||
Connect the person-delete signal
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
def get_bookmarks(self):
|
||||
"""
|
||||
Retrieve bookmarks from the database.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def update_bookmarks(self):
|
||||
"""
|
||||
@ -184,20 +185,20 @@ class Bookmarks:
|
||||
self.uistate.uimanager.ensure_update()
|
||||
text.close()
|
||||
|
||||
@abstractmethod
|
||||
def make_label(self, handle):
|
||||
"""
|
||||
Returns a (label, object) tuple appropriate to the type of the object
|
||||
that the handle refers to. The label is a text for the object, e.g. the
|
||||
object name.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
def callback(self, handle):
|
||||
"""
|
||||
Returns a unique call to a function with the associated handle. The
|
||||
function that will be called is defined in the derived class
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def add(self, person_handle):
|
||||
"""Append the person to the bottom of the bookmarks."""
|
||||
|
@ -29,6 +29,7 @@ Provide the base classes for GRAMPS' DataView classes
|
||||
# python modules
|
||||
#
|
||||
#----------------------------------------------------------------
|
||||
from abc import abstractmethod
|
||||
import pickle
|
||||
import time
|
||||
import logging
|
||||
@ -1095,42 +1096,35 @@ class ListView(NavigationView):
|
||||
####################################################################
|
||||
# Template functions
|
||||
####################################################################
|
||||
def get_bookmarks(self):
|
||||
"""
|
||||
Template function to get bookmarks.
|
||||
We could implement this in the NavigationView
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
def edit(self, obj, data=None):
|
||||
"""
|
||||
Template function to allow the editing of the selected object
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
def remove(self, handle, data=None):
|
||||
"""
|
||||
Template function to allow the removal of an object by its handle
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
def add(self, obj, data=None):
|
||||
"""
|
||||
Template function to allow the adding of a new object
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
def merge(self, obj, data=None):
|
||||
"""
|
||||
Template function to allow the merger of two objects.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
def remove_object_from_handle(self, handle):
|
||||
"""
|
||||
Template function to allow the removal of an object by its handle
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def open_all_nodes(self, obj):
|
||||
"""
|
||||
|
@ -28,6 +28,7 @@ Provide the base classes for GRAMPS' DataView classes
|
||||
# python modules
|
||||
#
|
||||
#----------------------------------------------------------------
|
||||
from abc import abstractmethod
|
||||
import logging
|
||||
|
||||
_LOG = logging.getLogger('.navigationview')
|
||||
@ -216,12 +217,12 @@ class NavigationView(PageView):
|
||||
if handle and not hobj.lock and not (handle == hobj.present()):
|
||||
hobj.push(handle)
|
||||
|
||||
@abstractmethod
|
||||
def goto_handle(self, handle):
|
||||
"""
|
||||
Needs to be implemented by classes derived from this.
|
||||
Used to move to the given handle.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def selected_handles(self):
|
||||
"""
|
||||
@ -457,50 +458,19 @@ class NavigationView(PageView):
|
||||
####################################################################
|
||||
# Template functions
|
||||
####################################################################
|
||||
def get_bookmarks(self):
|
||||
"""
|
||||
Template function to get bookmarks.
|
||||
We could implement this here based on navigation_type()
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def edit(self, obj):
|
||||
"""
|
||||
Template function to allow the editing of the selected object
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def remove(self, handle):
|
||||
"""
|
||||
Template function to allow the removal of an object by its handle
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def add(self, obj):
|
||||
"""
|
||||
Template function to allow the adding of a new object
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def remove_object_from_handle(self, handle):
|
||||
"""
|
||||
Template function to allow the removal of an object by its handle
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
def build_tree(self):
|
||||
"""
|
||||
Rebuilds the current display. This must be overridden by the derived
|
||||
class.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
def build_widget(self):
|
||||
"""
|
||||
Builds the container widget for the interface. Must be overridden by the
|
||||
the base class. Returns a gtk container widget.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def key_press_handler(self, widget, event):
|
||||
"""
|
||||
|
@ -27,6 +27,7 @@ Provide the base class for GRAMPS' DataView classes
|
||||
# python modules
|
||||
#
|
||||
#----------------------------------------------------------------
|
||||
from abc import ABCMeta, abstractmethod
|
||||
import logging
|
||||
_LOG = logging.getLogger('.pageview')
|
||||
|
||||
@ -57,7 +58,7 @@ from ..actiongroup import ActionGroup
|
||||
# PageView
|
||||
#
|
||||
#------------------------------------------------------------------------------
|
||||
class PageView(DbGUIElement):
|
||||
class PageView(DbGUIElement, metaclass=ABCMeta):
|
||||
"""
|
||||
The PageView class is the base class for all Data Views in GRAMPS. All
|
||||
Views should derive from this class. The ViewManager understands the public
|
||||
@ -312,12 +313,12 @@ class PageView(DbGUIElement):
|
||||
self.bottombar.set_inactive()
|
||||
self.active = False
|
||||
|
||||
@abstractmethod
|
||||
def build_tree(self):
|
||||
"""
|
||||
Rebuilds the current display. This must be overridden by the derived
|
||||
class.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def ui_definition(self):
|
||||
"""
|
||||
@ -389,12 +390,12 @@ class PageView(DbGUIElement):
|
||||
self.top = self.build_interface()
|
||||
return self.top
|
||||
|
||||
@abstractmethod
|
||||
def build_widget(self):
|
||||
"""
|
||||
Builds the container widget for the main view pane. Must be overridden
|
||||
by the base class. Returns a gtk container widget.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def define_actions(self):
|
||||
"""
|
||||
@ -473,40 +474,6 @@ class PageView(DbGUIElement):
|
||||
"""
|
||||
self.uistate.clear_filter_results()
|
||||
|
||||
def edit(self, obj):
|
||||
"""
|
||||
Template function to allow the editing of the selected object
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def remove(self, handle):
|
||||
"""
|
||||
Template function to allow the removal of an object by its handle
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def remove_object_from_handle(self, handle):
|
||||
"""
|
||||
Template function to allow the removal of an object by its handle
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def add(self, obj):
|
||||
"""
|
||||
Template function to allow the adding of a new object
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def _key_press(self, obj, event):
|
||||
"""
|
||||
Define the action for a key press event
|
||||
"""
|
||||
# TODO: This is never used? (replaced in ListView)
|
||||
if event.keyval in (Gdk.KEY_Return, Gdk.KEY_KP_Enter):
|
||||
self.edit(obj)
|
||||
return True
|
||||
return False
|
||||
|
||||
def on_delete(self):
|
||||
"""
|
||||
Method called on shutdown. Data views should put code here
|
||||
@ -569,7 +536,7 @@ class PageView(DbGUIElement):
|
||||
|
||||
:return: list of functions
|
||||
"""
|
||||
raise NotImplementedError
|
||||
return []
|
||||
|
||||
def configure(self):
|
||||
"""
|
||||
|
@ -346,6 +346,12 @@ class BasePersonView(ListView):
|
||||
|
||||
self.uistate.set_busy_cursor(False)
|
||||
|
||||
def remove_object_from_handle(self, handle):
|
||||
"""
|
||||
The remove_selected_objects method is not called in this view.
|
||||
"""
|
||||
pass
|
||||
|
||||
def define_actions(self):
|
||||
"""
|
||||
Required define_actions function for PageView. Builds the action
|
||||
|
@ -75,6 +75,12 @@ class DashboardView(PageView):
|
||||
self.dbstate, self.uistate)
|
||||
return self.widget
|
||||
|
||||
def build_tree(self):
|
||||
"""
|
||||
Rebuilds the current display.
|
||||
"""
|
||||
pass
|
||||
|
||||
def get_stock(self):
|
||||
"""
|
||||
Return image associated with the view, which is used for the
|
||||
|
@ -281,6 +281,12 @@ class FamilyView(ListView):
|
||||
trans.set_description(_("Family [%s]") % gramps_id)
|
||||
self.uistate.set_busy_cursor(False)
|
||||
|
||||
def remove_object_from_handle(self, handle):
|
||||
"""
|
||||
The remove_selected_objects method is not called in this view.
|
||||
"""
|
||||
pass
|
||||
|
||||
def edit(self, obj):
|
||||
for handle in self.selected_handles():
|
||||
family = self.dbstate.db.get_family_from_handle(handle)
|
||||
|
Loading…
Reference in New Issue
Block a user