Hey Guys,
I have this code Example:
import ui
from anchors import SafeAreaView, dock, At, at, size_to_fit, flow
from objc_util import ObjCClass
def style(*views):
for v in views:
v.text_color = v.tint_color = v.border_color = 'yellow'
v.border_width = 1
v.alignment = ui.ALIGN_CENTER
return v
class main(SafeAreaView):
def __init__(self):
# Bildschirmgröße
self.WIDTH, self.HEIGHT = ui.get_screen_size()
self.main_content = ui.View(frame=self.bounds, flex='WH', bg_color='')
self.add_subview(self.main_content)
self.button_area = style(ui.View(name='button_area', bg_color=''))
dock(self.button_area).bottom(self.main_content, At.TIGHT)
at(self.button_area).height = at(self.button_area).fit_height
self.name = 'Barcode Scanner'
self.background_color = 'black'
self.present('fullscreen', hide_title_bar=True)
self.StartPage()
#FUNKTION StartPage
def StartPage(self):
user_button = size_to_fit(ui.Button(name='user_button', title='Kunden'))
user_button.action = self.sidebar_openClose
if user_button.image:
user_button.width = user_button.height
dock(user_button).bottom_center(self.button_area)
setting_button = size_to_fit(ui.Button(name='setting_button', title='Einstellungen'))
setting_button.action = self.sidebar_openClose
if setting_button.image:
setting_button.width = setting_button.height
dock(setting_button).bottom_right(self.button_area)
at(self.button_area).height = at(self.button_area).fit_height
#FUNKTION sidebar_openClose
def sidebar_openClose(self, sender):
if sender.name != 'close_button':
self.sidebar = style(ui.View(name='showSettingUser', width=150))
self.add_subview(self.sidebar)
at(self.sidebar).top = at(self.main_content).top
at(self.sidebar).bottom = at(self.main_content).bottom
at(self.sidebar).right = at(self.main_content).left
close_button = size_to_fit(ui.Button(name='close_button', title='Schließen'))
close_button.action = self.sidebar_openClose
dock(close_button).bottom_center(self.sidebar)
if sender.name == 'user_button':
USERS = [
'Name 1',
'Name 2',
'Name 3',
'Name 4',
'asjlkd kjashdgl',
'this is a long name',
'Hakuna Matata'
]
buttons = []
for i in USERS:
b = size_to_fit(ui.Button(name=i, title=i))
b.objc_instance.button().contentHorizontalAlignment=1
buttons.append(b)
flow(*buttons).from_left_down(self.sidebar)
elif sender.name == 'setting_button':
SETTINGS = [
'Einstellung 1',
'Einstellung 2',
'Einstellung 3',
'Einstellung 4'
]
buttons = [
size_to_fit(ui.Button(name=i, title=i))
for i in SETTINGS
]
flow(*buttons).from_left_down(self.sidebar)
if sender.name != 'close_button':
if self.main_content.x == 0:
self.main_content.x = -self.sidebar.x
elif sender.name == 'close_button':
if self['showSettingUser'] != None:
self.main_content.x = 0
self.remove_subview(self.sidebar)
if __name__ == '__main__':
main()
but when i run this and open and close 2 Sidebars the i get this error:
observeValueForKeyPath: <NSKeyValueObserving_ObjC: 0x283150010> <class 'AttributeError'> 'NoneType' object has no attribute 'bounds'
is in my code an issue or is this at all the right way to do this ?
Thanks
DavinE
EDIT:
another Question.. when i open the Sidebar my text are cutted... size_to_fix have no effect..
how can i fix this ?
(on my "Kunden" Button)