# HG changeset patch # User souliane # Date 1385056630 -3600 # Node ID 56aa0e98c92e8dc70eb410e32747eb14b72caea3 # Parent 074970227bc0de5c9be1f0675c1f3b62ace84612 frontends tools: moved src/tools/frontends to frontends/src/tools diff -r 074970227bc0 -r 56aa0e98c92e frontends/src/primitivus/card_game.py --- a/frontends/src/primitivus/card_game.py Thu Nov 21 18:23:08 2013 +0100 +++ b/frontends/src/primitivus/card_game.py Thu Nov 21 18:57:10 2013 +0100 @@ -19,7 +19,7 @@ import urwid from urwid_satext import sat_widgets -from sat.tools.frontends.games import TarotCard +from sat_frontends.tools.games import TarotCard from sat_frontends.quick_frontend.quick_card_game import QuickCardGame from sat_frontends.primitivus.xmlui import XMLUI diff -r 074970227bc0 -r 56aa0e98c92e frontends/src/primitivus/primitivus --- a/frontends/src/primitivus/primitivus Thu Nov 21 18:23:08 2013 +0100 +++ b/frontends/src/primitivus/primitivus Thu Nov 21 18:57:10 2013 +0100 @@ -31,7 +31,7 @@ from sat_frontends.primitivus.xmlui import XMLUI from sat_frontends.primitivus.progress import Progress from sat_frontends.primitivus.notify import Notify -from sat.tools.frontends.misc import InputHistory +from sat_frontends.tools.misc import InputHistory import sat_frontends.primitivus.constants import logging from logging import debug, info, error diff -r 074970227bc0 -r 56aa0e98c92e frontends/src/tools/__init__.py diff -r 074970227bc0 -r 56aa0e98c92e frontends/src/tools/composition.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/frontends/src/tools/composition.py Thu Nov 21 18:57:10 2013 +0100 @@ -0,0 +1,90 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +""" +Libervia: a Salut à Toi frontend +Copyright (C) 2013 Adrien Cossa + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +""" + +# Map the messages recipient types to their properties. +RECIPIENT_TYPES = {"To": {"desc": "Direct recipients", "optional": False}, + "Cc": {"desc": "Carbon copies", "optional": True}, + "Bcc": {"desc": "Blind carbon copies", "optional": True}} + +# Rich text buttons icons and descriptions +RICH_BUTTONS = { + "bold": {"tip": "Bold", "icon": "media/icons/dokuwiki/toolbar/16/bold.png"}, + "italic": {"tip": "Italic", "icon": "media/icons/dokuwiki/toolbar/16/italic.png"}, + "underline": {"tip": "Underline", "icon": "media/icons/dokuwiki/toolbar/16/underline.png"}, + "code": {"tip": "Code", "icon": "media/icons/dokuwiki/toolbar/16/mono.png"}, + "strikethrough": {"tip": "Strikethrough", "icon": "media/icons/dokuwiki/toolbar/16/strike.png"}, + "heading": {"tip": "Heading", "icon": "media/icons/dokuwiki/toolbar/16/hequal.png"}, + "numberedlist": {"tip": "Numbered List", "icon": "media/icons/dokuwiki/toolbar/16/ol.png"}, + "list": {"tip": "List", "icon": "media/icons/dokuwiki/toolbar/16/ul.png"}, + "link": {"tip": "Link", "icon": "media/icons/dokuwiki/toolbar/16/linkextern.png"}, + "horizontalrule": {"tip": "Horizontal rule", "icon": "media/icons/dokuwiki/toolbar/16/hr.png"} + } + +# Define here your rich text formats, the key must match the ones used in button. +# Tupples values must have 3 elements : prefix to the selection or cursor +# position, sample text to write if the marker is not applied on a selection, +# suffix to the selection or cursor position. +# FIXME: must not be hard-coded like this +RICH_FORMATS = {"markdown": {"bold": ("**", "bold", "**"), + "italic": ("*", "italic", "*"), + "code": ("`", "code", "`"), + "heading": ("\n# ", "Heading 1", "\n## Heading 2\n"), + "list": ("\n* ", "item", "\n + subitem\n"), + "link": ("[desc](", "link", ")"), + "horizontalrule": ("\n***\n", "", "") + }, + "bbcode": {"bold": ("[b]", "bold", "[/b]"), + "italic": ("[i]", "italic", "[/i]"), + "underline": ("[u]", "underline", "[/u]"), + "strikethrough": ("[s]", "strikethrough", "[/s]"), + "code": ("[code]", "code", "[/code]"), + "link": ("[url=", "link", "]desc[/url]"), + "list": ("\n[list] [*]", "item 1", " [*]item 2 [/list]\n") + }, + "dokuwiki": {"bold": ("**", "bold", "**"), + "italic": ("//", "italic", "//"), + "underline": ("__", "underline", "__"), + "strikethrough": ("", "strikethrough", ""), + "code": ("", "code", ""), + "heading": ("\n==== ", "Heading 1", " ====\n=== Heading 2 ===\n"), + "link": ("[[", "link", "|desc]]"), + "list": ("\n * ", "item\n", "\n * subitem\n"), + "horizontalrule": ("\n----\n", "", "") + }, + "XHTML": {"bold": ("", "bold", ""), + "italic": ("", "italic", ""), + "underline": ("", "underline", ""), + "strikethrough": ("", "strikethrough", ""), + "code": ("
", "code", "
"), + "heading": ("\n

", "Heading 1", "

\n

Heading 2

\n"), + "link": ("desc"), + "list": ("\n
  • ", "item 1", "
  • item 2
\n"), + "horizontalrule": ("\n
\n", "", "") + } + + } + +# These values should be equal to the ones in plugin_misc_text_syntaxes +# FIXME: should the plugin import them from here to avoid duplicity? Importing +# the plugin's values from here is not possible because Libervia would fail. +PARAM_KEY_COMPOSITION = "Composition" +PARAM_NAME_SYNTAX = "Syntax" + diff -r 074970227bc0 -r 56aa0e98c92e frontends/src/tools/games.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/frontends/src/tools/games.py Thu Nov 21 18:57:10 2013 +0100 @@ -0,0 +1,79 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# SAT: a jabber client +# Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org) + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +"""This library help manage general games (e.g. card games) and it is shared by the frontends""" + +SUITS_ORDER = ['pique', 'coeur', 'trefle', 'carreau', 'atout'] # I have switched the usual order 'trefle' and 'carreau' because card are more easy to see if suit colour change (black, red, black, red) +VALUES_ORDER = [str(i) for i in xrange(1, 11)] + ["valet", "cavalier", "dame", "roi"] + + +class TarotCard(object): + """This class is used to represent a car logically""" + + def __init__(self, tuple_card): + """@param tuple_card: tuple (suit, value)""" + self.suit, self.value = tuple_card + self.bout = self.suit == "atout" and self.value in ["1", "21", "excuse"] + if self.bout or self.value == "roi": + self.points = 4.5 + elif self.value == "dame": + self.points = 3.5 + elif self.value == "cavalier": + self.points = 2.5 + elif self.value == "valet": + self.points = 1.5 + else: + self.points = 0.5 + + def get_tuple(self): + return (self.suit, self.value) + + @staticmethod + def from_tuples(tuple_list): + result = [] + for card_tuple in tuple_list: + result.append(TarotCard(card_tuple)) + return result + + def __cmp__(self, other): + if other is None: + return 1 + if self.suit != other.suit: + idx1 = SUITS_ORDER.index(self.suit) + idx2 = SUITS_ORDER.index(other.suit) + return idx1.__cmp__(idx2) + if self.suit == 'atout': + if self.value == other.value == 'excuse': + return 0 + if self.value == 'excuse': + return -1 + if other.value == 'excuse': + return 1 + return int(self.value).__cmp__(int(other.value)) + # at this point we have the same suit which is not 'atout' + idx1 = VALUES_ORDER.index(self.value) + idx2 = VALUES_ORDER.index(other.value) + return idx1.__cmp__(idx2) + + def __str__(self): + return "[%s,%s]" % (self.suit, self.value) + + +# These symbols are diplayed by Libervia next to the player's nicknames +SYMBOLS = {"radiocol": u"♬", "tarot": [u"♠", u"♣", u"♥", u"♦"]} diff -r 074970227bc0 -r 56aa0e98c92e frontends/src/tools/misc.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/frontends/src/tools/misc.py Thu Nov 21 18:57:10 2013 +0100 @@ -0,0 +1,66 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# SAT helpers methods for plugins +# Copyright (C) 2013 Adrien Cossa (souliane@mailoo.org) + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + + +# Default value for the "New discussion room" user input +DEFAULT_MUC = 'sat@chat.jabberfr.org' + + +class InputHistory(object): + + def _updateInputHistory(self, text=None, step=None, callback=None, mode=""): + """Update the lists of previously sent messages. Several lists can be + handled as they are stored in a dictionary, the argument "mode" being + used as the entry key. There's also a temporary list to allow you play + with previous entries before sending a new message. Parameters values + can be combined: text is None and step is None to initialize a main + list and the temporary one, step is None to update a list and + reinitialize the temporary one, step is not None to update + the temporary list between two messages. + @param text: text to be saved. + @param step: step to move the temporary index. + @param callback: method to display temporary entries. + @param mode: the dictionary key for main lists. + """ + if not hasattr(self, "input_histories"): + self.input_histories = {} + history = self.input_histories.setdefault(mode, []) + if step is None and text is not None: + # update the main list + if text in history: + history.remove(text) + history.append(text) + length = len(history) + if step is None or length == 0: + # prepare the temporary list and index + self.input_history_tmp = history[:] + self.input_history_tmp.append("") + self.input_history_index = length + if step is None: + return + # update the temporary list + if text is not None: + # save the current entry + self.input_history_tmp[self.input_history_index] = text + # move to another entry if possible + index_tmp = self.input_history_index + step + if index_tmp >= 0 and index_tmp < len(self.input_history_tmp): + if callback is not None: + callback(self.input_history_tmp[index_tmp]) + self.input_history_index = index_tmp diff -r 074970227bc0 -r 56aa0e98c92e frontends/src/tools/strings.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/frontends/src/tools/strings.py Thu Nov 21 18:57:10 2013 +0100 @@ -0,0 +1,42 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# SAT helpers methods for plugins +# Copyright (C) 2013 Adrien Cossa (souliane@mailoo.org) + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + + +def getURLParams(url): + """This comes from pyjamas.Location.makeUrlDict with a small change + to also parse full URLs, and parameters with no value specified + (in that case the default value "" is used). + @param url: any URL with or without parameters + @return: a dictionary of the parameters, if any was given, or {} + """ + dict_ = {} + if "/" in url: + # keep the part after the last "/" + url = url[url.rindex("/") + 1:] + if url.startswith("?"): + # remove the first "?" + url = url[1:] + pairs = url.split("&") + for pair in pairs: + if len(pair) < 3: + continue + kv = pair.split("=", 1) + dict_[kv[0]] = kv[1] if len(kv) > 1 else "" + return dict_ + diff -r 074970227bc0 -r 56aa0e98c92e frontends/src/tools/xml.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/frontends/src/tools/xml.py Thu Nov 21 18:57:10 2013 +0100 @@ -0,0 +1,48 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# SAT: a jabber client +# Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org) + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +"""This library help manage XML used in SàT frontends """ + +# we don't import minidom as a different class can be used in frontends +# (e.g. NativeDOM in Libervia) + + +def inlineRoot(doc): + """ make the root attribute inline + @param root_node: minidom's Document compatible class + @return: plain XML + """ + root_elt = doc.documentElement + if root_elt.hasAttribute('style'): + styles_raw = root_elt.getAttribute('style') + styles = styles_raw.split(';') + new_styles = [] + for style in styles: + try: + key, value = style.split(':') + except ValueError: + continue + if key.strip().lower() == 'display': + value = 'inline' + new_styles.append('%s: %s' % (key.strip(), value.strip())) + root_elt.setAttribute('style', "; ".join(new_styles)) + else: + root_elt.setAttribute('style', 'display: inline') + return root_elt.toxml() + diff -r 074970227bc0 -r 56aa0e98c92e frontends/src/wix/card_game.py --- a/frontends/src/wix/card_game.py Thu Nov 21 18:23:08 2013 +0100 +++ b/frontends/src/wix/card_game.py Thu Nov 21 18:57:10 2013 +0100 @@ -24,7 +24,7 @@ import pdb from logging import debug, info, error from sat.tools.jid import JID -from sat.tools.frontends.games import TarotCard +from sat_frontends.tools.games import TarotCard from sat_frontends.quick_frontend.quick_card_game import QuickCardGame from sat_frontends.wix.xmlui import XMLUI diff -r 074970227bc0 -r 56aa0e98c92e setup.py --- a/setup.py Thu Nov 21 18:23:08 2013 +0100 +++ b/setup.py Thu Nov 21 18:57:10 2013 +0100 @@ -160,7 +160,7 @@ package_dir={'sat': 'src', 'sat_frontends': 'frontends/src'}, packages=['sat', 'sat.tools', 'sat.bridge', 'sat.plugins', 'sat.test', 'sat.core', 'sat.memory', 'sat_frontends', 'sat_frontends.bridge', 'sat_frontends.quick_frontend', - 'sat_frontends.primitivus', 'sat_frontends.wix'], + 'sat_frontends.primitivus', 'sat_frontends.wix', 'sat_frontends.tools'], package_data={'sat': ['sat.tac', 'sat.sh'], 'sat_frontends': ['wix/COPYING']}, data_files=[(os.path.join(sys.prefix, 'share/locale/fr/LC_MESSAGES'), ['i18n/fr/LC_MESSAGES/sat.mo']), diff -r 074970227bc0 -r 56aa0e98c92e src/plugins/plugin_misc_quiz.py --- a/src/plugins/plugin_misc_quiz.py Thu Nov 21 18:23:08 2013 +0100 +++ b/src/plugins/plugin_misc_quiz.py Thu Nov 21 18:57:10 2013 +0100 @@ -27,7 +27,7 @@ from wokkel import data_form from sat.tools.xml_tools import dataForm2XML -from sat.tools.frontends.games import TarotCard +from sat_frontends.tools.games import TarotCard from time import time diff -r 074970227bc0 -r 56aa0e98c92e src/plugins/plugin_misc_tarot.py --- a/src/plugins/plugin_misc_tarot.py Thu Nov 21 18:23:08 2013 +0100 +++ b/src/plugins/plugin_misc_tarot.py Thu Nov 21 18:57:10 2013 +0100 @@ -23,7 +23,7 @@ from wokkel import data_form from sat.tools.xml_tools import dataForm2XML -from sat.tools.frontends.games import TarotCard +from sat_frontends.tools.games import TarotCard from time import time import random diff -r 074970227bc0 -r 56aa0e98c92e src/tools/frontends/__init__.py diff -r 074970227bc0 -r 56aa0e98c92e src/tools/frontends/composition.py --- a/src/tools/frontends/composition.py Thu Nov 21 18:23:08 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,90 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -""" -Libervia: a Salut à Toi frontend -Copyright (C) 2013 Adrien Cossa - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -""" - -# Map the messages recipient types to their properties. -RECIPIENT_TYPES = {"To": {"desc": "Direct recipients", "optional": False}, - "Cc": {"desc": "Carbon copies", "optional": True}, - "Bcc": {"desc": "Blind carbon copies", "optional": True}} - -# Rich text buttons icons and descriptions -RICH_BUTTONS = { - "bold": {"tip": "Bold", "icon": "media/icons/dokuwiki/toolbar/16/bold.png"}, - "italic": {"tip": "Italic", "icon": "media/icons/dokuwiki/toolbar/16/italic.png"}, - "underline": {"tip": "Underline", "icon": "media/icons/dokuwiki/toolbar/16/underline.png"}, - "code": {"tip": "Code", "icon": "media/icons/dokuwiki/toolbar/16/mono.png"}, - "strikethrough": {"tip": "Strikethrough", "icon": "media/icons/dokuwiki/toolbar/16/strike.png"}, - "heading": {"tip": "Heading", "icon": "media/icons/dokuwiki/toolbar/16/hequal.png"}, - "numberedlist": {"tip": "Numbered List", "icon": "media/icons/dokuwiki/toolbar/16/ol.png"}, - "list": {"tip": "List", "icon": "media/icons/dokuwiki/toolbar/16/ul.png"}, - "link": {"tip": "Link", "icon": "media/icons/dokuwiki/toolbar/16/linkextern.png"}, - "horizontalrule": {"tip": "Horizontal rule", "icon": "media/icons/dokuwiki/toolbar/16/hr.png"} - } - -# Define here your rich text formats, the key must match the ones used in button. -# Tupples values must have 3 elements : prefix to the selection or cursor -# position, sample text to write if the marker is not applied on a selection, -# suffix to the selection or cursor position. -# FIXME: must not be hard-coded like this -RICH_FORMATS = {"markdown": {"bold": ("**", "bold", "**"), - "italic": ("*", "italic", "*"), - "code": ("`", "code", "`"), - "heading": ("\n# ", "Heading 1", "\n## Heading 2\n"), - "list": ("\n* ", "item", "\n + subitem\n"), - "link": ("[desc](", "link", ")"), - "horizontalrule": ("\n***\n", "", "") - }, - "bbcode": {"bold": ("[b]", "bold", "[/b]"), - "italic": ("[i]", "italic", "[/i]"), - "underline": ("[u]", "underline", "[/u]"), - "strikethrough": ("[s]", "strikethrough", "[/s]"), - "code": ("[code]", "code", "[/code]"), - "link": ("[url=", "link", "]desc[/url]"), - "list": ("\n[list] [*]", "item 1", " [*]item 2 [/list]\n") - }, - "dokuwiki": {"bold": ("**", "bold", "**"), - "italic": ("//", "italic", "//"), - "underline": ("__", "underline", "__"), - "strikethrough": ("", "strikethrough", ""), - "code": ("", "code", ""), - "heading": ("\n==== ", "Heading 1", " ====\n=== Heading 2 ===\n"), - "link": ("[[", "link", "|desc]]"), - "list": ("\n * ", "item\n", "\n * subitem\n"), - "horizontalrule": ("\n----\n", "", "") - }, - "XHTML": {"bold": ("", "bold", ""), - "italic": ("", "italic", ""), - "underline": ("", "underline", ""), - "strikethrough": ("", "strikethrough", ""), - "code": ("
", "code", "
"), - "heading": ("\n

", "Heading 1", "

\n

Heading 2

\n"), - "link": ("desc"), - "list": ("\n
  • ", "item 1", "
  • item 2
\n"), - "horizontalrule": ("\n
\n", "", "") - } - - } - -# These values should be equal to the ones in plugin_misc_text_syntaxes -# FIXME: should the plugin import them from here to avoid duplicity? Importing -# the plugin's values from here is not possible because Libervia would fail. -PARAM_KEY_COMPOSITION = "Composition" -PARAM_NAME_SYNTAX = "Syntax" - diff -r 074970227bc0 -r 56aa0e98c92e src/tools/frontends/games.py --- a/src/tools/frontends/games.py Thu Nov 21 18:23:08 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# SAT: a jabber client -# Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org) - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. - -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -"""This library help manage general games (e.g. card games) and it is shared by the frontends""" - -SUITS_ORDER = ['pique', 'coeur', 'trefle', 'carreau', 'atout'] # I have switched the usual order 'trefle' and 'carreau' because card are more easy to see if suit colour change (black, red, black, red) -VALUES_ORDER = [str(i) for i in xrange(1, 11)] + ["valet", "cavalier", "dame", "roi"] - - -class TarotCard(object): - """This class is used to represent a car logically""" - - def __init__(self, tuple_card): - """@param tuple_card: tuple (suit, value)""" - self.suit, self.value = tuple_card - self.bout = self.suit == "atout" and self.value in ["1", "21", "excuse"] - if self.bout or self.value == "roi": - self.points = 4.5 - elif self.value == "dame": - self.points = 3.5 - elif self.value == "cavalier": - self.points = 2.5 - elif self.value == "valet": - self.points = 1.5 - else: - self.points = 0.5 - - def get_tuple(self): - return (self.suit, self.value) - - @staticmethod - def from_tuples(tuple_list): - result = [] - for card_tuple in tuple_list: - result.append(TarotCard(card_tuple)) - return result - - def __cmp__(self, other): - if other is None: - return 1 - if self.suit != other.suit: - idx1 = SUITS_ORDER.index(self.suit) - idx2 = SUITS_ORDER.index(other.suit) - return idx1.__cmp__(idx2) - if self.suit == 'atout': - if self.value == other.value == 'excuse': - return 0 - if self.value == 'excuse': - return -1 - if other.value == 'excuse': - return 1 - return int(self.value).__cmp__(int(other.value)) - # at this point we have the same suit which is not 'atout' - idx1 = VALUES_ORDER.index(self.value) - idx2 = VALUES_ORDER.index(other.value) - return idx1.__cmp__(idx2) - - def __str__(self): - return "[%s,%s]" % (self.suit, self.value) - - -# These symbols are diplayed by Libervia next to the player's nicknames -SYMBOLS = {"radiocol": u"♬", "tarot": [u"♠", u"♣", u"♥", u"♦"]} diff -r 074970227bc0 -r 56aa0e98c92e src/tools/frontends/misc.py --- a/src/tools/frontends/misc.py Thu Nov 21 18:23:08 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# SAT helpers methods for plugins -# Copyright (C) 2013 Adrien Cossa (souliane@mailoo.org) - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. - -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - - -# Default value for the "New discussion room" user input -DEFAULT_MUC = 'sat@chat.jabberfr.org' - - -class InputHistory(object): - - def _updateInputHistory(self, text=None, step=None, callback=None, mode=""): - """Update the lists of previously sent messages. Several lists can be - handled as they are stored in a dictionary, the argument "mode" being - used as the entry key. There's also a temporary list to allow you play - with previous entries before sending a new message. Parameters values - can be combined: text is None and step is None to initialize a main - list and the temporary one, step is None to update a list and - reinitialize the temporary one, step is not None to update - the temporary list between two messages. - @param text: text to be saved. - @param step: step to move the temporary index. - @param callback: method to display temporary entries. - @param mode: the dictionary key for main lists. - """ - if not hasattr(self, "input_histories"): - self.input_histories = {} - history = self.input_histories.setdefault(mode, []) - if step is None and text is not None: - # update the main list - if text in history: - history.remove(text) - history.append(text) - length = len(history) - if step is None or length == 0: - # prepare the temporary list and index - self.input_history_tmp = history[:] - self.input_history_tmp.append("") - self.input_history_index = length - if step is None: - return - # update the temporary list - if text is not None: - # save the current entry - self.input_history_tmp[self.input_history_index] = text - # move to another entry if possible - index_tmp = self.input_history_index + step - if index_tmp >= 0 and index_tmp < len(self.input_history_tmp): - if callback is not None: - callback(self.input_history_tmp[index_tmp]) - self.input_history_index = index_tmp diff -r 074970227bc0 -r 56aa0e98c92e src/tools/frontends/strings.py --- a/src/tools/frontends/strings.py Thu Nov 21 18:23:08 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# SAT helpers methods for plugins -# Copyright (C) 2013 Adrien Cossa (souliane@mailoo.org) - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. - -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - - -def getURLParams(url): - """This comes from pyjamas.Location.makeUrlDict with a small change - to also parse full URLs, and parameters with no value specified - (in that case the default value "" is used). - @param url: any URL with or without parameters - @return: a dictionary of the parameters, if any was given, or {} - """ - dict_ = {} - if "/" in url: - # keep the part after the last "/" - url = url[url.rindex("/") + 1:] - if url.startswith("?"): - # remove the first "?" - url = url[1:] - pairs = url.split("&") - for pair in pairs: - if len(pair) < 3: - continue - kv = pair.split("=", 1) - dict_[kv[0]] = kv[1] if len(kv) > 1 else "" - return dict_ - diff -r 074970227bc0 -r 56aa0e98c92e src/tools/frontends/xml.py --- a/src/tools/frontends/xml.py Thu Nov 21 18:23:08 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# SAT: a jabber client -# Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org) - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. - -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -"""This library help manage XML used in SàT frontends """ - -# we don't import minidom as a different class can be used in frontends -# (e.g. NativeDOM in Libervia) - - -def inlineRoot(doc): - """ make the root attribute inline - @param root_node: minidom's Document compatible class - @return: plain XML - """ - root_elt = doc.documentElement - if root_elt.hasAttribute('style'): - styles_raw = root_elt.getAttribute('style') - styles = styles_raw.split(';') - new_styles = [] - for style in styles: - try: - key, value = style.split(':') - except ValueError: - continue - if key.strip().lower() == 'display': - value = 'inline' - new_styles.append('%s: %s' % (key.strip(), value.strip())) - root_elt.setAttribute('style', "; ".join(new_styles)) - else: - root_elt.setAttribute('style', 'display: inline') - return root_elt.toxml() - diff -r 074970227bc0 -r 56aa0e98c92e src/tools/plugins/__init__.py