def menu_button(self, title, action, diameter, center):
btn = ui.Button(
title=title,
action=action,
tint_color='white',
background_color=self.menu_color
)
btn.width = btn.height = diameter
btn.corner_radius = diameter/2
btn.center = center
self.menu.add_subview(btn)
# def menu_player_field(self, action, name, text, corner, width):
# (x,y) = corner
# fld = ui.TextField(
# action=action,
# name=name,
# text=text,
# tint_color='white',
# corner_radius=5,
# background_color=self.menu_color,
# frame=(x, y, width, 30)
# )
# self.menu.add_subview(fld)
python类Button()的实例源码
def __init__(self, spec):
super().__init__()
self.present('full_screen', hide_title_bar=True)
spec.append(('Cancel', None))
menu_content_height = len(spec) * (self.button_height + self.button_gap)
self.menu_height = min(menu_content_height, self.menu_max_height)
self.btns = []
for (i, (action_title, action_func)) in enumerate(spec):
action_wrapper = functools.partial(self.func_wrapper, action_func)
bg_color = '#e9e1e1' if action_func else '#4e4b4b'
tnt_color = 'black' if action_func else 'white'
btn = ui.Button(
title=action_title,
action=action_wrapper,
tint_color=tnt_color,
background_color=bg_color,
corner_radius=5
)
self.add_subview(btn)
self.btns.append(btn)
def new_button(self):
a_caption = 'Button' + '{:02d}'.format(self.count_objs)
self.count_objs += 1
mypage.unibutton((40, 80, 80, 40, a_caption))
a_button = mypage.unibuttons [-1]
a_button.color = a_button.background_color
if mypage.kivy:
a_button.bind(on_touch_move=self.touch_move)
a_button.bind(on_touch_down=self.touch_down)
else:
a_button.touch_enabled = False
a_button.color = a_button.background_color
a_button.pos = (a_button.x, a_button.y)
self.new_objs.append(a_button)
def new_button(self):
a_caption = 'Button' + '{:02d}'.format(self.count_objs)
self.count_objs += 1
mypage.unibutton((40, 80, 80, 40, a_caption))
a_button = mypage.unibuttons [-1]
a_button.color = a_button.background_color
if mypage.kivy:
a_button.bind(on_touch_move=self.touch_move)
a_button.bind(on_touch_down=self.touch_down)
else:
a_button.touch_enabled = False
a_button.color = a_button.background_color
a_button.pos = (a_button.x, a_button.y)
self.new_objs.append(a_button)
def demo_ChainedTransition():
v1 = ui.View(frame=(0, 0, 500, 500), background_color="pink")
v1.add_subview(ui.Button(frame=(100, 100, 300, 20)))
v1.subviews[0].title = "Hello! I'm a button"
v1.add_subview(ui.Slider(frame=(100, 300, 100, 20)))
v2 = ui.View(background_color="lightblue")
v2.add_subview(ui.ImageView(frame=(100, 100, 300, 300)))
v2.subviews[0].image = ui.Image.named('test:Peppers')
v3 = ui.View(background_color="lightgreen")
v3.add_subview(ui.Switch(frame=(100, 100, 20, 10)))
v3.subviews[0].value = True
t1 = ui2.Transition(v1, v2, ui2.TRANSITION_CURL_UP, 1.5)
t2 = ui2.Transition(v2, v3, ui2.TRANSITION_FLIP_FROM_LEFT, 1)
t3 = ui2.Transition(v3, v1, ui2.TRANSITION_CROSS_DISSOLVE, 1)
v1.present("sheet", hide_title_bar=True)
ui2.delay(ui2.ChainedTransition(t1, t2, t3).play, 1)
def __init__(self, app, cell, category_name, tool_name, tool_url):
self.app, self.cell = app, cell
self.category_name, self.tool_name, self.tool_url = category_name, tool_name, tool_url
self.btn = ui.Button()
self.cell.content_view.add_subview(self.btn)
self.btn.font = ('Helvetica', 12)
self.btn.background_color = 'white'
self.btn.border_width = 1
self.btn.corner_radius = 5
self.btn.size_to_fit()
self.btn.width = 58
self.btn.x = self.app.nav_view.width - self.btn.width - 8
self.btn.y = (self.cell.height - self.btn.height) / 2
if self.app.is_tool_installed(self.category_name, tool_name):
self.set_state_uninstall()
else:
self.set_state_install()
def __init__(self, default_user_name='Name'):
self.name = 'Enter your username:'
self.background_color = 0.40, 0.80, 1.00
self.frame=(0, 0, 500, 500)
self.label = ui.Label(frame=(12, 100, 2000, 55))
self.label.text = 'What is your name?'
self.label.text_color = 'black'
self.label.font = ('Avenir-Black', 55)
self.add_subview(self.label)
self.text_field = ui.TextField(frame=(155, 175, 200, 32))
self.text_field.text = default_user_name
self.text_field.text_color = 'grey'
self.text_field.clear_button_mode = 'while_editing'
self.add_subview(self.text_field)
button = ui.Button(background_color='white',
frame=(360, 175, 75, 36),
image=ui.Image.named('ionicons-arrow-right-a-32'))
self.add_subview(button)
def addbut(sender,toview):
root=sender
while root.superview:
root=root.superview
#add a button to parent view
import random,string
if root['switch'].value:
w=random.randrange(30,110)
h=random.randrange(20,75)
else:
w=40
h=40
title=string.ascii_letters[random.randint(0,26)]
for v in toview:
b=ui.Button(frame=(0,0,w,h),bg_color=(.8,.8,.8))
b.border_width=1
b.border_color=(0,0,0)
b.corner_radius=10
b.title=title
b.action=lambda sender:addbut(sender,toview)
v.add_subview(b)
def open_dialog(self,sender):
# expand out a view/dialog from sender
root=self.find_root(self.root)
overlay=ui.Button(frame=(0,0)+tuple(root.frame)[2:],bg_color=(0,0,0,0.25),name='overlay')
overlay.action=self.dispatch_cancel_action
finalframe=self.frame
self.width=5
overlay.add_subview(self)
root.add_subview(overlay)
def ani():
self.frame=finalframe
self.center=overlay.center
self.y=0
ui.animate(ani,0.15)
self.overlay=overlay
def create_new_window(root,sender):
v=ZoomView()
v.bg_color=0.90, 0.90, 0.90
v.border_color='grey'
v.border_width=2
v.x=random.randrange(75,300)
v.y=random.randrange(75,300)
v.width=v.height=300
closebutton=ui.Button(frame=(250,0,50,50), bg_color='grey')
closebutton.image=ui.Image.named('ionicons-close-round-32')
closebutton.flex='bl'
def closeview(sender):
sender.superview.superview.remove_subview(sender.superview)
closebutton.action=closeview
tv=ui.TextView()
tv.frame=(20,20,258,258)
tv.flex='wh'
v.add_subview(tv)
v.add_subview(closebutton)
root.add_subview(v)
def __init__(self,frame=(0,0,300,32),name='dropdown', items=[]):
'''Create a dropdown view, with items in list.
items can be either an iterable, or a function returning an iterable.
the function can be interrupted if it checks .abort(), which is set when user selects a row, for expensive ops like os.walk.
pressing the dropdown button brings up the list, which can be aborted by selecting an item
'''
self.frame=frame
self.textfield=ui.TextField(frame=frame,name='textfield')
self.textfield.autocapitalization_type=ui.AUTOCAPITALIZE_NONE
self.textfield.autocorrection_type=False
self.button=ui.Button(name='button',bg_color=None)
self.add_subview(self.textfield)
self.add_subview(self.button)
h=frame[3]
self.button.frame=(self.width-32, h-32, 32,32)
self.button.image=ui.Image.named('ionicons-arrow-down-b-32')
self.button.action=self.open_finder
self.base=os.path.expanduser('~/Documents')
self._abort=False
self.items=items
self.button.flex='l'
self.textfield.flex='w'
def stop_populating(self,sender):
console.hide_activity()
root=self.find_root()
self._abort=True
if not isinstance(sender,ui.Button):
#take no action
self.textfield.text=sender.items[ sender.selected_row]
def act():
if self.textfield.action:
self.textfield.action(self.textfield)
ui.delay(act,0.1)
def ani():
self.dialog.height=0
def cleanup():
root.remove_subview(root['overlay'])
ui.delay(cleanup,0.2)
ui.animate(ani,0.15)
def touch_ended(self,touch):
# dispatch whatever is under the touch
# for multitouch probably only want to execute when there are no active touches left.
# this method would need to clean out touches, but still keep info on the active gesture. when there are no active touches left, then kill the gesture
# for now.... just look under the touch, and call something appropriate.
# need to handle each ui type!
#print self.name, 'touch ended'
for s in self.subviews:
#probably need to check whether another view is on top...
if TouchDispatcher.hit(s,ui.convert_point(touch.location,self,s)):
if isinstance(s,ui.TextField):
#print '..textfield begin editing'
s.begin_editing()
#think about setting cursor.... HARD! but possible i think?
elif isinstance(s, ui.Button):
#print '..button launch'
s.action(s)
elif isinstance(s, TouchDispatcher):
# adjust touch location to subviews coordinates, then dispatch
# print '..touch end: dispatch: ', s.name
t=Touch(touch)
t.location=ui.convert_point(touch.location,self,s)
s.touch_ended(t)
def create_new_window(root,sender):
v=ZoomView()
v.bg_color=0.90, 0.90, 0.90
v.border_color='grey'
v.border_width=2
v.x=random.randrange(75,300)
v.y=random.randrange(75,300)
v.width=v.height=300
closebutton=ui.Button(frame=(250,0,50,50), bg_color='grey')
closebutton.image=ui.Image.named('ionicons-close-round-32')
closebutton.flex='bl'
def closeview(sender):
sender.superview.superview.remove_subview(sender.superview)
closebutton.action=closeview
tv=ui.TextView()
tv.frame=(20,20,258,258)
tv.flex='wh'
v.add_subview(tv)
v.add_subview(closebutton)
root.add_subview(v)
def __init__(self, elements, saveCallBack, addElementAction, saveFlowAction, runFlowAction, showElementRuntimeView, thememanager, flowType, flowTypeSelection):
self.flowType = flowType
self.elements = elements
self.saveCallBack = saveCallBack
self.flowTypeSelection = flowTypeSelection
self.showElementRuntimeView = showElementRuntimeView
self.extraRows = 2
self.adminRow = 0
self.typeRow = 1
self.title = ''
self.currentElementNumber = -1
self.addElementButton = ui.ButtonItem(title = 'Add Element', action = addElementAction)
self.saveFlowButton = ui.ButtonItem(title='Save', action=saveFlowAction)
self.runFlowButton = ui.ButtonItem(title='Run', action=runFlowAction)
self.titleButton = ui.Button(title='Change Title')
self.editButtonsRight = [self.addElementButton]
self.editButtonsLeft = [self.saveFlowButton]
self.runButtonsRight = [self.runFlowButton]
self.runButtonsLeft = []
self.thememanager = thememanager
def open_dialog(self,sender):
# expand out a view/dialog from sender
root=self.find_root(self.root)
overlay=ui.Button(frame=(0,0)+tuple(root.frame)[2:],bg_color=(0,0,0,0.25),name='overlay')
overlay.action=self.dispatch_cancel_action
finalframe=self.frame
self.width=5
overlay.add_subview(self)
root.add_subview(overlay)
def ani():
self.frame=finalframe
self.center=overlay.center
self.y=0
ui.animate(ani,0.15)
self.overlay=overlay
def __init__(self,frame=(0,0,300,32),name='dropdown', items=[]):
'''Create a dropdown view, with items in list.
items can be either an iterable, or a function returning an iterable.
the function can be interrupted if it checks .abort(), which is set when user selects a row, for expensive ops like os.walk.
pressing the dropdown button brings up the list, which can be aborted by selecting an item
'''
self.frame=frame
self.textfield=ui.TextField(frame=frame,name='textfield')
self.textfield.autocapitalization_type=ui.AUTOCAPITALIZE_NONE
self.textfield.autocorrection_type=False
self.button=ui.Button(name='button',bg_color=None)
self.add_subview(self.textfield)
self.add_subview(self.button)
h=frame[3]
self.button.frame=(self.width-32, h-32, 32,32)
self.button.image=ui.Image.named('ionicons-arrow-down-b-32')
self.button.action=self.open_finder
self.base=os.path.expanduser('~/Documents')
self._abort=False
self.items=items
self.button.flex='l'
self.textfield.flex='w'
def stop_populating(self,sender):
console.hide_activity()
root=self.find_root()
self._abort=True
if not isinstance(sender,ui.Button):
#take no action
self.textfield.text=sender.items[ sender.selected_row]
def act():
if self.textfield.action:
self.textfield.action(self.textfield)
ui.delay(act,0.1)
def ani():
self.dialog.height=0
def cleanup():
root.remove_subview(root['overlay'])
ui.delay(cleanup,0.2)
ui.animate(ani,0.15)
def init_size(self): # initialize with correct size when landscape orientation = ui.WebView(frame=(0,0,100,200)).eval_js('window.orientation') if orientation in (-90, 90): self.frame = (0, 0, self.height, self.width)
def did_load(self): self.init_buttons() self.init_webbrowser() self.init_addressbar() self.init_size() self.flex = 'WH' self.bookmarks = self.load_bookmarks() self.history = self.load_history() self.addressbar_is_editing = False self.webpage_has_loaded = False self.favourite_images = {True :ui.Image.named('ionicons-ios7-star-32'), False:ui.Image.named('ionicons-ios7-star-outline-32')}
def save_history(self, filename=filename_history): with open(filename, 'w') as f: url = self.get_url() if url in self.history: self.history.remove(url) self.history.append(url) f.seek(0) pickle.dump(self.history, f) def clear_history(self, sender, filename=filename_history): with open(filename, 'w') as f: self.history = [] f.seek(0) pickle.dump(self.history, f) sender.superview.superview['history'].data_source.items = self.history sender.superview.superview['history'].reload()
def save_bookmark(self, filename=filename_bookmarks): with open(filename, 'w') as f: url = self.get_url() title = self.get_title() or self.parse_url(url) self.bookmarks[title] = url f.seek(0) json.dump(self.bookmarks, f, indent=4) self['controlpanel']['favourite'].image = self.favourite_images[True]
def remove_bookmark(self, title=None, filename=filename_bookmarks): with open(filename, 'w') as f: title = title or self.get_title() del self.bookmarks[title] f.seek(0) json.dump(self.bookmarks, f, indent=4) self['controlpanel']['favourite'].image = self.favourite_images[False]
def popup_menu(self): popup = ui.View(name='menu', frame=(0, 0, 320, 500)) toolbar = ui.View(frame=(-5, 0, 330, 100), name='toolbar') toolbar.border_width = 0.5 toolbar.border_color = '#B2B2B2' label = ui.Label() label.text = 'Bookmarks' label.alignment = ui.ALIGN_CENTER label.frame = (0, 0, 320, 50) label.name = 'title' segment_ctrl = ui.SegmentedControl(name='segctrl') segment_ctrl.segments = ['Bookmarks', 'History'] segment_ctrl.width = 170 segment_ctrl.center = popup.center segment_ctrl.y = label.height segment_ctrl.selected_index = 0 segment_ctrl.action = self.bookmarks_or_history button = ui.Button() button.frame = (segment_ctrl.x*3.5, segment_ctrl.y, 60, 30) button.font = ('<system>', 15) button.title= 'Clear' button.name = 'clear' button.action = self.clear_history button.hidden = True toolbar.add_subview(label) toolbar.add_subview(segment_ctrl) toolbar.add_subview(button) popup.add_subview(toolbar) data_source = ui.ListDataSource(sorted(self.bookmarks.keys())) popup.add_subview(self.list_bookmarks_and_history(data_source, width=320,height=toolbar.superview.height-toolbar.height, y=toolbar.height, name='bookmarks')) x, y = self['controlpanel']['bookmarks'].center popup.present('popover', popover_location=(x, y), hide_title_bar=True)
def bookmarks_or_history(self, sender): toolbar = sender.superview if sender.selected_index == 0: toolbar['clear'].hidden = True toolbar['title'].text = 'Bookmarks' data_source = ui.ListDataSource(sorted(self.bookmarks.keys())) tv = self.list_bookmarks_and_history(data_source, width=320, height=toolbar.superview.height-toolbar.height, y=toolbar.height, name='bookmarks') toolbar.superview.remove_subview(toolbar.superview['history']) else: toolbar['clear'].hidden = False toolbar['title'].text = 'History' data_source = ui.ListDataSource(self.history[::-1]) tv = self.list_bookmarks_and_history(data_source, width=320, height=toolbar.superview.height-toolbar.height, y=toolbar.height, name='history') toolbar.superview['bookmarks'].hidden=True toolbar.superview.remove_subview(toolbar.superview['bookmarks']) sender.superview.superview.add_subview(tv)
def list_bookmarks_and_history(self, data_source, **kwargs): tv = ui.TableView() tv.data_source = data_source tv.delegate = self for k, v in kwargs.items(): setattr(tv, k, v) return tv
def show_more_menu(self): popup = ui.TableView() popup.width = 250 popup.height = 500 popup.name = 'More' popup.data_source = popup.delegate = self button = self['controlpanel']['more'] popup.present('popover', popover_location=(button.x, button.y+button.height))
def button_tapped(self, sender): if sender.name == 'favourite': if self.get_url() in self.bookmarks.values(): self.remove_bookmark() else: self.save_bookmark() elif sender.name == 'bookmarks': self.popup_menu() elif sender.name == 'more': self.show_more_menu() else: eval("self['webview'].{}()".format(sender.name))
def tableview_number_of_rows(self, tableview, section): if tableview.name == 'Bookmarks': return len(self.bookmarks) elif tableview.name == 'More': return 1
def tableview_cell_for_row(self, tableview, section, row): if tableview.name == 'Bookmarks': cell = ui.TableViewCell() cell.text_label.text = sorted(self.bookmarks.keys())[row] cell.image_view.image = ui.Image.named('ionicons-ios7-bookmarks-outline-32') cell.image_view.tint_color = '#66CCFF' return cell elif tableview.name == 'More': cell = ui.TableViewCell() cell.text_label.text = 'Settings' cell.image_view.image = ui.Image.named('ionicons-wrench-32') return cell
@ui.in_background def tableview_did_select(self, tableview, section, row): if tableview.name == 'bookmarks': url = self.bookmarks[sorted(self.bookmarks.keys())[row]] self.load_url(url) tableview.superview.close() elif tableview.name == 'history': url = tableview.data_source.items[row] tableview.superview.close() self.load_url(url) elif tableview.name == 'More': tableview.close() console.hud_alert('No settings yet...', 'error', 1)
def tableview_can_delete(self, tableview, section, row): return True
def tableview_delete(self, tableview, section, row): item = sorted(self.bookmarks.keys())[row] self.remove_bookmark(item) tableview.reload()
def textfield_did_begin_editing(self, textfield): self.addressbar_is_editing = True self.set_url() self['controlpanel']['reload'].hidden = True
def textfield_did_end_editing(self, textfield): self.addressbar_is_editing = False self['controlpanel']['reload'].hidden = False self.set_url()
def textfield_should_return(self, textfield): url = self['controlpanel']['addressbar'].text self.load_url(url) textfield.end_editing() return True
def webview_did_start_load(self, webview): self.webpage_has_loaded = False
def webview_did_finish_load(self, webview): if not self.addressbar_is_editing: self.set_url() self.webpage_has_loaded = True page_is_bookmarked = unicode(self.get_url()) in self.bookmarks.values() self['controlpanel']['favourite'].image = self.favourite_images[page_is_bookmarked] self.save_history()
def next_turn(self, sender=None):
self.turn += 1
try:
self.turn += self.active_players[self.turn:].index(True)
except ValueError:
winners = []
for i, layer in enumerate(self.play_layers):
if layer.waypoints_visited == len(layer.waypoints):
winners.append(i)
if len(winners) > 0:
msg = ''
for winner in winners:
msg += ' ' + self.colors[winner].capitalize()
console.alert('Winner', msg, button1='Ok', hide_cancel_button=True)
self.hide_all()
self.show_main_menu()
return
self.turn = self.active_players.index(True)
self.hide_play_menu()
if self.active_players.count(True) > 1:
turn_button = ui.Button(frame=self.bg.bounds, background_color=(0, 0, 0, 0.9))
turn_button.title = ' Tap to play'
turn_button.tint_color = self.colors[self.turn]
def turn_start_action(sender):
self.bg.remove_subview(turn_button)
self.play_layers[self.turn].start_turn()
turn_button.action = turn_start_action
self.bg.add_subview(turn_button)
turn_button.image = self.main_menu.icons['player'+str(self.turn)]
else:
self.play_layers[self.turn].start_turn()
def setup_bottom_menu(self, buttons):
bottom_menu_height = 40
(_, _, w, h) = self.bg.bounds
bottom_menu = EvenView(margin = 20)
bottom_menu.flex = 'WT'
bottom_menu.frame = (0, h - bottom_menu_height, w, bottom_menu_height)
bottom_menu.background_color = 'white'
self.bg.add_subview(bottom_menu)
for icon, func in buttons:
button = ui.Button(image = ui.Image.named(icon))
button.action = func
button.name = func.__name__
button.tint_color = self.menu_color
bottom_menu.add_subview(button)
return bottom_menu
def menu_color_button(self, name, color, icon, corner):
(x,y) = corner
#img = self.button_image('plf:AlienBlue_stand', 45)
#img = ui.Image.named(icon_name).with_rendering_mode(ui.RENDERING_MODE_ORIGINAL)
btn = ui.Button(
name=name,
action=self.toggle,
background_color=color
)
btn.frame=(x, y, 50, 50)
btn.corner_radius = 25
btn.image=icon
btn.background_color = tuple([btn.background_color[i] for i in range(3)]) + (0.8,)
self.menu.add_subview(btn)
return btn
# def button_image(self, name, max_dim):
# img = ui.Image.named(name)
# with io.BytesIO(img.to_png()) as fp:
# p_img = pilImage.open(fp)
# scale = max_dim/max(p_img.size)
# (w,h) = p_img.size
# target = (int(w*scale), int(h*scale))
# p_img = p_img.resize(target)
# with io.BytesIO() as fp:
# p_img.save(fp, 'PNG')
# result_img = ui.Image.from_data(fp.getvalue())
# return result_img.with_rendering_mode(ui.RENDERING_MODE_ORIGINAL)
def __init__(self, initial_width, initial_height, *args, **kwargs):
super().__init__(*args, **kwargs)
self._initial_width = initial_width
self._initial_height = initial_height
self.frame = (10, 100, 275, 250)
self.background_color = 'white'
self.img_width = ui.TextField(frame=(10, 30, 100, 25),
keyboard_type=ui.KEYBOARD_DECIMAL_PAD,
text=str(initial_width),
action=self.update_height)
self.add_subview(self.img_width)
width_label = ui.Label(frame=(10, 5, 150, 25), text='Image Width')
self.add_subview(width_label)
self.img_height = ui.TextField(frame=(150, 30, 100, 25),
keyboard_type=ui.KEYBOARD_DECIMAL_PAD,
text=str(initial_height),
action=self.update_width)
self.add_subview(self.img_height)
height_label = ui.Label(frame=(150, 5, 150, 25), text='Image Height')
self.add_subview(height_label)
aspect_ratio = self._initial_width / self._initial_height
self.aspect = ui.TextField(frame=(70, 100, 150, 25),
text=str(aspect_ratio),
keyboard_type=ui.KEYBOARD_DECIMAL_PAD,
alignment=ui.ALIGN_CENTER,
action=self.updatefrom_aspectratio)
self.add_subview(self.aspect)
aspect_label = ui.Label(frame=(70, 75, 150, 25),
text='Aspect',
alignment=ui.ALIGN_CENTER)
self.add_subview(aspect_label)
self.save_button = ui.Button(frame=(175, 150, 50, 25),
title='Save',
action=self.save)
self.add_subview(self.save_button)
self.cancel_button = ui.Button(frame=(30, 150, 50, 25),
title='Cancel',
action=self.cancel)
self.add_subview(self.cancel_button)
def __getDetailButtonForStatus(self, status, height, action, row):
img = ui.Image.named(self.__getDetailImageForStatus(status))
button = ui.Button()
button.image = img
size = img.size
ratio = size.y / size.x
button.height = height * 0.9
button.width = button.height * ratio
ca = CustomAction(button)
ca.action = self.action
ca.row = row
button.action = ca
return button
def __getDetailButtonForStatus(self, status, height, action, row):
img = ui.Image.named(self.__getDetailImageForStatus(status))
button = ui.Button()
button.image = img
size = img.size
ratio = size.y / size.x
button.height = height * 0.9
button.width = button.height * ratio
ca = CustomAction(button)
ca.action = self.action
ca.row = row
button.action = ca
return button
def __getDetailButtonForStatus(self, status, height, action, row):
img = ui.Image.named(self.__getDetailImageForStatus(status))
button = ui.Button()
button.image = img
size = img.size
ratio = size.y / size.x
button.height = height * 0.9
button.width = button.height * ratio
ca = CustomAction(button)
ca.action = self.action
ca.row = row
button.action = ca
return button
def __getDetailButtonForStatus(self, status, height, action, row):
img = ui.Image.named(self.__getDetailImageForStatus(status))
button = ui.Button()
button.image = img
size = img.size
ratio = size.y / size.x
button.height = height * 0.9
button.width = button.height * ratio
ca = CustomAction(button)
ca.action = self.action
ca.row = row
button.action = ca
return button
def __getDetailButtonForStatus(self, status, height, action, row):
img = ui.Image.named(self.__getDetailImageForStatus(status))
button = ui.Button()
button.image = img
size = img.size
ratio = size.y / size.x
button.height = height * 0.9
button.width = button.height * ratio
ca = CustomAction(button)
ca.action = self.action
ca.row = row
button.action = ca
return button
def unibutton(self, params):
self.unibuttons.append([])
if len(params) == 6:
function = params[5]
else:
function = nofunction
if self.kivy:
from kivy.uix.button import Button
self.unibuttons[len(self.unibuttons) - 1] = Button(
text = params[4],
size_hint_y = None,
size_hint_x = None,
height = params[3] * self.yratio,
width = params[2] * self.xratio,
font_size = 17.5 * self.yratio,
pos = (params[0] * self.xratio, params[1] * self.yratio),
on_press = function )
self.root.add_widget(self.unibuttons[len(self.unibuttons) - 1])
else:
import ui
self.unibuttons[len(self.unibuttons) - 1] = ui.Button(frame= \
(params[0] * self.xratio, (600 - params[1] - \
params[3]) * self.yratio, \
params[2] * self.xratio, params[3] * self.yratio), \
title = params[4])
self.unibuttons[len(self.unibuttons) - 1].background_color \
= (0.4,0.4,0.4)
self.unibuttons[len(self.unibuttons) - 1].action = function
self.unibuttons[len(self.unibuttons) - 1].height = params[3] * \
self.xratio
self.unibuttons[len(self.unibuttons) - 1].width = params[2] * \
self.yratio
self.unibuttons[len(self.unibuttons) - 1].tint_color = 'white'
self.root.add_subview(self.unibuttons[len(self.unibuttons) - 1])
def unibutton(self, params):
self.unibuttons.append([])
if len(params) == 6:
function = params[5]
else:
function = nofunction
if self.kivy:
from kivy.uix.button import Button
self.unibuttons[len(self.unibuttons) - 1] = Button(
text = params[4],
size_hint_y = None,
size_hint_x = None,
height = params[3] * self.yratio,
width = params[2] * self.xratio,
font_size = 17.5 * self.yratio,
pos = (params[0] * self.xratio, params[1] * self.yratio),
on_press = function )
self.root.add_widget(self.unibuttons[len(self.unibuttons) - 1])
else:
import ui
self.unibuttons[len(self.unibuttons) - 1] = ui.Button(frame= \
(params[0] * self.xratio, (600 - params[1] - \
params[3]) * self.yratio, \
params[2] * self.xratio, params[3] * self.yratio), \
title = params[4])
self.unibuttons[len(self.unibuttons) - 1].background_color \
= (0.4,0.4,0.4)
self.unibuttons[len(self.unibuttons) - 1].action = function
self.unibuttons[len(self.unibuttons) - 1].height = params[3] * \
self.xratio
self.unibuttons[len(self.unibuttons) - 1].width = params[2] * \
self.yratio
self.unibuttons[len(self.unibuttons) - 1].tint_color = 'white'
self.unibuttons[len(self.unibuttons) - 1].font = ('<system>', \
17.5 * self.yratio)
self.root.add_subview(self.unibuttons[len(self.unibuttons) - 1])