本文整理汇总了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
开发者ID:chrisbiggar,项目名称:shiny-light,代码行数:27,代码来源:layout.py
示例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
开发者ID:swindy,项目名称:sy-game,代码行数:57,代码来源:scrollable.py
示例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)
开发者ID:swindy,项目名称:sy-game,代码行数:11,代码来源:frame.py
示例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
开发者ID:swindy,项目名称:sy-game,代码行数:11,代码来源:frame.py
示例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)
开发者ID:dagophil,项目名称:cardgame,代码行数:32,代码来源:card_game_view.py
示例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
开发者ID:chrisbiggar,项目名称:shiny-light,代码行数:14,代码来源:frame.py
示例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 = []
开发者ID:chrisbiggar,项目名称:shiny-light,代码行数:16,代码来源:layout.py
示例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
开发者ID:dagophil,项目名称:cardgame,代码行数:60,代码来源:login_view.py
示例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()]
开发者ID:chrisbiggar,项目名称:shiny-light,代码行数:20,代码来源:layout.py
示例10: teardown
def teardown(self):
for row in self.content:
for cell in row:
cell.teardown()
self.content = []
Widget.teardown(self)
开发者ID:chrisbiggar,项目名称:shiny-light,代码行数:6,代码来源:layout.py
示例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)
开发者ID:chrisbiggar,项目名称:shiny-light,代码行数:6,代码来源:layout.py
示例12: delete
def delete(self):
"""Deletes graphic elements within the Wrapper."""
if self.content is not None:
self.content.delete()
Widget.delete(self)
开发者ID:chrisbiggar,项目名称:shiny-light,代码行数:5,代码来源:frame.py
示例13: teardown
def teardown(self):
self.content.teardown()
self.content = None
Widget.teardown(self)
开发者ID:chrisbiggar,项目名称:shiny-light,代码行数:4,代码来源:frame.py
注:本文中的widgets.Widget类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论