A L{UiCollection} that supports searching for items in scrollable layout elements. This class can be used with horizontally or vertically scrollable controls.
| 2262 | |
| 2263 | |
| 2264 | class UiScrollable(UiCollection): |
| 2265 | """ |
| 2266 | A L{UiCollection} that supports searching for items in scrollable layout elements. |
| 2267 | |
| 2268 | This class can be used with horizontally or vertically scrollable controls. |
| 2269 | """ |
| 2270 | |
| 2271 | def __init__(self, view): |
| 2272 | self.vc = None |
| 2273 | self.view = view |
| 2274 | self.vertical = True |
| 2275 | self.bounds = view.getBounds() |
| 2276 | (self.x, self.y, self.w, self.h) = view.getPositionAndSize() |
| 2277 | self.steps = 10 |
| 2278 | self.duration = 800 |
| 2279 | self.swipeDeadZonePercentage = 0.1 |
| 2280 | self.maxSearchSwipes = 10 |
| 2281 | |
| 2282 | def flingBackward(self): |
| 2283 | if self.vertical: |
| 2284 | s = (self.x + self.w / 2, self.y + self.h * self.swipeDeadZonePercentage) |
| 2285 | e = (self.x + self.w / 2, self.y + self.h - self.h * self.swipeDeadZonePercentage) |
| 2286 | else: |
| 2287 | s = (self.x + self.w * self.swipeDeadZonePercentage, self.y + self.h / 2) |
| 2288 | e = (self.x + self.w * (1.0 - self.swipeDeadZonePercentage), self.y + self.h / 2) |
| 2289 | if DEBUG: |
| 2290 | print("flingBackward: view=", self.view.__smallStr__(), self.view.getPositionAndSize(), file=sys.stderr) |
| 2291 | print("self.view.device.drag(%s, %s, %s, %s)" % (s, e, self.duration, self.steps), file=sys.stderr) |
| 2292 | self.view.device.drag(s, e, self.duration, self.steps, self.view.device.display['orientation']) |
| 2293 | |
| 2294 | def flingForward(self): |
| 2295 | if self.vertical: |
| 2296 | s = (self.x + self.w / 2, (self.y + self.h) - self.h * self.swipeDeadZonePercentage) |
| 2297 | e = (self.x + self.w / 2, self.y + self.h * self.swipeDeadZonePercentage) |
| 2298 | else: |
| 2299 | s = (self.x + self.w * (1.0 - self.swipeDeadZonePercentage), self.y + self.h / 2) |
| 2300 | e = (self.x + self.w * self.swipeDeadZonePercentage, self.y + self.h / 2) |
| 2301 | if DEBUG: |
| 2302 | print("flingForward: view=", self.view.__smallStr__(), self.view.getPositionAndSize(), file=sys.stderr) |
| 2303 | print("self.view.device.drag(%s, %s, %s, %s)" % (s, e, self.duration, self.steps), file=sys.stderr) |
| 2304 | self.view.device.drag(s, e, self.duration, self.steps, self.view.device.display['orientation']) |
| 2305 | |
| 2306 | def flingToBeginning(self, maxSwipes=10): |
| 2307 | if self.vertical: |
| 2308 | for _ in range(maxSwipes): |
| 2309 | if DEBUG: |
| 2310 | print("flinging to beginning", file=sys.stderr) |
| 2311 | self.flingBackward() |
| 2312 | |
| 2313 | def flingToEnd(self, maxSwipes=10): |
| 2314 | if self.vertical: |
| 2315 | for _ in range(maxSwipes): |
| 2316 | if DEBUG: |
| 2317 | print("flinging to end", file=sys.stderr) |
| 2318 | self.flingForward() |
| 2319 | |
| 2320 | def scrollTextIntoView(self, text): |
| 2321 | """ |
no outgoing calls
no test coverage detected