Plugins/WizardPlugins/DotDesktopWizard/DotDesktopListSelectionDialog.py

Thu, 10 Jan 2019 14:18:48 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 10 Jan 2019 14:18:48 +0100
changeset 6645
ad476851d7e0
parent 6048
82ad8ec9548c
permissions
-rw-r--r--

Updated copyright for 2019.

6017
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
6645
ad476851d7e0 Updated copyright for 2019.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
3 # Copyright (c) 2013 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
6017
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a dialog to select multiple entries from a list.
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from __future__ import unicode_literals
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 from PyQt5.QtWidgets import QDialog, QListWidgetItem, QAbstractItemView
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 from .Ui_DotDesktopListSelectionDialog import Ui_DotDesktopListSelectionDialog
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 class DotDesktopListSelectionDialog(QDialog, Ui_DotDesktopListSelectionDialog):
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 """
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 Class implementing a dialog to select multiple entries from a list.
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 """
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 def __init__(self, entries, selectedEntries, separator, subEntries=None,
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 allowMultiMain=True, allowMultiSub=True, parent=None):
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 Constructor
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 @param entries list of entries to be shown (list of string)
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 @param selectedEntries list of entries to be selected (list of string
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 or string of entries separated by separator)
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 @param separator separator string (string)
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 @param subEntries secondary list of entries (list of string)
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 @param allowMultiMain flag indicating to allow multiple selections for
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 the main entry (bool)
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 @param allowMultiSub flag indicating to allow multiple selections for
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 the sub entry (bool)
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 @param parent reference to the parent widget (QWidget)
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 """
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 super(DotDesktopListSelectionDialog, self).__init__(parent)
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 self.setupUi(self)
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 if isinstance(selectedEntries, str):
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 selectedEntries = selectedEntries.split(separator)
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 if not allowMultiMain:
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 self.entriesList.setSelectionMode(
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 QAbstractItemView.SingleSelection)
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 if not allowMultiSub:
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 self.subList.setSelectionMode(
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 QAbstractItemView.SingleSelection)
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 for entry in entries:
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 itm = QListWidgetItem(entry, self.entriesList)
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 if entry in selectedEntries:
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 itm.setSelected(True)
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 if subEntries:
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 for entry in subEntries:
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 itm = QListWidgetItem(entry, self.subList)
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 if entry in selectedEntries:
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 itm.setSelected(True)
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 else:
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 self.subList.setVisible(False)
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 def getData(self, separator=None, separatorAtEnd=False):
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 """
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 Public method to extract the selected entries as a list
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 or a string.
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 @param separator separator string (string)
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 @param separatorAtEnd flag indicating to append the separator (boolean)
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 @return list of selected entries (list of string) if the separator is
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 None or a string with entries delimited by separator (string)
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 """
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 entries = []
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 for itm in self.entriesList.selectedItems():
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 entries.append(itm.text())
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 for itm in self.subList.selectedItems():
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 entries.append(itm.text())
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 if separator is None:
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 return entries
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 else:
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 entriesStr = separator.join(entries)
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 if separatorAtEnd:
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 entriesStr += separator
dab01678626d Added the .desktop wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 return entriesStr

eric ide

mercurial