1
|
|
|
''' |
2
|
|
|
WARNING: deprecated module. |
3
|
|
|
|
4
|
|
|
API defined in this module has been deprecated in version 0.5 will likely be |
5
|
|
|
removed at 0.6. |
6
|
|
|
''' |
7
|
|
|
import warnings |
8
|
|
|
|
9
|
|
|
from markupsafe import Markup |
10
|
|
|
from flask import url_for |
11
|
|
|
|
12
|
|
|
from .compat import deprecated |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
warnings.warn('Deprecated module widget', category=DeprecationWarning) |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
class WidgetBase(object): |
19
|
|
|
_type = 'base' |
20
|
|
|
place = None |
21
|
|
|
|
22
|
|
|
@deprecated('Deprecated widget API') |
23
|
|
|
def __new__(cls, *args, **kwargs): |
24
|
|
|
return super(WidgetBase, cls).__new__(cls) |
25
|
|
|
|
26
|
|
|
def __init__(self, *args, **kwargs): |
27
|
|
|
self.args = args |
28
|
|
|
self.kwargs = kwargs |
29
|
|
|
|
30
|
|
|
def for_file(self, file): |
31
|
|
|
return self |
32
|
|
|
|
33
|
|
|
@classmethod |
34
|
|
|
def from_file(cls, file): |
35
|
|
|
if not hasattr(cls, '__empty__'): |
36
|
|
|
cls.__empty__ = cls() |
37
|
|
|
return cls.__empty__.for_file(file) |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
class LinkWidget(WidgetBase): |
41
|
|
|
_type = 'link' |
42
|
|
|
place = 'link' |
43
|
|
|
|
44
|
|
|
def __init__(self, text=None, css=None, icon=None): |
45
|
|
|
self.text = text |
46
|
|
|
self.css = css |
47
|
|
|
self.icon = icon |
48
|
|
|
super(LinkWidget, self).__init__() |
49
|
|
|
|
50
|
|
|
def for_file(self, file): |
51
|
|
|
if None in (self.text, self.icon): |
52
|
|
|
return self.__class__( |
53
|
|
|
file.name if self.text is None else self.text, |
54
|
|
|
self.css, |
55
|
|
|
self.icon if self.icon is not None else |
56
|
|
|
'dir-icon' if file.is_directory else |
57
|
|
|
'file-icon', |
58
|
|
|
) |
59
|
|
|
return self |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
class ButtonWidget(WidgetBase): |
63
|
|
|
_type = 'button' |
64
|
|
|
place = 'button' |
65
|
|
|
|
66
|
|
|
def __init__(self, html='', text='', css=''): |
67
|
|
|
self.content = Markup(html) if html else text |
68
|
|
|
self.css = css |
69
|
|
|
super(ButtonWidget, self).__init__() |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
class StyleWidget(WidgetBase): |
73
|
|
|
_type = 'stylesheet' |
74
|
|
|
place = 'style' |
75
|
|
|
|
76
|
|
|
@property |
77
|
|
|
def href(self): |
78
|
|
|
return url_for(*self.args, **self.kwargs) |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
class JavascriptWidget(WidgetBase): |
82
|
|
|
_type = 'script' |
83
|
|
|
place = 'javascript' |
84
|
|
|
|
85
|
|
|
@property |
86
|
|
|
def src(self): |
87
|
|
|
return url_for(*self.args, **self.kwargs) |
88
|
|
|
|