-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymbolViewController.py
159 lines (131 loc) · 5.69 KB
/
symbolViewController.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
from enum import Enum
from pyrubicon.objc.api import ObjCClass, ObjCInstance
from pyrubicon.objc.api import objc_method
from pyrubicon.objc.runtime import send_super, objc_id
from pyrubicon.objc.types import NSInteger
from rbedge.enumerations import (
UIImageSymbolWeight,
UIImageSymbolScale,
)
from rbedge import pdbr
from caseElement import CaseElement
from pyLocalizedString import localizedString
from baseTableViewController import BaseTableViewController
from storyboard.symbolViewController import prototypes
UIImage = ObjCClass('UIImage')
UIImageSymbolConfiguration = ObjCClass('UIImageSymbolConfiguration')
UIColor = ObjCClass('UIColor')
# Cell identifier for each SF Symbol table view cell.
class SymbolKind(Enum):
plainSymbol = 'plainSymbol'
tintedSymbol = 'tintedSymbol'
largeSizeSymbol = 'largeSizeSymbol'
hierarchicalColorSymbol = 'hierarchicalColorSymbol'
paletteColorsSymbol = 'paletteColorsSymbol'
preferringMultiColorSymbol = 'preferringMultiColorSymbol'
class SymbolViewController(BaseTableViewController):
@objc_method
def initWithStyle_(self, style: NSInteger) -> ObjCInstance:
send_super(__class__,
self,
'initWithStyle:',
style,
restype=objc_id,
argtypes=[
NSInteger,
])
self.setupPrototypes_(prototypes)
return self
# MARK: - View Life Cycle
@objc_method
def viewDidLoad(self):
send_super(__class__, self, 'viewDidLoad') # xxx: 不要?
self.navigationItem.title = localizedString('SymbolsTitle') if (
title := self.navigationItem.title) is None else title
self.testCells_extend([
CaseElement(localizedString('PlainSymbolTitle'),
SymbolKind.plainSymbol.value, self.configurePlainSymbol_),
CaseElement(localizedString('TintedSymbolTitle'),
SymbolKind.tintedSymbol.value, self.configureTintedSymbol_),
CaseElement(localizedString('LargeSymbolTitle'),
SymbolKind.largeSizeSymbol.value,
self.configureLargeSizeSymbol_),
])
if True: # wip: `available(iOS 15, *)`
# These type SF Sybols, and variants are available on iOS 15, Mac Catalyst 15 or later.
self.testCells_extend([
CaseElement(localizedString('HierarchicalSymbolTitle'),
SymbolKind.hierarchicalColorSymbol.value,
self.configureHierarchicalSymbol_),
CaseElement(localizedString('PaletteSymbolTitle'),
SymbolKind.paletteColorsSymbol.value,
self.configurePaletteColorsSymbol_),
CaseElement(localizedString('PreferringMultiColorSymbolTitle'),
SymbolKind.preferringMultiColorSymbol.value,
self.configurePreferringMultiColorSymbol_),
])
# MARK: - UITableViewDataSource
@objc_method
def tableView_heightForRowAtIndexPath_(self, tableView, indexPath) -> float:
cellTest = self.testCells[indexPath.section]
cell = tableView.dequeueReusableCellWithIdentifier_(cellTest.cellID)
return cell.contentView.bounds.size.height
# MARK: - Configuration
@objc_method
def configurePlainSymbol_(self, imageView):
image = UIImage.systemImageNamed_('cloud.sun.rain.fill')
imageView.image = image
@objc_method
def configureTintedSymbol_(self, imageView):
image = UIImage.systemImageNamed_('cloud.sun.rain.fill')
imageView.image = image
imageView.tintColor = UIColor.systemPurpleColor()
@objc_method
def configureLargeSizeSymbol_(self, imageView):
image = UIImage.systemImageNamed_('cloud.sun.rain.fill')
imageView.image = image
symbolConfig = UIImageSymbolConfiguration.configurationWithPointSize_weight_scale_(
32.0, UIImageSymbolWeight.heavy, UIImageSymbolScale.large)
imageView.preferredSymbolConfiguration = symbolConfig
# @available(iOS 15.0, *)
@objc_method
def configureHierarchicalSymbol_(self, imageView):
imageConfig = UIImageSymbolConfiguration.configurationWithHierarchicalColor_(
UIColor.systemRedColor())
hierarchicalSymbol = UIImage.systemImageNamed_('cloud.sun.rain.fill')
imageView.image = hierarchicalSymbol
imageView.preferredSymbolConfiguration = imageConfig
# @available(iOS 15.0, *)
@objc_method
def configurePaletteColorsSymbol_(self, imageView):
palleteSymbolConfig = UIImageSymbolConfiguration.configurationWithPaletteColors_(
[
UIColor.systemRedColor(),
UIColor.systemOrangeColor(),
UIColor.systemYellowColor(),
])
palleteSymbol = UIImage.systemImageNamed_('battery.100.bolt')
imageView.image = palleteSymbol
imageView.backgroundColor = UIColor.darkTextColor()
imageView.preferredSymbolConfiguration = palleteSymbolConfig
# @available(iOS 15.0, *)
@objc_method
def configurePreferringMultiColorSymbol_(self, imageView):
preferredSymbolConfig = UIImageSymbolConfiguration.configurationPreferringMulticolor(
)
preferredSymbol = UIImage.systemImageNamed_('circle.hexagongrid.fill')
imageView.image = preferredSymbol
imageView.preferredSymbolConfiguration = preferredSymbolConfig
if __name__ == '__main__':
from rbedge.functions import NSStringFromClass
from rbedge.enumerations import (
UITableViewStyle,
UIModalPresentationStyle,
)
from rbedge import present_viewController
table_style = UITableViewStyle.grouped
main_vc = SymbolViewController.alloc().initWithStyle_(table_style)
_title = NSStringFromClass(SymbolViewController)
main_vc.navigationItem.title = _title
presentation_style = UIModalPresentationStyle.fullScreen
present_viewController(main_vc, presentation_style)