Make life easier with defaultdict and list comprehensions
svn: r16169
This commit is contained in:
parent
86bc6f6979
commit
e8b87b5f00
@ -34,6 +34,7 @@ Manages the main window and the pluggable views
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
from collections import defaultdict
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
@ -1475,10 +1476,7 @@ class ViewManager(CLIManager):
|
|||||||
Toggles media include values in the quick backup dialog.
|
Toggles media include values in the quick backup dialog.
|
||||||
"""
|
"""
|
||||||
include = widget.get_active()
|
include = widget.get_active()
|
||||||
if include:
|
extension = "gpkg" if include else "gramps"
|
||||||
extension = "gpkg"
|
|
||||||
else:
|
|
||||||
extension = "gramps"
|
|
||||||
filename = file_entry.get_text()
|
filename = file_entry.get_text()
|
||||||
if "." in filename:
|
if "." in filename:
|
||||||
base, ext = filename.rsplit(".", 1)
|
base, ext = filename.rsplit(".", 1)
|
||||||
@ -1758,7 +1756,7 @@ def get_available_views():
|
|||||||
"""
|
"""
|
||||||
pmgr = GuiPluginManager.get_instance()
|
pmgr = GuiPluginManager.get_instance()
|
||||||
view_list = pmgr.get_reg_views()
|
view_list = pmgr.get_reg_views()
|
||||||
viewstoshow = {}
|
viewstoshow = defaultdict(list)
|
||||||
for pdata in view_list:
|
for pdata in view_list:
|
||||||
mod = pmgr.load_plugin(pdata)
|
mod = pmgr.load_plugin(pdata)
|
||||||
if not mod or not hasattr(mod, pdata.viewclass):
|
if not mod or not hasattr(mod, pdata.viewclass):
|
||||||
@ -1774,27 +1772,22 @@ def get_available_views():
|
|||||||
pdata.authors_email else '...'})
|
pdata.authors_email else '...'})
|
||||||
continue
|
continue
|
||||||
viewclass = getattr(mod, pdata.viewclass)
|
viewclass = getattr(mod, pdata.viewclass)
|
||||||
|
|
||||||
# pdata.category is (string, trans-string):
|
# pdata.category is (string, trans-string):
|
||||||
if pdata.category[0] in viewstoshow:
|
if pdata.order == START:
|
||||||
if pdata.order == START:
|
viewstoshow[pdata.category[0]].insert(0, (pdata, viewclass) )
|
||||||
viewstoshow[pdata.category[0]].insert(0, ((pdata, viewclass)))
|
|
||||||
else:
|
|
||||||
viewstoshow[pdata.category[0]].append((pdata, viewclass))
|
|
||||||
else:
|
else:
|
||||||
viewstoshow[pdata.category[0]] = [(pdata, viewclass)]
|
viewstoshow[pdata.category[0]].append( (pdata, viewclass) )
|
||||||
|
|
||||||
resultorder = []
|
|
||||||
# First, get those in order defined, if exists:
|
# First, get those in order defined, if exists:
|
||||||
for item in config.get("interface.view-categories"):
|
resultorder = [viewstoshow[cat]
|
||||||
if item in viewstoshow:
|
for cat in config.get("interface.view-categories")
|
||||||
resultorder.append(viewstoshow[item])
|
if cat in viewstoshow]
|
||||||
|
|
||||||
# Next, get the rest in some order:
|
# Next, get the rest in some order:
|
||||||
viewstoshow_names = viewstoshow.keys()
|
resultorder.extend(viewstoshow[cat]
|
||||||
viewstoshow_names.sort()
|
for cat in sorted(viewstoshow.keys())
|
||||||
for item in viewstoshow_names:
|
if viewstoshow[cat] not in resultorder)
|
||||||
if viewstoshow[item] in resultorder:
|
|
||||||
continue
|
|
||||||
resultorder.append(viewstoshow[item])
|
|
||||||
return resultorder
|
return resultorder
|
||||||
|
|
||||||
def views_to_show(views, use_last=True):
|
def views_to_show(views, use_last=True):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user