本文整理汇总了Python中fife.extensions.pychan.widgets.Icon类的典型用法代码示例。如果您正苦于以下问题:Python Icon类的具体用法?Python Icon怎么用?Python Icon使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Icon类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _draw
def _draw(self):
"""Draws the icon + bar."""
# hash buttons by creation function call
# NOTE: there may be problems with multiple buttons with the same
# images and helptext at the same time
create_btn = Callback(ImageButton, path=self.path, helptext=self.helptext)
self.button = None
if self.uncached:
self.button = create_btn()
else:
self.button = self.__widget_cache.get(create_btn, None)
if self.button is None: # create button
self.__widget_cache[create_btn] = self.button = create_btn()
else: # disconnect button from earlier layout
if self.button.parent:
self.button.parent.removeChild(self.button)
# can't cache the other instances, because we need multiple instances
# with the same data active at the same time
self.label = Label(text=self.text)
self.label.position = self.text_position
self.fill_bar = Icon(image="content/gui/images/tabwidget/green_line.png")
fill_level = (self.button.height * self.filled) // 100
self.fill_bar.size = ((2 * self.fill_bar.size[0]) // 3, fill_level)
# move fillbar down after resizing, since its origin is top aligned
self.fill_bar.position = (self.button.width, self.button.height - fill_level)
self.addChildren(self.button, self.fill_bar, self.label)
if self.marker > 0:
marker_icon = Icon(image="content/gui/icons/templates/production/marker.png")
marker_level = (self.button.height * self.marker) // 100
marker_icon.position = (self.button.width - 1, self.button.height - marker_level)
marker_icon.max_size = (5, 1)
self.addChild(marker_icon)
示例2: _init_tabs
def _init_tabs(self):
"""Add enough tabbuttons for all widgets."""
def on_tab_removal(tabwidget):
# called when a tab is being removed (via weakref since tabs shouldn't have references to the parent tabwidget)
# If one tab is removed, the whole tabwidget will die..
# This is easy usually the desired behavior.
if tabwidget():
tabwidget().on_remove()
# Load buttons
for index, tab in enumerate(self._tabs):
# don't add a reference to the
tab.add_remove_listener(Callback(on_tab_removal, weakref.ref(self)))
container = Container(name="container_%s" % index)
background = Icon(name="bg_%s" % index)
button = ImageButton(name=str(index), size=(50, 50))
if self.current_tab is tab:
background.image = tab.button_background_image_active
button.path = tab.path_active
else:
background.image = tab.button_background_image
button.path = tab.path
button.capture(Callback(self._show_tab, index))
if hasattr(tab, 'helptext') and tab.helptext is not None:
button.helptext = tab.helptext
container.size = background.size
container.addChild(background)
container.addChild(button)
self.content.addChild(container)
self.widget.size = (50, 55*len(self._tabs))
self.widget.adaptLayout()
self._apply_layout_hack()
示例3: show_tooltip
def show_tooltip(self):
if not self.helptext:
return
# recreate full tooltip since new text needs to be relayouted
if self.gui is None:
self.gui = load_uh_widget('tooltip.xml')
else:
self.gui.removeAllChildren()
translated_tooltip = _(self.helptext)
#HACK this looks better than splitting into several lines & joining
# them. works because replace_whitespace in fill defaults to True:
replaced = translated_tooltip.replace(r'\n', self.CHARS_PER_LINE * ' ')
replaced = replaced.replace('[br]', self.CHARS_PER_LINE * ' ')
tooltip = textwrap.fill(replaced, self.CHARS_PER_LINE)
line_count = len(tooltip.splitlines()) - 1
top_image = Icon(image=self.TOP_IMAGE, position=(0, 0))
self.gui.addChild(top_image)
top_x, top_y = top_image.position
top_y += self.SIZE_BG_TOP
for i in xrange(0, line_count):
middle_image = Icon(image=self.MIDDLE_IMAGE)
middle_image.position = (top_x, top_y + self.LINE_HEIGHT * i)
self.gui.addChild(middle_image)
bottom_image = Icon(image=self.BOTTOM_IMAGE)
bottom_image.position = (top_x, top_y + self.LINE_HEIGHT * line_count)
self.gui.addChild(bottom_image)
label = Label(text=tooltip, position=(10, 5))
self.gui.addChild(label)
self.gui.stylize('tooltip')
size_y = self.SIZE_BG_TOP + self.LINE_HEIGHT * line_count + self.SIZE_BG_BOTTOM
self.gui.size = (145, size_y)
self.gui.show()
示例4: update_queue
def update_queue(self, container_active):
""" Update the queue display"""
queue = self.producer.get_unit_production_queue()
queue_container = container_active.findChild(name="queue_container")
queue_container.removeAllChildren()
for place_in_queue, unit_type in enumerate(queue):
image = self.__class__.UNIT_THUMBNAIL.format(type_id=unit_type)
helptext = T("{ship} (place in queue: {place})").format(
ship=self.instance.session.db.get_unit_type_name(unit_type),
place=place_in_queue + 1)
# people don't count properly, always starting at 1..
icon_name = "queue_elem_" + str(place_in_queue)
try:
icon = Icon(name=icon_name, image=image, helptext=helptext)
except fife.NotFound as e:
# It's possible that this error was raised from a missing thumbnail asset,
# so we check against that now and use a fallback thumbnail instead
if 'content/gui/icons/thumbnails/' in e.what():
# actually load the fallback unit image
image = self.__class__.UNIT_THUMBNAIL.format(type_id="unknown_unit")
icon = Icon(name=icon_name, image=image, helptext=helptext)
else:
raise
rm_from_queue_cb = Callback(RemoveFromQueue(self.producer, place_in_queue).execute,
self.instance.session)
icon.capture(rm_from_queue_cb, event_name="mouseClicked")
queue_container.addChild(icon)
示例5: create_resource_icon
def create_resource_icon(res_id, db):
"""Creates a pychan Icon for a resource. Helptext is set to name of *res_id*.
@param res_id: resource id
@param db: dbreader for main db"""
widget = Icon(image=get_res_icon_path(res_id))
widget.helptext = db.get_res_name(res_id)
return widget
示例6: refresh
def refresh(self):
"""This function is called by the TabWidget to redraw the widget."""
self._refresh_utilisation()
# remove old production line data
parent_container = self.widget.child_finder('production_lines')
while parent_container.children:
child = parent_container.children[-1]
if hasattr(child, "anim"):
child.anim.stop()
del child.anim
parent_container.removeChild( child )
# create a container for each production
# sort by production line id to have a consistent (basically arbitrary) order
for production in self.get_displayed_productions():
# we need to be notified of small production changes
# that aren't passed through the instance
production.add_change_listener(self._schedule_refresh, no_duplicates=True)
gui = load_uh_widget(self.production_line_gui_xml)
# fill in values to gui reflecting the current game state
container = gui.findChild(name="production_line_container")
self._set_resource_amounts(container, production)
if production.is_paused():
container.removeChild( container.findChild(name="toggle_active_active") )
toggle_icon = container.findChild(name="toggle_active_inactive")
toggle_icon.name = "toggle_active"
else:
container.removeChild( container.findChild(name="toggle_active_inactive") )
toggle_icon = container.findChild(name="toggle_active_active")
toggle_icon.name = "toggle_active"
if production.get_state() == PRODUCTION.STATES.producing:
bg = Icon(image=self.__class__.BUTTON_BACKGROUND)
bg.position = toggle_icon.position
container.addChild(bg)
container.removeChild(toggle_icon) # fix z-ordering
container.addChild(toggle_icon)
anim = PychanAnimation(toggle_icon, self.__class__.ACTIVE_PRODUCTION_ANIM_DIR)
container.anim = anim
anim.start(1.0/12, -1) # always start anew, people won't notice
self._animations.append( weakref.ref( anim ) )
# fill it with input and output resources
in_res_container = container.findChild(name="input_res")
self._add_resource_icons(in_res_container, production.get_consumed_resources(), marker=True)
out_res_container = container.findChild(name="output_res")
self._add_resource_icons(out_res_container, production.get_produced_resources())
# active toggle_active button
toggle_active = ToggleActive(self.instance.get_component(Producer), production)
container.mapEvents({
'toggle_active': Callback(toggle_active.execute, self.instance.session)
})
# NOTE: this command causes a refresh, so we needn't change the toggle_active-button-image
container.stylize('menu_black')
parent_container.addChild(container)
super(ProductionOverviewTab, self).refresh()
示例7: update_queue
def update_queue(self, container_active):
""" Update the queue display"""
queue = self.producer.get_unit_production_queue()
queue_container = container_active.findChild(name="queue_container")
queue_container.removeAllChildren()
for place_in_queue, unit_type in enumerate(queue):
image = self.__class__.UNIT_THUMBNAIL.format(type_id=unit_type)
helptext = T("{ship} (place in queue: {place})").format(
ship=self.instance.session.db.get_unit_type_name(unit_type), place=place_in_queue + 1
)
# people don't count properly, always starting at 1..
icon_name = "queue_elem_" + str(place_in_queue)
try:
icon = Icon(name=icon_name, image=image, helptext=helptext)
except RuntimeError, e:
# It's possible that this error was raised from a missing thumbnail asset,
# so we check against that now and use a fallback thumbnail instead
# TODO string matching for runtime errors is nightmare fuel
# Better: Replace RuntimeError in fife with a more precise error class if possible
# and only catch that class here
if e.message.startswith(
"_[NotFound]_ , Something was searched, but not found :: content/gui/icons/thumbnails/"
):
# actually load the fallback unit image
image = self.__class__.UNIT_THUMBNAIL.format(type_id="unknown_unit")
icon = Icon(name=icon_name, image=image, helptext=helptext)
else:
raise
rm_from_queue_cb = Callback(RemoveFromQueue(self.producer, place_in_queue).execute, self.instance.session)
icon.capture(rm_from_queue_cb, event_name="mouseClicked")
queue_container.addChild(icon)
示例8: create_resource_icon
def create_resource_icon(res_id, db, size=50):
"""Creates a pychan Icon for a resource. Helptext is set to name of *res_id*.
Returns None if *size* parameter is invalid (not one of 16, 24, 32, 50).
@param res_id: resource id
@param db: dbreader for main db
@param size: Size of icon in px. Valid: 16, 24, 32, 50."""
widget = None
if size in (16, 24, 32, 50):
widget = Icon(image=get_res_icon_path(res_id, size))
widget.helptext = db.get_res_name(res_id)
return widget
示例9: get_instance
class CoordsTooltip:
@classmethod
def get_instance(cls, cursor_tool):
if cursor_tool.session.ingame_gui.coordinates_tooltip is not None:
inst = cursor_tool.session.ingame_gui.coordinates_tooltip
inst.cursor_tool = cursor_tool
return inst
else:
return CoordsTooltip(cursor_tool)
def __init__(self, cursor_tool, **kwargs):
super().__init__(**kwargs)
cursor_tool.session.ingame_gui.coordinates_tooltip = self
self.cursor_tool = cursor_tool
self.enabled = False
self.icon = Icon(position=(1, 1)) # 0, 0 is currently not supported by tooltips
def toggle(self):
self.enabled = not self.enabled
if not self.enabled and self.icon.tooltip_shown:
self.icon.hide_tooltip()
def show_evt(self, evt):
if self.enabled:
if evt.isConsumedByWidgets():
if self.icon.tooltip_shown:
self.icon.hide_tooltip()
return
x, y = self.cursor_tool.get_world_location(evt).to_tuple()
self.icon.helptext = '{:d}, {:d} '.format(x, y) + T("Press H to remove this hint")
self.icon.position_tooltip(evt)
self.icon.show_tooltip()
示例10: __init__
class Background:
"""
Display a centered background image on top of a black screen.
"""
def __init__(self):
available_images = glob.glob('content/gui/images/background/mainmenu/bg_*.png')
self.bg_images = deque(available_images)
latest_bg = horizons.globals.fife.get_uh_setting("LatestBackground")
try:
# If we know the current background from an earlier session,
# show all other available ones before picking that one again.
self.bg_images.remove(latest_bg)
self.bg_images.append(latest_bg)
except ValueError:
pass
(res_width, res_height) = horizons.globals.fife.get_fife_setting('ScreenResolution').split('x')
self._black_box = Container()
self._black_box.size = int(res_width), int(res_height)
self._black_box.base_color = (0, 0, 0, 255)
self._image = Icon(position_technique='center:center')
self.rotate_image()
def rotate_image(self):
"""Select next background image to use in the game menu.
Triggered by the "Change background" main menu button.
"""
self.bg_images.rotate(1)
self._image.image = self.bg_images[0]
# Save current background choice to settings.
# This keeps the background image consistent between sessions.
horizons.globals.fife.set_uh_setting("LatestBackground", self.bg_images[0])
horizons.globals.fife.save_settings()
def show(self):
self._black_box.show()
self._image.show()
def hide(self):
self._image.hide()
self._black_box.hide()
@property
def visible(self):
return self._image.isVisible()
示例11: __init__
def __init__(self):
self.mainlistener = MainListener(self)
self.windows = WindowManager()
# temporary aliases for compatibility with rest of the code
self.show_popup = self.windows.show_popup
self.show_error_popup = self.windows.show_error_popup
# Main menu background image setup.
available_images = glob.glob('content/gui/images/background/mainmenu/bg_*.png')
self.bg_images = deque(available_images)
latest_bg = horizons.globals.fife.get_uh_setting("LatestBackground")
try:
# If we know the current background from an earlier session,
# show all other available ones before picking that one again.
self.bg_images.remove(latest_bg)
self.bg_images.append(latest_bg)
except ValueError:
pass
self._background = Icon(position_technique='center:center')
self.rotate_background()
self._background.show()
self.singleplayermenu = SingleplayerMenu(self.windows)
self.multiplayermenu = MultiplayerMenu(self, self.windows)
self.help_dialog = HelpDialog(self.windows)
self.loadingscreen = LoadingScreen()
self.settings_dialog = SettingsDialog(self.windows)
self.mainmenu = MainMenu(self, self.windows)
self.fps_display = FPSDisplay()
示例12: __init__
def __init__(self, cursor_tool, **kwargs):
super(CoordsTooltip, self).__init__(**kwargs)
cursor_tool.session.ingame_gui.coordinates_tooltip = self
self.cursor_tool = cursor_tool
self.enabled = False
self.icon = Icon(position=(1, 1)) # 0, 0 is currently not supported by tooltips
示例13: update_queue
def update_queue(self, container_active):
""" Update the queue display"""
queue = self.producer.get_unit_production_queue()
queue_container = container_active.findChild(name="queue_container")
queue_container.removeAllChildren()
for place_in_queue, unit_type in enumerate(queue):
image = self.__class__.UNIT_THUMBNAIL.format(type_id=unit_type)
helptext = _("{ship} (place in queue: {place})").format(
ship=self.instance.session.db.get_unit_type_name(unit_type), place=place_in_queue + 1
)
# people don't count properly, always starting at 1..
icon_name = "queue_elem_" + str(place_in_queue)
icon = Icon(name=icon_name, image=image, helptext=helptext)
rm_from_queue_cb = Callback(RemoveFromQueue(self.producer, place_in_queue).execute, self.instance.session)
icon.capture(rm_from_queue_cb, event_name="mouseClicked")
queue_container.addChild(icon)
示例14: __init__
def __init__(self, cursor_tool, **kwargs):
super(CoordsTooltip, self).__init__(**kwargs)
cursor_tool.session.coordinates_tooltip = self
self.cursor_tool = cursor_tool
self.enabled = False
self.icon = Icon()
示例15: _connect_input_res
def _connect_input_res(self, centered_container, container, production):
"""Draws incoming arrows for production line container."""
input_amount = len(production.get_consumed_resources())
if input_amount == 0:
# Do not draw input arrows if there is no input
return
# center the production line
icon_height = ImageFillStatusButton.CELL_SIZE[1] + ImageFillStatusButton.PADDING
center_y = (icon_height // 2) * (input_amount - 1)
centered_container.position = (0, center_y)
if input_amount % 2:
# Add center arrow for 1, 3, 5, ... but not 2, 4, ...
mid_arrow = Icon(image=self.__class__.ARROW_MID)
mid_arrow.position = (58, 17 + center_y)
container.insertChild(mid_arrow, 0)
for res in xrange(input_amount // 2):
# --\ <= placed for res = 1
# --\| <= place connector <= placed for res = 0
# ---O--> <= placed above (mid_arrow)
# --/| <= place connector <= placed for res = 0
# --/ <= placed for res = 1
offset = -17 + (icon_height // 2) * (2 * res + (input_amount % 2) + 1)
top_arrow = Icon(image=self.__class__.ARROW_TOP)
top_arrow.position = (58, center_y - offset)
container.insertChild(top_arrow, 0)
bottom_arrow = Icon(image=self.__class__.ARROW_BOTTOM)
bottom_arrow.position = (58, center_y + offset)
container.insertChild(bottom_arrow, 0)
# Place a connector image (the | in above sketch) that vertically connects
# the input resource arrows. We need those if the production line has more
# than three input resources. Connectors are placed in the inner loop parts.
place_connectors = (1 + 2 * res) < (input_amount // 2)
if place_connectors:
# the connector downwards connects top_arrows
down_connector = Icon(image=self.__class__.ARROW_CONNECT_DOWN)
down_connector.position = (98, center_y - offset)
container.insertChild(down_connector, 0)
# the connector upwards connects up_arrows
up_connector = Icon(image=self.__class__.ARROW_CONNECT_UP)
up_connector.position = (98, center_y + offset)
container.insertChild(up_connector, 0)