Ok, I updated the code. Not the most compelling example or well written. Just suppose to be proof of concept. A lot more could be done to make it more functional as far as the taskbar goes. But regardless, I see new possibilities Inside an app other than just testing. Properties, settings etc...
Again, for some reason, I hadn't thought of using the popover in this manner. Thanks @ccc.
# coding: utf-8
import ui
_COLS = 4
_ROWS = 2
_BTN_H = 64
_BTN_W = 64
# simple idea for a floating pallete
# this could be done a lot better of course
# this is just a proof of concept
class task_bar(ui.View):
def __init__(self):
self.name = 'Task Bar'
self.frame = (0,0, _COLS * _BTN_W, (_ROWS * _BTN_H))
self.btn_callbacks= [0] * (_COLS *_ROWS)
#create the buttons
for i in range(_COLS * _ROWS):
btn = ui.Button(title = 'Task-' + str(i + 1))
btn.name = str(i)
btn.action = self.action
self.add_subview(btn)
self.style()
self.flex = 'WH'
def style(self):
for btn in self.subviews:
btn.background_color = 'red'
btn.border_width = .5
btn.tint_color = 'white'
btn.font = ('<system-bold>', 16)
def layout(self):
# thanks @ccc
for i, btn in enumerate(self.subviews):
btn.frame = (i % _COLS * _BTN_W, i / _COLS * _BTN_H, _BTN_W, _BTN_H)
def action(self, sender):
ind = int(sender.name)
if self.btn_callbacks[ind]:
func = self.btn_callbacks[ind]()
def show(self):
'''
i could not get it working properly with repeated calls to present, when hiding the menu bar of the pop up. each subsequent call added the height of the menu bar to the frame. i tried varioys things to combat this, but didnt get it correct.
'''
self.present('popover', hide_title_bar = False)
def set_task_button(self, btn_ind, title, func):
btn = self.subviews[btn_ind]
btn.title = title
self.btn_callbacks[btn_ind] = func
# this would be the class i am trying to test,
# calling methods etc, i dont have a ui for yet
class production(ui.View):
def __init__(self):
self.flex = 'WH'
self.tb = task_bar()
btn = ui.ButtonItem(title = 'task menu')
btn.action = self.menu_task
self.right_button_items =(btn,)
self.set_task_buttons()
self.create_ui_elements()
self.style()
def menu_task(self, sender):
self.tb.show()
def create_ui_elements(self):
for i in range(_COLS * _ROWS):
btn = ui.Button(title = 'btn-' + str(i + 1))
btn.name = str(i)
#btn.action = self.action
self.add_subview(btn)
def style(self):
for btn in self.subviews:
btn.background_color = 'lightblue'
btn.border_width = .5
btn.tint_color = 'white'
btn.font = ('<system_bold>', 18)
def layout(self):
w = self.width / _COLS
h = self.height / _ROWS
for i, btn in enumerate(self.subviews):
btn.frame = (i % _COLS * w, i / _COLS * h, w, h)
# stupid methods to call from the task bar
# the functions i would want to call when
# testing my code, when it doesnt yet have
# a wrapper class to run all the code
def hide_all_buttons(self):
for btn in self.subviews:
btn.hidden = True
def show_all_buttons(self):
for btn in self.subviews:
btn.hidden = False
#set the task buttons
def set_task_buttons(self):
tb = self.tb
tb.set_task_button(0, 'hide', self.hide_all_buttons)
tb.set_task_button(1,'show', self.show_all_buttons)
if __name__ == '__main__':
p = production().present()