1 """
2 Overview
3 ========
4 The data guessing module was created so that functions in in the dock widget would make somewhat intelligent
5 guesses at what the user might want to use ahead of time. This functionality is negelcted if the user wants it to
6 be, however, even guesses it does make are overwritable. This is purely meant as a time saver for users.
7 """
8
9 import PyQt4.QtGui
10
11 import re
12
13
14
15
16
17
19 """
20 Overview
21 ========
22 This function will take the name provided and produce a regular expression that accepts
23 strings very similar to the name provided. The regular expression may start with a number,
24 underscore, or nothing. Then it must contain the name provided, in any mixture of capital and
25 lower case letters. Finally it may end with a number or underscore, or nothing of course.
26
27 @param name: The name which you want turned into a regular expression.
28 @type name: string
29
30 @return: _sre.SRE_Pattern, a compiled regular expression retrieved from the I{re.compile ()} method.
31 """
32
33
34
35 nameInv = name.swapcase ()
36 nameFinal = ""
37 for index in xrange (len (name)):
38 nameFinal += "[" + name[index] + nameInv[index] + "]"
39
40
41
42
43 return re.compile (r"^(\b|[0-9_])" + nameFinal + r"(\b|[0-9_])")
44
46 """
47 Overview
48 ========
49 This function is currently the exact same as L{GenerateRegExpFromName<GenerateRegExpFromName>}. Originally
50 there was going to be a distinction in the types of regular expression objects returned. As of now, the
51 appropriate dock widgets still make use of this method, so if a compiled regular expression is ever desired,
52 only this function must be changed.
53
54 @param word: The word which you want turned into a regular expression.
55 @type word: string
56
57 @return: _sre.SRE_Pattern, a compiled regular expression retrieved from the I{re.compile ()} method.
58 """
59
60
61
62 wordInv = word.swapcase ()
63 wordFinal = ""
64 for index in xrange (len (word)):
65 wordFinal += "[" + word[index] + wordInv[index] + "]"
66
67
68
69 return re.compile (r"(\b|[0-9_])" + wordFinal + r"(\b|[0-9_])")
70
72 """
73 Overview
74 ========
75 This function takes a DockWidget and a list of regular expressions. It will run down the Basin Object Tree,
76 attempting to add any object that fits into the regular expression. When that occurs, it starts at the top
77 the Basin Object Tree again and does the same for the second regular expression until all of the regular
78 expressions have been tried. Normal rules apply for adding objects to a Dock Widget's Holder. This means
79 that if the first two regular expressions find objects with different parents lists, the second will kick
80 the first one out.
81
82 @param object: This is the dock widget for which the guesses are being made on.
83 @type object: L{DockWidget<DockWidget>}
84
85 @param guessList: A list of all the compiled regular expressions for which guesses are being made
86 @type guessList: list <_sre.SRE_Pattern>
87 """
88
89
90 object.clear ()
91 if ((not object._bridge._connected) and (not object._bridge._parallel)) or (not object._bridge._autoGuess):
92 return
93
94
95 iter = PyQt4.QtGui.QTreeWidgetItemIterator (object._bridge._regionViewer.top)
96 iter += 1
97
98 while iter.value ():
99
100 if len (guessList) == 0:
101 return
102
103 if guessList[0].search (str (iter.value ().text (0))):
104
105
106 guessList.pop (0)
107
108
109
110 object.DoubleClicked (iter.value ())
111
112 iter = PyQt4.QtGui.QTreeWidgetItemIterator (object._bridge._regionViewer.top)
113
114
115
116 iter += 1
117