本文整理汇总了Python中horizons.gui.util.LazyWidgetsDict类的典型用法代码示例。如果您正苦于以下问题:Python LazyWidgetsDict类的具体用法?Python LazyWidgetsDict怎么用?Python LazyWidgetsDict使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LazyWidgetsDict类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self):
self.mainlistener = MainListener(self)
self.current = None # currently active window
self.widgets = LazyWidgetsDict(self.styles) # access widgets with their filenames without '.xml'
build_help_strings(self.widgets['help'])
self.session = None
self.current_dialog = None
self.dialog_executed = False
self.__pause_displayed = False
self._background_image = self._get_random_background()
示例2: __init__
def __init__(self):
self.mainlistener = MainListener(self)
self.current = None # currently active window
self.widgets = LazyWidgetsDict(self.styles) # access widgets with their filenames without '.xml'
self.session = None
self.current_dialog = None
self.dialog_executed = False
self.__pause_displayed = False
self._background_image = self._get_random_background()
self.subscribe()
self.singleplayermenu = SingleplayerMenu(self)
self.multiplayermenu = MultiplayerMenu(self)
self.help_dialog = HelpDialog(self)
示例3: __init__
def __init__(self):
#i18n this defines how each line in our help looks like. Default: '[C] = Chat'
self.HELPSTRING_LAYOUT = _('[{key}] = {text}') #xgettext:python-format
self.mainlistener = MainListener(self)
self.current = None # currently active window
self.widgets = LazyWidgetsDict(self.styles) # access widgets with their filenames without '.xml'
self.keyconf = KeyConfig() # before build_help_strings
self.build_help_strings()
self.session = None
self.current_dialog = None
self.dialog_executed = False
self.__pause_displayed = False
self._background_image = self._get_random_background()
self.subscribe()
示例4: Gui
class Gui(SingleplayerMenu, MultiplayerMenu):
"""This class handles all the out of game menu, like the main and pause menu, etc.
"""
log = logging.getLogger("gui")
# styles to apply to a widget
styles = {
'mainmenu': 'menu',
'requirerestart': 'book',
'ingamemenu': 'headline',
'help': 'book',
'singleplayermenu': 'book',
'sp_random': 'book',
'sp_scenario': 'book',
'sp_campaign': 'book',
'sp_free_maps': 'book',
'multiplayermenu' : 'book',
'multiplayer_creategame' : 'book',
'multiplayer_gamelobby' : 'book',
'playerdataselection' : 'book',
'aidataselection' : 'book',
'select_savegame': 'book',
'ingame_pause': 'book',
'game_settings' : 'book',
# 'credits': 'book',
}
def __init__(self):
self.mainlistener = MainListener(self)
self.current = None # currently active window
self.widgets = LazyWidgetsDict(self.styles) # access widgets with their filenames without '.xml'
build_help_strings(self.widgets['help'])
self.session = None
self.current_dialog = None
self.dialog_executed = False
self.__pause_displayed = False
self._background_image = self._get_random_background()
GuiAction.subscribe( self._on_gui_action )
# basic menu widgets
def show_main(self):
"""Shows the main menu """
self._switch_current_widget('mainmenu', center=True, show=True, event_map={
'startSingle' : self.show_single, # first is the icon in menu
'start' : self.show_single, # second is the lable in menu
'startMulti' : self.show_multi,
'start_multi' : self.show_multi,
'settingsLink' : self.show_settings,
'settings' : self.show_settings,
'helpLink' : self.on_help,
'help' : self.on_help,
'closeButton' : self.show_quit,
'quit' : self.show_quit,
'dead_link' : self.on_chime, # call for help; SoC information
'chimebell' : self.on_chime,
'creditsLink' : self.show_credits,
'credits' : self.show_credits,
'loadgameButton' : horizons.main.load_game,
'loadgame' : horizons.main.load_game,
'changeBackground' : self.get_random_background_by_button
})
self.on_escape = self.show_quit
def toggle_pause(self):
"""
Show Pause menu
"""
# TODO: logically, this now belongs to the ingame_gui (it used to be different)
# this manifests itself by the need for the __pause_displayed hack below
# in the long run, this should be moved, therefore eliminating the hack, and
# ensuring correct setup/teardown.
if self.__pause_displayed:
self.__pause_displayed = False
self.hide()
self.current = None
UnPauseCommand(suggestion=True).execute(self.session)
self.on_escape = self.toggle_pause
else:
self.__pause_displayed = True
# reload the menu because caching creates spacing problems
# see http://trac.unknown-horizons.org/t/ticket/1047
self.widgets.reload('ingamemenu')
def do_load():
did_load = horizons.main.load_game()
if did_load:
self.__pause_displayed = False
def do_quit():
did_quit = self.quit_session()
if did_quit:
self.__pause_displayed = False
events = { # needed twice, save only once here
'e_load' : do_load,
'e_save' : self.save_game,
'e_sett' : self.show_settings,
#.........这里部分代码省略.........
示例5: __init__
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)
示例6: IngameGui
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():
#.........这里部分代码省略.........
示例7: __init__
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)
# Register for messages
SettlerUpdate.subscribe(self._on_settler_level_change)
SettlerInhabitantsChanged.subscribe(self._on_settler_inhabitant_change)
HoverSettlementChanged.subscribe(self._cityinfo_set)
示例8: IngameGui
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)
#.........这里部分代码省略.........
示例9: Gui
class Gui(object):
"""This class handles all the out of game menu, like the main and pause menu, etc.
"""
log = logging.getLogger("gui")
# styles to apply to a widget
styles = {
"mainmenu": "menu",
"requirerestart": "book",
"ingamemenu": "headline",
"help": "book",
"singleplayermenu": "book",
"sp_random": "book",
"sp_scenario": "book",
"sp_free_maps": "book",
"multiplayermenu": "book",
"multiplayer_creategame": "book",
"multiplayer_gamelobby": "book",
"playerdataselection": "book",
"aidataselection": "book",
"select_savegame": "book",
"ingame_pause": "book",
"game_settings": "book",
"editor_pause_menu": "headline",
}
def __init__(self):
self.mainlistener = MainListener(self)
self.current = None # currently active window
self.widgets = LazyWidgetsDict(self.styles) # access widgets with their filenames without '.xml'
self.session = None
self.current_dialog = None
self.dialog_executed = False
self.__pause_displayed = False
self._background_image = self._get_random_background()
self.subscribe()
self.singleplayermenu = SingleplayerMenu(self)
self.multiplayermenu = MultiplayerMenu(self)
self.help_dialog = HelpDialog(self)
self.selectsavegame_dialog = SelectSavegameDialog(self)
self.show_select_savegame = self.selectsavegame_dialog.show_select_savegame
def subscribe(self):
"""Subscribe to the necessary messages."""
GuiAction.subscribe(self._on_gui_action)
def unsubscribe(self):
GuiAction.unsubscribe(self._on_gui_action)
# basic menu widgets
def show_main(self):
"""Shows the main menu """
self._switch_current_widget(
"mainmenu",
center=True,
show=True,
event_map={
"startSingle": self.show_single, # first is the icon in menu
"start": self.show_single, # second is the label in menu
"startMulti": self.show_multi,
"start_multi": self.show_multi,
"settingsLink": self.show_settings,
"settings": self.show_settings,
"helpLink": self.on_help,
"help": self.on_help,
"editor_link": self.show_editor_start_menu,
"editor": self.show_editor_start_menu,
"closeButton": self.show_quit,
"quit": self.show_quit,
"creditsLink": self.show_credits,
"credits": self.show_credits,
"loadgameButton": self.load_game,
"loadgame": self.load_game,
"changeBackground": self.get_random_background_by_button,
},
)
self.on_escape = self.show_quit
def load_game(self):
saved_game = self.show_select_savegame(mode="load")
if saved_game is None:
return False # user aborted dialog
self.show_loading_screen()
options = StartGameOptions(saved_game)
horizons.main.start_singleplayer(options)
return True
def toggle_pause(self):
"""Shows in-game pause menu if the game is currently not paused.
Else unpauses and hides the menu. Multiple layers of the 'paused' concept exist;
if two widgets are opened which would both pause the game, we do not want to
unpause after only one of them is closed. Uses PauseCommand and UnPauseCommand.
"""
# TODO: logically, this now belongs to the ingame_gui (it used to be different)
#.........这里部分代码省略.........
示例10: Gui
class Gui(SingleplayerMenu, MultiplayerMenu):
"""This class handles all the out of game menu, like the main and pause menu, etc.
"""
log = logging.getLogger("gui")
# styles to apply to a widget
styles = {
'mainmenu': 'menu',
'requirerestart': 'book',
'ingamemenu': 'headline',
'help': 'book',
'singleplayermenu': 'book',
'sp_random': 'book',
'sp_scenario': 'book',
'sp_free_maps': 'book',
'multiplayermenu' : 'book',
'multiplayer_creategame' : 'book',
'multiplayer_gamelobby' : 'book',
'playerdataselection' : 'book',
'aidataselection' : 'book',
'select_savegame': 'book',
'ingame_pause': 'book',
'game_settings' : 'book',
# 'credits': 'book',
'editor_select_map': 'book',
}
def __init__(self):
#i18n this defines how each line in our help looks like. Default: '[C] = Chat'
self.HELPSTRING_LAYOUT = _('[{key}] = {text}') #xgettext:python-format
self.mainlistener = MainListener(self)
self.current = None # currently active window
self.widgets = LazyWidgetsDict(self.styles) # access widgets with their filenames without '.xml'
self.keyconf = KeyConfig() # before build_help_strings
self.build_help_strings()
self.session = None
self.current_dialog = None
self.dialog_executed = False
self.__pause_displayed = False
self._background_image = self._get_random_background()
self.subscribe()
def subscribe(self):
"""Subscribe to the necessary messages."""
GuiAction.subscribe(self._on_gui_action)
def unsubscribe(self):
GuiAction.unsubscribe(self._on_gui_action)
# basic menu widgets
def show_main(self):
"""Shows the main menu """
self._switch_current_widget('mainmenu', center=True, show=True, event_map={
'startSingle' : self.show_single, # first is the icon in menu
'start' : self.show_single, # second is the label in menu
'startMulti' : self.show_multi,
'start_multi' : self.show_multi,
'settingsLink' : self.show_settings,
'settings' : self.show_settings,
'helpLink' : self.on_help,
'help' : self.on_help,
'editor_link' : self.editor_load_map,
'editor' : self.editor_load_map,
'closeButton' : self.show_quit,
'quit' : self.show_quit,
'creditsLink' : self.show_credits,
'credits' : self.show_credits,
'loadgameButton' : self.load_game,
'loadgame' : self.load_game,
'changeBackground' : self.get_random_background_by_button,
})
self.on_escape = self.show_quit
def load_game(self):
saved_game = self.show_select_savegame(mode='load')
if saved_game is None:
return False # user aborted dialog
self.show_loading_screen()
options = StartGameOptions(saved_game)
horizons.main.start_singleplayer(options)
return True
def toggle_pause(self):
"""Shows in-game pause menu if the game is currently not paused.
Else unpauses and hides the menu. Multiple layers of the 'paused' concept exist;
if two widgets are opened which would both pause the game, we do not want to
unpause after only one of them is closed. Uses PauseCommand and UnPauseCommand.
"""
# TODO: logically, this now belongs to the ingame_gui (it used to be different)
# this manifests itself by the need for the __pause_displayed hack below
# in the long run, this should be moved, therefore eliminating the hack, and
# ensuring correct setup/teardown.
if self.__pause_displayed:
self.__pause_displayed = False
self.hide()
#.........这里部分代码省略.........