diff src/browser/sat_browser/game_tarot.py @ 676:849ffb24d5bf frontends_multi_profiles

browser side: menus refactorisation: - use of the new quick_frontends.quick_menus module, resulting in a big code simplification in Libervia - menu are added in there respective modules: main menus are done directely in libervia_main, while tarot and radiocol menus are done in game_tarot and game_radiocol - launchAction has the same signature as in QuickApp - base_menu: there are now 2 classes to launch an action: MenuCmd which manage quick_menus classes, and SimpleCmd to launch a generic callback - base_menu: MenuNode has been removed as logic is now in quick_menus - base_menu: GenericMenuBar.update method can be called to fully (re)build the menus - base_widget: removed WidgetSubMenuBar which is no more useful (GenericMenuBar do the same thing) - plugin_menu_context is used in LiberviaWidget and other classes with menus to indicate which menu types must be used - otr menus hooks are temporarily removed, will be fixed soon
author Goffi <goffi@goffi.org>
date Tue, 17 Mar 2015 20:42:02 +0100
parents b39a9eddfe56
children e876f493dccc
line wrap: on
line diff
--- a/src/browser/sat_browser/game_tarot.py	Tue Mar 17 20:28:41 2015 +0100
+++ b/src/browser/sat_browser/game_tarot.py	Tue Mar 17 20:42:02 2015 +0100
@@ -21,8 +21,9 @@
 from sat.core.log import getLogger
 log = getLogger(__name__)
 
-from sat.core.i18n import _
+from sat.core.i18n import _, D_
 from sat_frontends.tools.games import TarotCard
+from sat_frontends.tools import host_listener
 
 from pyjamas.ui.AbsolutePanel import AbsolutePanel
 from pyjamas.ui.DockPanel import DockPanel
@@ -34,6 +35,7 @@
 from pyjamas.ui import HasAlignment
 from pyjamas import Window
 from pyjamas import DOM
+from constants import Const as C
 
 import dialog
 import xmlui
@@ -386,3 +388,21 @@
         _dialog = dialog.GenericDialog(title, body, options=['NO_CLOSE'])
         body.setCloseCb(_dialog.close)
         _dialog.show()
+
+
+##  Menu
+
+def hostReady(host):
+    def onTarotGame():
+        def onPlayersSelected(room_jid, other_players):
+            other_players = [unicode(contact) for contact in other_players]
+            room_jid_s = unicode(room_jid) if room_jid else ''
+            host.bridge.launchTarotGame(other_players, room_jid_s, profile=C.PROF_KEY_NONE)
+        dialog.RoomAndContactsChooser(host, onPlayersSelected, 3, title="Tarot", title_invite=_(u"Please select 3 other players"), visible=(False, True))
+
+
+    def gotMenus():
+        host.menus.addMenu(C.MENU_GLOBAL, (D_(u"Games"), D_(u"Tarot")), callback=onTarotGame)
+    host.addListener('gotMenus', gotMenus)
+
+host_listener.addListener(hostReady)