Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Floating pallette ?? To help with testing (Pythonista v1.5)
-
I wanted to ask if there is a way or example code to make a version of a floating pallette. In my case at the moment, I don't want it for production code although I could see it would be great.
I want it for testing my code. I keep trying to cram ui.ButtonItems into the title bar for testing certain parts of my code. If I could have a smaller window with buttons on it That I could use to trigger my code would be great(just callback actions I set). Also would help me to seperate my so called production code from my testing code.If this is out of the question for v1.5, could this be done with v1.6
-
import ui ui.View().present() # the application's main view ui.View().present('popover') # a popover is kinda like a floating pallet over other views
-
Hmmmm, thanks @ccc. Will try that.... Sometimes, it's staring you right in the face....not sure why I didn't think about that. Not sure it will work, but very cool if it does.
-
Been going just over 10 hours today, time to call it a night. But I am getting there with the code. Will finish it tomorrow afternoon, Thai Time :)
# coding: utf-8 import ui _COLS = 4 _ROWS = 4 _BTN_H = 64 _BTN_W = 64 class task_bar(ui.View): def __init__(self, frame): self.frame = frame self.btn_callbacks= [0] * (_COLS *_ROWS) 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() print self.btn_callbacks 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): print sender.name ind = int(sender.name) if self.btn_callbacks[ind]: func = self.btn_callbacks[ind] func(self, sender) if __name__ == '__main__': frame = (0,0, _COLS * _BTN_W, (_ROWS * _BTN_H) -44) tb = task_bar(frame) tb.present('popover', hide_title_bar = True )
-
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()