E5Gui/E5Completers.py

changeset 55
b5c84934de9c
child 529
86332f558b7b
equal deleted inserted replaced
54:31463df17fd5 55:b5c84934de9c
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2007 - 2010 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing various kinds of completers.
8 """
9
10 from PyQt4.QtCore import QDir
11 from PyQt4.QtGui import QCompleter, QDirModel, QStringListModel
12
13 class E5FileCompleter(QCompleter):
14 """
15 Class implementing a completer for file names.
16 """
17 def __init__(self, parent = None,
18 completionMode = QCompleter.PopupCompletion,
19 showHidden = False):
20 """
21 Constructor
22
23 @param parent parent widget of the completer (QWidget)
24 @keyparam completionMode completion mode of the
25 completer (QCompleter.CompletionMode)
26 @keyparam showHidden flag indicating to show hidden entries as well (boolean)
27 """
28 QCompleter.__init__(self, parent)
29 self.__model = QDirModel(self)
30 if showHidden:
31 self.__model.setFilter(\
32 QDir.Filters(QDir.Dirs | QDir.Files | QDir.Drives | \
33 QDir.AllDirs | QDir.Hidden))
34 else:
35 self.__model.setFilter(\
36 QDir.Filters(QDir.Dirs | QDir.Files | QDir.Drives | QDir.AllDirs))
37 self.setModel(self.__model)
38 self.setCompletionMode(completionMode)
39 if parent:
40 parent.setCompleter(self)
41
42 class E5DirCompleter(QCompleter):
43 """
44 Class implementing a completer for directory names.
45 """
46 def __init__(self, parent = None,
47 completionMode = QCompleter.PopupCompletion,
48 showHidden = False):
49 """
50 Constructor
51
52 @param parent parent widget of the completer (QWidget)
53 @keyparam completionMode completion mode of the
54 completer (QCompleter.CompletionMode)
55 @keyparam showHidden flag indicating to show hidden entries as well (boolean)
56 """
57 QCompleter.__init__(self, parent)
58 self.__model = QDirModel(self)
59 if showHidden:
60 self.__model.setFilter(\
61 QDir.Filters(QDir.Drives | QDir.AllDirs | QDir.Hidden))
62 else:
63 self.__model.setFilter(\
64 QDir.Filters(QDir.Drives | QDir.AllDirs))
65 self.setModel(self.__model)
66 self.setCompletionMode(completionMode)
67 if parent:
68 parent.setCompleter(self)
69
70 class E5StringListCompleter(QCompleter):
71 """
72 Class implementing a completer for strings lists.
73 """
74 def __init__(self, parent = None, strings = [],
75 completionMode = QCompleter.PopupCompletion):
76 """
77 Constructor
78
79 @param parent parent widget of the completer (QWidget)
80 @param strings list of string to load into the completer (list of strings)
81 @keyparam completionMode completion mode of the
82 completer (QCompleter.CompletionMode)
83 """
84 QCompleter.__init__(self, parent)
85 self.__model = QStringListModel(strings, parent)
86 self.setModel(self.__model)
87 self.setCompletionMode(completionMode)
88 if parent:
89 parent.setCompleter(self)

eric ide

mercurial