本文整理汇总了Python中horizons.gui.widgets.messagewidget.MessageWidget.save方法的典型用法代码示例。如果您正苦于以下问题:Python MessageWidget.save方法的具体用法?Python MessageWidget.save怎么用?Python MessageWidget.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类horizons.gui.widgets.messagewidget.MessageWidget
的用法示例。
在下文中一共展示了MessageWidget.save方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: IngameGui
# 需要导入模块: from horizons.gui.widgets.messagewidget import MessageWidget [as 别名]
# 或者: from horizons.gui.widgets.messagewidget.MessageWidget import save [as 别名]
class IngameGui(LivingObject):
"""Class handling all the ingame gui events.
Assumes that only 1 instance is used (class variables)"""
gui = livingProperty()
tabwidgets = livingProperty()
message_widget = livingProperty()
minimap = livingProperty()
styles = {
'city_info' : 'resource_bar',
'change_name' : 'book',
'save_map' : 'book',
'chat' : 'book',
}
def __init__(self, session, gui):
super(IngameGui, self).__init__()
self.session = session
assert isinstance(self.session, horizons.session.Session)
self.main_gui = gui
self.main_widget = None
self.tabwidgets = {}
self.settlement = None
self.resource_source = None
self.resources_needed, self.resources_usable = {}, {}
self._old_menu = None
self.widgets = LazyWidgetsDict(self.styles, center_widgets=False)
self.cityinfo = self.widgets['city_info']
self.cityinfo.child_finder = PychanChildFinder(self.cityinfo)
self.logbook = LogBook(self.session)
self.message_widget = MessageWidget(self.session)
self.players_overview = PlayersOverview(self.session)
self.players_settlements = PlayersSettlements(self.session)
self.players_ships = PlayersShips(self.session)
# self.widgets['minimap'] is the guichan gui around the actual minimap,
# which is saved in self.minimap
minimap = self.widgets['minimap']
minimap.position_technique = "right+0:top+0"
icon = minimap.findChild(name="minimap")
self.minimap = Minimap(icon,
targetrenderer=horizons.globals.fife.targetrenderer,
imagemanager=horizons.globals.fife.imagemanager,
session=self.session,
view=self.session.view)
def speed_up():
SpeedUpCommand().execute(self.session)
def speed_down():
SpeedDownCommand().execute(self.session)
minimap.mapEvents({
'zoomIn' : self.session.view.zoom_in,
'zoomOut' : self.session.view.zoom_out,
'rotateRight' : Callback.ChainedCallbacks(self.session.view.rotate_right, self.minimap.rotate_right),
'rotateLeft' : Callback.ChainedCallbacks(self.session.view.rotate_left, self.minimap.rotate_left),
'speedUp' : speed_up,
'speedDown' : speed_down,
'destroy_tool' : self.session.toggle_destroy_tool,
'build' : self.show_build_menu,
'diplomacyButton' : self.show_diplomacy_menu,
'gameMenuButton' : self.main_gui.toggle_pause,
'logbook' : self.logbook.toggle_visibility
})
minimap.show()
#minimap.position_technique = "right+15:top+153"
self.widgets['tooltip'].hide()
self.resource_overview = ResourceOverviewBar(self.session)
ResourceBarResize.subscribe(self._on_resourcebar_resize)
# Register for messages
SettlerUpdate.subscribe(self._on_settler_level_change)
SettlerInhabitantsChanged.subscribe(self._on_settler_inhabitant_change)
HoverSettlementChanged.subscribe(self._cityinfo_set)
def _on_resourcebar_resize(self, message):
self._update_cityinfo_position()
def end(self):
self.widgets['minimap'].mapEvents({
'zoomIn' : None,
'zoomOut' : None,
'rotateRight' : None,
'rotateLeft': None,
'destroy_tool' : None,
'build' : None,
'diplomacyButton' : None,
'gameMenuButton' : None
})
for w in self.widgets.itervalues():
#.........这里部分代码省略.........
示例2: IngameGui
# 需要导入模块: from horizons.gui.widgets.messagewidget import MessageWidget [as 别名]
# 或者: from horizons.gui.widgets.messagewidget.MessageWidget import save [as 别名]
#.........这里部分代码省略.........
'destroy_tool' : None,
'build' : None,
'diplomacyButton' : None,
'gameMenuButton' : None
})
self.mainhud.hide()
self.mainhud = None
self.windows.close_all()
self.message_widget = None
self.minimap = None
self.resource_overview.end()
self.resource_overview = None
self.keylistener = None
self.cityinfo.end()
self.cityinfo = None
self.hide_menu()
if self.cursor:
self.cursor.remove()
self.cursor.end()
self.cursor = None
LastActivePlayerSettlementManager().remove()
LastActivePlayerSettlementManager.destroy_instance()
self.production_finished_icon_manager.end()
self.production_finished_icon_manager = None
self.status_icon_manager.end()
self.status_icon_manager = None
super(IngameGui, self).end()
def show_select_savegame(self, mode):
window = SelectSavegameDialog(mode, self.windows)
return self.windows.show(window)
def toggle_pause(self):
self.windows.toggle(self.pausemenu)
def toggle_help(self):
self.windows.toggle(self.help_dialog)
def minimap_to_front(self):
"""Make sure the full right top gui is visible and not covered by some dialog"""
self.mainhud.hide()
self.mainhud.show()
def show_diplomacy_menu(self):
# check if the menu is already shown
if getattr(self.get_cur_menu(), 'name', None) == "diplomacy_widget":
self.hide_menu()
return
if not DiplomacyTab.is_useable(self.session.world):
self.windows.show_popup(_("No diplomacy possible"),
_("Cannot do diplomacy as there are no other players."))
return
tab = DiplomacyTab(self, self.session.world)
self.show_menu(tab)
def show_multi_select_tab(self, instances):
tab = TabWidget(self, tabs=[SelectMultiTab(instances)], name='select_multi')
self.show_menu(tab)
示例3: IngameGui
# 需要导入模块: from horizons.gui.widgets.messagewidget import MessageWidget [as 别名]
# 或者: from horizons.gui.widgets.messagewidget.MessageWidget import save [as 别名]
class IngameGui(LivingObject):
"""Class handling all the ingame gui events.
Assumes that only 1 instance is used (class variables)"""
gui = livingProperty()
tabwidgets = livingProperty()
message_widget = livingProperty()
minimap = livingProperty()
styles = {
'city_info' : 'city_info',
'change_name' : 'book',
'save_map' : 'book',
'chat' : 'book',
}
def __init__(self, session, gui):
super(IngameGui, self).__init__()
self.session = session
assert isinstance(self.session, horizons.session.Session)
self.main_gui = gui
self.main_widget = None
self.tabwidgets = {}
self.settlement = None
self.resource_source = None
self.resources_needed, self.resources_usable = {}, {}
self._old_menu = None
self.widgets = LazyWidgetsDict(self.styles, center_widgets=False)
cityinfo = self.widgets['city_info']
cityinfo.child_finder = PychanChildFinder(cityinfo)
# special settings for really small resolutions
#TODO explain what actually happens
width = horizons.main.fife.engine_settings.getScreenWidth()
x = 'center'
y = 'top'
x_offset = +15
y_offset = +4
if width < 800:
x = 'left'
x_offset = 10
y_offset = +66
elif width < 1020:
x_offset = (1050 - width) / 2
cityinfo.position_technique = "%s%+d:%s%+d" % (x, x_offset, y, y_offset) # usually "center-10:top+4"
self.logbook = LogBook(self.session)
self.message_widget = MessageWidget(self.session)
self.players_overview = PlayersOverview(self.session)
self.players_settlements = PlayersSettlements(self.session)
self.players_ships = PlayersShips(self.session)
self.scenario_chooser = ScenarioChooser(self.session)
# self.widgets['minimap'] is the guichan gui around the actual minimap,
# which is saved in self.minimap
minimap = self.widgets['minimap']
minimap.position_technique = "right+0:top+0"
icon = minimap.findChild(name="minimap")
self.minimap = Minimap(icon,
targetrenderer=horizons.main.fife.targetrenderer,
imagemanager=horizons.main.fife.imagemanager,
session=self.session,
view=self.session.view)
def speed_up():
SpeedUpCommand().execute(self.session)
def speed_down():
SpeedDownCommand().execute(self.session)
minimap.mapEvents({
'zoomIn' : self.session.view.zoom_in,
'zoomOut' : self.session.view.zoom_out,
'rotateRight' : Callback.ChainedCallbacks(self.session.view.rotate_right, self.minimap.rotate_right),
'rotateLeft' : Callback.ChainedCallbacks(self.session.view.rotate_left, self.minimap.rotate_left),
'speedUp' : speed_up,
'speedDown' : speed_down,
'destroy_tool' : self.session.toggle_destroy_tool,
'build' : self.show_build_menu,
'diplomacyButton' : self.show_diplomacy_menu,
'gameMenuButton' : self.main_gui.toggle_pause,
'logbook' : self.logbook.toggle_visibility
})
minimap.show()
#minimap.position_technique = "right+15:top+153"
self.widgets['tooltip'].hide()
self.resource_overview = ResourceOverviewBar(self.session)
ResourceBarResize.subscribe(self._on_resourcebar_resize)
# map buildings to build functions calls with their building id.
# This is necessary because BuildTabs have no session.
self.callbacks_build = dict()
for building_id in Entities.buildings.iterkeys():
self.callbacks_build[building_id] = Callback(self._build, building_id)
#.........这里部分代码省略.........
示例4: IngameGui
# 需要导入模块: from horizons.gui.widgets.messagewidget import MessageWidget [as 别名]
# 或者: from horizons.gui.widgets.messagewidget.MessageWidget import save [as 别名]
#.........这里部分代码省略.........
self.set_cursor('building', cls, None if unit is None else unit())
def toggle_road_tool(self):
if not isinstance(self.cursor, mousetools.BuildingTool) or self.cursor._class.id != BUILDINGS.TRAIL:
self._build(BUILDINGS.TRAIL)
else:
self.set_cursor()
def get_cur_menu(self):
"""Returns menu that is currently displayed"""
return self._old_menu
def show_menu(self, menu):
"""Shows a menu
@param menu: str with the guiname or pychan object.
"""
if self._old_menu is not None:
if hasattr(self._old_menu, "remove_remove_listener"):
self._old_menu.remove_remove_listener( Callback(self.show_menu, None) )
self._old_menu.hide()
self._old_menu = menu
if self._old_menu is not None:
if hasattr(self._old_menu, "add_remove_listener"):
self._old_menu.add_remove_listener( Callback(self.show_menu, None) )
self._old_menu.show()
self.minimap_to_front()
TabWidgetChanged.broadcast(self)
def hide_menu(self):
self.show_menu(None)
def save(self, db):
self.message_widget.save(db)
self.logbook.save(db)
self.resource_overview.save(db)
LastActivePlayerSettlementManager().save(db)
def load(self, db):
self.message_widget.load(db)
self.logbook.load(db)
self.resource_overview.load(db)
if self.session.is_game_loaded():
LastActivePlayerSettlementManager().load(db)
cur_settlement = LastActivePlayerSettlementManager().get_current_settlement()
self.cityinfo.set_settlement(cur_settlement)
self.minimap.draw() # update minimap to new world
self.current_cursor = 'default'
self.cursor = mousetools.SelectionTool(self.session)
# Set cursor correctly, menus might need to be opened.
# Open menus later; they may need unit data not yet inited
self.cursor.apply_select()
if not self.session.is_game_loaded():
# Fire a message for new world creation
self.session.ingame_gui.message_widget.add(point=None, string_id='NEW_WORLD')
def show_change_name_dialog(self, instance):
"""Shows a dialog where the user can change the name of an object."""
self.change_name_dialog.show(instance)
def on_escape(self):
示例5: IngameGui
# 需要导入模块: from horizons.gui.widgets.messagewidget import MessageWidget [as 别名]
# 或者: from horizons.gui.widgets.messagewidget.MessageWidget import save [as 别名]
#.........这里部分代码省略.........
else:
self.show_menu(menu)
def build_load_tab(self, num):
"""Loads a subcontainer into the build menu and changes the tabs background.
@param num: number representing the tab to load.
"""
tab1 = self.widgets['build'].findChild(name=('tab'+str(self.active_build)))
tab2 = self.widgets['build'].findChild(name=('tab'+str(num)))
activetabimg, nonactiveimg= tab1._getImage(), tab2._getImage()
tab1._setImage(nonactiveimg)
tab2._setImage(activetabimg)
contentarea = self.widgets['build'].findChild(name='content')
contentarea.removeChild(self.widgets['build_tab'+str(self.active_build)])
contentarea.addChild(self.widgets['build_tab'+str(num)])
contentarea.adaptLayout()
self.active_build = num
def set_status_position(self, resource_name):
icon_name = resource_name + '_icon'
for i in xrange(1, 3):
lbl_name = resource_name + '_' + str(i)
# tools_1 = inventory amount, tools_2 = cost of to-be-built building
if resource_name == 'gold':
self._set_label_position('status_gold', lbl_name, icon_name, 33, 31 + i*20)
else:
self._set_label_position('status', lbl_name, icon_name, 24, 31 + i*20)
def _set_label_position(self, widget, lbl_name, icon_name, xoffset, yoffset):
icon = self.widgets[widget].child_finder(icon_name)
label = self.widgets[widget].child_finder(lbl_name)
label.position = (icon.position[0] - label.size[0]/2 + xoffset, yoffset)
def save(self, db):
self.message_widget.save(db)
self.logbook.save(db)
def load(self, db):
self.message_widget.load(db)
self.logbook.load(db)
self.minimap.draw() # update minimap to new world
def show_change_name_dialog(self, instance):
"""Shows a dialog where the user can change the name of a NamedObject.
The game gets paused while the dialog is executed."""
self.session.speed_pause()
events = {
'okButton': Callback(self.change_name, instance),
'cancelButton': self._hide_change_name_dialog
}
self.main_gui.on_escape = self._hide_change_name_dialog
changename = self.widgets['change_name']
newname = changename.findChild(name='new_name')
changename.mapEvents(events)
newname.capture(Callback(self.change_name, instance))
changename.show()
newname.requestFocus()
def _hide_change_name_dialog(self):
"""Escapes the change_name dialog"""
self.session.speed_unpause()
self.main_gui.on_escape = self.main_gui.toggle_pause
self.widgets['change_name'].hide()
def change_name(self, instance):
示例6: IngameGui
# 需要导入模块: from horizons.gui.widgets.messagewidget import MessageWidget [as 别名]
# 或者: from horizons.gui.widgets.messagewidget.MessageWidget import save [as 别名]
#.........这里部分代码省略.........
self._old_menu = self._get_menu_object(menu)
if self._old_menu is not None:
self._old_menu.show()
self.minimap_to_front()
def hide_menu(self):
self.show_menu(None)
def toggle_menu(self, menu):
"""Shows a menu or hides it if it is already displayed.
@param menu: parameter supported by show_menu().
"""
if self.get_cur_menu() == self._get_menu_object(menu):
self.hide_menu()
else:
self.show_menu(menu)
def build_load_tab(self, num):
"""Loads a subcontainer into the build menu and changes the tabs background.
@param num: number representing the tab to load.
"""
tab1 = self.widgets['build'].findChild(name=('tab'+str(self.active_build)))
tab2 = self.widgets['build'].findChild(name=('tab'+str(num)))
activetabimg, nonactiveimg= tab1._getImage(), tab2._getImage()
tab1._setImage(nonactiveimg)
tab2._setImage(activetabimg)
contentarea = self.widgets['build'].findChild(name='content')
contentarea.removeChild(self.widgets['build_tab'+str(self.active_build)])
contentarea.addChild(self.widgets['build_tab'+str(num)])
contentarea.adaptLayout()
self.active_build = num
def save(self, db):
self.message_widget.save(db)
self.logbook.save(db)
def load(self, db):
self.message_widget.load(db)
self.logbook.load(db)
self.minimap.draw() # update minimap to new world
def show_change_name_dialog(self, instance):
"""Shows a dialog where the user can change the name of a NamedObject.
The game gets paused while the dialog is executed."""
self.session.speed_pause()
events = {
'okButton': Callback(self.change_name, instance),
'cancelButton': self._hide_change_name_dialog
}
self.main_gui.on_escape = self._hide_change_name_dialog
changename = self.widgets['change_name']
newname = changename.findChild(name='new_name')
changename.mapEvents(events)
newname.capture(Callback(self.change_name, instance))
changename.show()
newname.requestFocus()
def _hide_change_name_dialog(self):
"""Escapes the change_name dialog"""
self.session.speed_unpause()
self.main_gui.on_escape = self.main_gui.show_pause
self.widgets['change_name'].hide()
def change_name(self, instance):
示例7: IngameGui
# 需要导入模块: from horizons.gui.widgets.messagewidget import MessageWidget [as 别名]
# 或者: from horizons.gui.widgets.messagewidget.MessageWidget import save [as 别名]
#.........这里部分代码省略.........
def build_load_tab(self, num):
"""Loads a subcontainer into the build menu and changes the tabs background.
@param num: number representing the tab to load.
"""
tab1 = self.widgets['build'].findChild(name=('tab'+str(self.active_build)))
tab2 = self.widgets['build'].findChild(name=('tab'+str(num)))
activetabimg, nonactiveimg= tab1._getImage(), tab2._getImage()
tab1._setImage(nonactiveimg)
tab2._setImage(activetabimg)
contentarea = self.widgets['build'].findChild(name='content')
contentarea.removeChild(self.widgets['build_tab'+str(self.active_build)])
contentarea.addChild(self.widgets['build_tab'+str(num)])
contentarea.adaptLayout()
self.active_build = num
def set_status_position(self, resource_name):
for i in xrange(1, 4):
icon_name = resource_name + '_icon'
plusx = 0
if i > 1:
# increase x position for lines greater the 1
plusx = 20
if resource_name == 'gold':
self.widgets['status_gold'].child_finder(resource_name + '_' + str(i)).position = (
self.widgets['status_gold'].child_finder(icon_name).position[0] + 33 - self.widgets['status_gold'].findChild(name = resource_name + '_' + str(i)).size[0]/2,
41 + 10 * i + plusx
)
else:
self.widgets['status'].child_finder(resource_name + '_' + str(i)).position = (
self.widgets['status'].child_finder(icon_name).position[0] + 24 - self.widgets['status'].child_finder(resource_name + '_' + str(i)).size[0]/2,
41 + 10 * i + plusx
)
def save(self, db):
self.message_widget.save(db)
def load(self, db):
self.message_widget.load(db)
self.minimap.draw() # update minimap to new world
def show_change_name_dialog(self, instance):
"""Shows a dialog where the user can change the name of a NamedObject.
The game gets paused while the dialog is executed."""
self.session.speed_pause()
events = {
'okButton': pychan.tools.callbackWithArguments(self.change_name, instance),
'cancelButton': self._hide_change_name_dialog
}
self.main_gui.on_escape = self._hide_change_name_dialog
self.widgets['change_name'].mapEvents(events)
self.widgets['change_name'].findChild(name='new_name').capture( \
pychan.tools.callbackWithArguments(self.change_name, instance)
)
self.widgets['change_name'].show()
self.widgets['change_name'].findChild(name="new_name").requestFocus()
def _hide_change_name_dialog(self):
"""Escapes the change_name dialog"""
self.session.speed_unpause()
self.main_gui.on_escape = self.main_gui.show_pause
self.widgets['change_name'].hide()
def change_name(self, instance):
"""Applies the change_name dialogs input and hides it"""
new_name = self.widgets['change_name'].collectData('new_name')