本文整理匯總了Python中widgets.Widget類的典型用法代碼示例。如果您正苦於以下問題:Python Widget類的具體用法?Python Widget怎麽用?Python Widget使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Widget類的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: layout
def layout(self, x, y):
"""
Lays out the child Widgets, in order from left to right.
@param x X coordinate of the lower left corner
@param y Y coordinate of the lower left corner
"""
Widget.layout(self, x, y)
# Expand any expandable content to our height
for item in self.content:
if item.is_expandable() and item.height < self.height:
item.expand(item.width, self.height)
left = x
if self.align == VALIGN_TOP:
for item in self.content:
item.layout(left, y + self.height - item.height)
left += item.width + self.padding
elif self.align == VALIGN_CENTER:
for item in self.content:
item.layout(left, y + self.height/2 - item.height/2)
left += item.width + self.padding
else: # VALIGN_BOTTOM
for item in self.content:
item.layout(left, y)
left += item.width + self.padding
示例2: size
def size(self, dialog):
"""
Recalculate the size of the Scrollable.
@param dialog Dialog which contains us
"""
if dialog is None:
return
Widget.size(self, dialog)
if self.is_fixed_size:
self.width, self.height = self.max_width, self.max_height
self.hscrollbar_height = dialog.theme["hscrollbar"]["left"]["image"].height
self.vscrollbar_width = dialog.theme["vscrollbar"]["up"]["image"].width
if self.root_group is None: # do we need to re-clone dialog groups?
self.theme = dialog.theme
self.batch = dialog.batch
self.root_group = ScrollableGroup(0, 0, self.width, self.height, parent=dialog.fg_group)
self.panel_group = pyglet.graphics.OrderedGroup(0, self.root_group)
self.bg_group = pyglet.graphics.OrderedGroup(1, self.root_group)
self.fg_group = pyglet.graphics.OrderedGroup(2, self.root_group)
self.highlight_group = pyglet.graphics.OrderedGroup(3, self.root_group)
Wrapper.delete(self) # force children to abandon old groups
Wrapper.size(self, self) # all children are to use our groups
if self.always_show_scrollbars or (self.max_width and self.width > self.max_width):
if self.hscrollbar is None:
self.hscrollbar = HScrollbar(self.max_width)
else:
if self.hscrollbar is not None:
self.hscrollbar.delete()
self.hscrollbar = None
if self.always_show_scrollbars or (self.max_height and self.height > self.max_height):
if self.vscrollbar is None:
self.vscrollbar = VScrollbar(self.max_height)
else:
if self.vscrollbar is not None:
self.vscrollbar.delete()
self.vscrollbar = None
self.width = min(self.max_width or self.width, self.width)
self.content_width = self.width
self.height = min(self.max_height or self.height, self.height)
self.content_height = self.height
if self.hscrollbar is not None:
self.hscrollbar.size(dialog)
self.hscrollbar.set(self.max_width, max(self.content.width, self.max_width))
self.height += self.hscrollbar.height
if self.vscrollbar is not None:
self.vscrollbar.size(dialog)
self.vscrollbar.set(self.max_height, max(self.content.height, self.max_height))
self.width += self.vscrollbar.width
示例3: layout
def layout(self, x, y):
"""
Assigns a new position to the Wrapper.
@param x X coordinate of the Wrapper's lower left corner
@param y Y coordinate of the Wrapper's lower left corner
"""
Widget.layout(self, x, y)
if self.content is not None:
x, y = GetRelativePoint(self, self.anchor, self.content, self.anchor, self.content_offset)
self.content.layout(x, y)
示例4: __init__
def __init__(self, content=None, is_expandable=False, anchor=ANCHOR_CENTER, offset=(0, 0)):
"""
Creates a new Wrapper around an included Widget.
@param content The Widget to be wrapped.
"""
Widget.__init__(self)
self.content = content
self.expandable = is_expandable
self.anchor = anchor
self.content_offset = offset
示例5: ask_tricks
def ask_tricks(self, n):
"""
Ask the user for the number of tricks.
:param n: the maximum number of tricks
"""
# Create the container with the fade in effect.
container = Widget((self.screen.get_width()/2-200, 100), (400, self.screen.get_height()-120), 40)
container.opacity = 0
container.add_action(actions.FadeInAction(0.5))
self._ask_tricks_widget = container
self._background_widget.add_widget(container)
# Create the question text.
text_w = special_widgets.warning_widget((0, 0), (400, 60), "How many tricks do you make?", self._font,
close_on_click=False)
text_w.visible = True
container.add_widget(text_w)
# Create the numbers.
class ChooseHandler(object):
def __init__(self, view, nn):
self._view = view
self._n = nn
def __call__(self, x, y):
self._view._handle_say_tricks(self._n)
for i in xrange(n+1):
size = (50, 50)
pos = ((i % 6) * (size[0]+20), 80 + (i/6) * (size[1] + 20))
w = special_widgets.warning_widget(pos, size, str(i), self._font, close_on_click=False)
w.visible = True
w.handle_clicked = ChooseHandler(self, i)
container.add_widget(w)
示例6: size
def size(self, dialog):
"""
The default Wrapper wraps up its Widget snugly.
@param dialog The Dialog which contains the Wrapper
"""
if dialog is None:
return
Widget.size(self, dialog)
if self.content is not None:
self.content.size(dialog)
self.width, self.height = self.content.width, self.content.height
else:
self.width = self.height = 0
示例7: __init__
def __init__(self, content=[], align=HALIGN_CENTER, padding=5):
"""
Creates a new VerticalLayout.
@param content A list of Widgets to be arranged
@param align HALIGN_LEFT if Widgets are to be left-justified,
HALIGN_CENTER if they should be centered, and
HALIGN_RIGHT if they are to be right-justified.
@param padding This amount of padding is inserted between widgets.
"""
assert isinstance(content, list) or isinstance(content, tuple)
Widget.__init__(self)
self.align = align
self.padding = padding
self.content = [x or Spacer() for x in content]
self.expandable = []
示例8: _create_widgets
def _create_widgets(self):
"""
Create the widgets and return the one that contains them all.
:return: the background widget
"""
# Create the background widget.
bg = self._rm.get_image(BACKGROUND_IMAGE, self.screen.get_size())
bg_widget = ImageWidget((0, 0), self.screen.get_size(), -1, bg)
# Create the container for the input widgets.
x = (self.screen.get_width() - INPUT_WIDTH - INPUT_PADDING[1] - INPUT_PADDING[3]) / 2
y = self.screen.get_height() / 2
w = INPUT_WIDTH + INPUT_PADDING[1] + INPUT_PADDING[3]
h = self.screen.get_height() - y
input_container = Widget((x, y), (w, h), 0)
bg_widget.add_widget(input_container)
# Create the input widgets.
username_input = TextInput(
(0, 0),
INPUT_WIDTH,
0,
self._font,
padding=INPUT_PADDING,
color=INPUT_FORE_COLOR,
fill=INPUT_FILL_COLOR,
default_text="username",
default_font=self._default_font,
)
host_input = copy.copy(username_input)
host_input.default_text = "host"
host_input.position = (0, INPUT_OFFSET)
port_input = copy.copy(username_input)
port_input.default_text = "port"
port_input.position = (0, 2 * INPUT_OFFSET)
input_container.add_widget(username_input)
input_container.add_widget(host_input)
input_container.add_widget(port_input)
self._text_inputs = {"username": username_input, "host": host_input, "port": port_input}
# Create the button widget.
btn = special_widgets.simple_button((0, 3 * INPUT_OFFSET), (w, 100), "Login", self._font)
def btn_clicked(x, y):
self._ev_manager.post(events.LoginRequestedEvent())
btn.handle_clicked = btn_clicked
input_container.add_widget(btn)
# Create the connection failed warning.
self._connection_failed_warning = special_widgets.warning_widget(
None, (400, 100), "Connection failed", self._font, screen_size=self.screen.get_size()
)
bg_widget.add_widget(self._connection_failed_warning)
self._username_taken_warning = special_widgets.warning_widget(
None, (400, 100), "Username already taken", self._font, screen_size=self.screen.get_size()
)
bg_widget.add_widget(self._username_taken_warning)
return bg_widget
示例9: size
def size(self, dialog):
"""
Calculates size of the layout, based on its children.
@param dialog The Dialog which contains the layout
"""
if dialog is None:
return
Widget.size(self, dialog)
height = 0
if len(self.content) < 2:
width = 0
else:
width = -self.padding
for item in self.content:
item.size(dialog)
height = max(height, item.height)
width += item.width + self.padding
self.width, self.height = width, height
self.expandable = [x for x in self.content if x.is_expandable()]
示例10: teardown
def teardown(self):
for row in self.content:
for cell in row:
cell.teardown()
self.content = []
Widget.teardown(self)
示例11: delete
def delete(self):
"""Deletes all graphic elements within the layout."""
for row in self.content:
for cell in row:
cell.delete()
Widget.delete(self)
示例12: delete
def delete(self):
"""Deletes graphic elements within the Wrapper."""
if self.content is not None:
self.content.delete()
Widget.delete(self)
示例13: teardown
def teardown(self):
self.content.teardown()
self.content = None
Widget.teardown(self)