1 """
2 An Example DataSource and DataType implementation.
3 """
4 import random
5 import logging
6 log = logging.getLogger("modules.Example")
7
8 import conduit
9 import conduit.Exceptions as Exceptions
10 import conduit.Utils as Utils
11 import conduit.datatypes.DataType as DataType
12 import conduit.dataproviders.DataProvider as DataProvider
13
14 MODULES = {
15 "ExampleDataProviderTwoWay" : { "type": "dataprovider" },
16 "ExampleConverter" : { "type": "converter" }
17 }
18
20 """
21 An example dataprovider demonstrating how to partition
22 funtionality in such a way
23 """
24
25 _name_ = "Example Dataprovider"
26 _description_ = "Demonstrates a Twoway Dataprovider"
27 _category_ = conduit.dataproviders.CATEGORY_MISC
28 _module_type_ = "twoway"
29 _in_type_ = "exampledata"
30 _out_type_ = "exampledata"
31 _icon_ = "applications-internet"
32
33 DEFAULT_FOO_VALUE = 42
34
36 """
37 Constructor should call the base constructor and initialize
38 all variables that are restored from configuration
39 """
40 DataProvider.TwoWay.__init__(self)
41 self.data = []
42 self.foo = 0
43
45 """
46 @returns: True if data at the LUID exists
47 """
48 return random.randint(0,1)
49
51 """
52 @returns: A ExampleDataType with the specified LUID
53 """
54 data = ExampleDataType(
55 uri=LUID,
56 data=self.foo*random.randint(1,100)
57 )
58 return data
59
61 """
62 @returns: Rid
63 """
64 data = ExampleDataType(
65 uri=random.randint(1,100),
66 data=self.foo*random.randint(1,100)
67 )
68 return data.get_rid()
69
71 """
72 Some dataproviders assign a new LUID when data is replaced. This
73 is the purpose of having replace in a different function to _put
74 """
75 data.set_UID(random.randint(1,100))
76 return data.get_rid()
77
96
97 items = [
98 {
99 "Name" : "Value of Foo:",
100 "Widget" : gtk.Entry,
101 "Callback" : set_foo,
102 "InitialValue" : str(self.foo)
103 }
104 ]
105
106 dialog = SimpleConfigurator.SimpleConfigurator(window, self._name_, items)
107
108 dialog.run()
109
111 """
112 The refresh method should do whatever is needed to ensure that a
113 subseqent call to get_all returns the correct result.
114
115 The refresh method is always called before the sync step. DataSources
116 should always call the base classes refresh() method.
117 """
118 DataProvider.TwoWay.refresh(self)
119 self.data = [str(random.randint(1,100)) for i in range(10)]
120
122 """
123 Returns the LUIDs of all items to synchronize.
124 DataSources should