-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtintedToolbarViewController.py
158 lines (130 loc) · 5.1 KB
/
tintedToolbarViewController.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
'''
note: Storyboard 実装なし
'''
import ctypes
from pathlib import Path
from pyrubicon.objc.api import ObjCClass, ObjCInstance, Block, NSData
from pyrubicon.objc.api import objc_method
from pyrubicon.objc.runtime import send_super, objc_id, SEL
from rbedge.enumerations import (
UIBarStyle,
UIBarButtonSystemItem,
)
from rbedge import pdbr
from pyLocalizedString import localizedString
UIViewController = ObjCClass('UIViewController')
NSLayoutConstraint = ObjCClass('NSLayoutConstraint')
UIColor = ObjCClass('UIColor')
UIBarButtonItem = ObjCClass('UIBarButtonItem')
NSURL = ObjCClass('NSURL')
UIImage = ObjCClass('UIImage')
UIActivityViewController = ObjCClass('UIActivityViewController')
class TintedToolbarViewController(UIViewController):
@objc_method
def dealloc(self):
# xxx: 呼ばない-> `send_super(__class__, self, 'dealloc')`
#print('\tdealloc')
pass
# MARK: - View Life Cycle
@objc_method
def viewDidLoad(self):
send_super(__class__, self, 'viewDidLoad')
self.navigationItem.title = localizedString('TintedToolbarTitle') if (
title := self.navigationItem.title) is None else title
self.view.backgroundColor = UIColor.systemBackgroundColor()
# See the `UIBarStyle` enum for more styles, including `.Default`.
self.navigationController.toolbar.setBarStyle_(UIBarStyle.black)
self.navigationController.toolbar.setTranslucent_(False)
self.navigationController.toolbar.setTintColor_(UIColor.systemGreenColor())
self.navigationController.toolbar.setBackgroundColor_(
UIColor.systemBlueColor())
# MARK: - `UIBarButtonItem` Creation and Configuration
refreshBarButtonItem = UIBarButtonItem.alloc().initWithBarButtonSystemItem(
UIBarButtonSystemItem.refresh,
target=self,
action=SEL('barButtonItemClicked:'))
# Note that there's no target/action since this represents empty space.
flexibleSpaceBarButtonItem = UIBarButtonItem.alloc(
).initWithBarButtonSystemItem(UIBarButtonSystemItem.flexibleSpace,
target=None,
action=None)
actionBarButtonItem = UIBarButtonItem.alloc().initWithBarButtonSystemItem(
UIBarButtonSystemItem.action,
target=self,
action=SEL('actionBarButtonItemClicked:'))
toolbarButtonItems = [
refreshBarButtonItem,
flexibleSpaceBarButtonItem,
actionBarButtonItem,
]
self.setToolbarItems_animated_(toolbarButtonItems, True)
self.navigationController.setToolbarHidden_(False)
@objc_method
def viewWillAppear_(self, animated: bool):
send_super(__class__,
self,
'viewWillAppear:',
animated,
argtypes=[
ctypes.c_bool,
])
#print('viewWillAppear')
@objc_method
def viewDidAppear_(self, animated: bool):
send_super(__class__,
self,
'viewDidAppear:',
animated,
argtypes=[
ctypes.c_bool,
])
#print('viewDidAppear')
@objc_method
def viewDidDisappear_(self, animated: bool):
send_super(__class__,
self,
'viewDidDisappear:',
animated,
argtypes=[
ctypes.c_bool,
])
#print('viewDidDisappear')
@objc_method
def didReceiveMemoryWarning(self):
send_super(__class__, self, 'didReceiveMemoryWarning')
print(f'{__class__}: didReceiveMemoryWarning')
# MARK: - Actions
@objc_method
def barButtonItemClicked_(self, barButtonItem):
print(
f'A bar button item on the tinted toolbar was clicked: {barButtonItem}.')
@objc_method
def actionBarButtonItemClicked_(self, barButtonItem):
# xxx: `lambda` の使い方が悪い
dataWithContentsOfURL = lambda path_str: NSData.dataWithContentsOfURL_(
NSURL.fileURLWithPath_(str(Path(path_str).absolute())))
image_path = './UIKitCatalogCreatingAndCustomizingViewsAndControls/UIKitCatalog/Assets.xcassets/Flowers_1.imageset/Flowers_1.png'
if (image :=
UIImage.alloc().initWithData_(dataWithContentsOfURL(image_path))):
activityItems = [
'Shared piece of text',
image,
]
activityViewController = UIActivityViewController.alloc(
).initWithActivityItems_applicationActivities_(activityItems, None)
if (popoverPresentationController :=
activityViewController.popoverPresentationController()) is not None:
# xxx: 挙動未確認
popoverPresentationController.barButtonItem = barButtonItem
self.presentViewController(activityViewController,
animated=True,
completion=None)
if __name__ == '__main__':
from rbedge.functions import NSStringFromClass
from rbedge.enumerations import UIModalPresentationStyle
from rbedge import present_viewController
main_vc = TintedToolbarViewController.new()
_title = NSStringFromClass(TintedToolbarViewController)
main_vc.navigationItem.title = _title
presentation_style = UIModalPresentationStyle.fullScreen
present_viewController(main_vc, presentation_style)