Skip to content

Commit

Permalink
core.config, gui.main: add New from template submenu
Browse files Browse the repository at this point in the history
  • Loading branch information
oaubert committed Nov 29, 2024
1 parent 82cfb5e commit 2dedd00
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 15 deletions.
8 changes: 6 additions & 2 deletions lib/advene/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Config:
@ivar namespace: the XML namespace for Advene extensions.
@ivar templatefilename: the filename for the XML template file
@ivar templates: dict (alias, filename) for the template files
@ivar preferences: the GUI preferences
@type preferences: dict
Expand Down Expand Up @@ -217,7 +217,11 @@ def __init__ (self):
self.namespace = "http://experience.univ-lyon1.fr/advene/ns/advenetool"

# These files are stored in the resources directory
self.templatefilename = "template.azp"
self.templates = {
'basic': "template.azp",
'remind': "remind-template.azp",
'ada': "ada-template.azp"
}

# Generic options
# They are automatically saved across sessions
Expand Down
10 changes: 6 additions & 4 deletions lib/advene/core/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1947,7 +1947,7 @@ def shortcut_evaluateValue(element, expr):
color = self.get_element_color(container)
return color

def load_package (self, uri=None, alias=None, activate=True):
def load_package (self, uri=None, alias=None, activate=True, template=None):
"""Load a package.
This method is esp. used as a callback for webserver. If called
Expand All @@ -1962,11 +1962,13 @@ def load_package (self, uri=None, alias=None, activate=True):
uri = helper.path2uri(uri)
if uri is None or uri == "":
try:
if template is None:
template = config.data.advenefile(config.data.templates['basic'])
self.package = Package (uri="new_pkg",
source=config.data.advenefile(config.data.templatefilename))
source=template)
except Exception:
logger.error(_("Cannot find the template package %(filename)s")
% {'filename': config.data.advenefile(config.data.templatefilename)}, exc_info=True)
% {'filename': template}, exc_info=True)

alias='new_pkg'
self.package = Package (alias, source=None)
Expand Down Expand Up @@ -2864,7 +2866,7 @@ def update_admin_views_from_template(self):
"""Automatically merge admin views from template package.
"""
template = Package (uri="new_pkg",
source=config.data.advenefile(config.data.templatefilename))
source=config.data.advenefile(config.data.templates['basic']))
differ = Differ(template, self.package)
diff = list(differ.diff())
counter = { 'update_content': 0,
Expand Down
2 changes: 1 addition & 1 deletion lib/advene/gui/edit/transcribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,7 @@ def notify(self, *p, **kw):
#controller.package = Package (uri=sys.argv[1])
config.data.path['resources']= Path('/usr/local/src/advene-project/share')
controller.package = Package (uri="new_pkg",
source=config.data.advenefile(config.data.templatefilename))
source=config.data.advenefile(config.data.templates['basic']))

transcription = TranscriptionEdit(controller=controller)

Expand Down
32 changes: 24 additions & 8 deletions lib/advene/gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,12 @@ def __init__(self, application_id="org.advene.application",
self.menu_definition=(
(_("_File"), (
("", # Empty label -> section (and not submenu)
(( _("_New package"), 'app.new-package', _("Create a new package"), 'new'),
(( _("_New package"), (
( _("Standard template"), 'app.new-package', _("Create a new package with the standard template"), 'new-basic'),
( _("REMIND template"), 'app.new-package-remind', _("Create a new package with the REMIND template"), 'new-remind'),
( _("AdA template"), 'app.new-package-ada', _("Create a new package with the AdA template"), 'new-ada')
),
"", ""),
( _("_Open package"), 'app.open-dialog', _("Open a package"), 'open' ),
( _("Open recent"), RecentFilesMenu(
Gtk.RecentManager.get_default(),
Expand Down Expand Up @@ -3805,13 +3810,24 @@ def on_win_key_press_event (self, win=None, event=None):
def on_new1_activate (self, button=None, data=None):
"""New package. Erase the current one.
"""
if 'new_pkg' in self.controller.packages:
# An unsaved template package already exists.
# Ask to save it first.
dialog.message_dialog(_("An unsaved template package exists\nSave it first."))
else:
self.set_busy_cursor(True)
self.controller.load_package ()
self.set_busy_cursor(True)
self.controller.load_package ()
return True

@named_action(name="app.new-package-remind")
def on_new_remind_activate (self, button=None, data=None):
"""New package with REMIND template.
"""
self.set_busy_cursor(True)
self.controller.load_package (template=config.data.advenefile(config.data.templates['remind']))
return True

@named_action(name="app.new-package-ada")
def on_new_ada_activate (self, button=None, data=None):
"""New package with AdA template.
"""
self.set_busy_cursor(True)
self.controller.load_package (template=config.data.advenefile(config.data.templates['ada']))
return True

@named_action(name="app.close")
Expand Down
Binary file added share/ada-template.azp
Binary file not shown.

0 comments on commit 2dedd00

Please sign in to comment.