frontends tools: moved src/tools/frontends to frontends/src/tools
This commit is contained in:
parent
674a3e958d
commit
d7d411d6ef
13 changed files with 6 additions and 6 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ from sat_frontends.primitivus.gateways import GatewaysManager
|
|||
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
|
||||
|
|
|
|||
90
frontends/src/tools/composition.py
Normal file
90
frontends/src/tools/composition.py
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Libervia: a Salut à Toi frontend
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
# 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": ("<del>", "strikethrough", "</del>"),
|
||||
"code": ("<code>", "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": ("<b>", "bold", "</b>"),
|
||||
"italic": ("<i>", "italic", "</i>"),
|
||||
"underline": ("<u>", "underline", "</u>"),
|
||||
"strikethrough": ("<s>", "strikethrough", "</s>"),
|
||||
"code": ("<pre>", "code", "</pre>"),
|
||||
"heading": ("\n<h3>", "Heading 1", "</h3>\n<h4>Heading 2</h4>\n"),
|
||||
"link": ("<a href=\"", "link", "\">desc</a>"),
|
||||
"list": ("\n<ul><li>", "item 1", "</li><li>item 2</li></ul>\n"),
|
||||
"horizontalrule": ("\n<hr/>\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"
|
||||
|
||||
79
frontends/src/tools/games.py
Normal file
79
frontends/src/tools/games.py
Normal file
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""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"♦"]}
|
||||
66
frontends/src/tools/misc.py
Normal file
66
frontends/src/tools/misc.py
Normal file
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
# 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
|
||||
42
frontends/src/tools/strings.py
Normal file
42
frontends/src/tools/strings.py
Normal file
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
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_
|
||||
|
||||
48
frontends/src/tools/xml.py
Normal file
48
frontends/src/tools/xml.py
Normal file
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""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()
|
||||
|
||||
|
|
@ -24,7 +24,7 @@ import os.path, glob
|
|||
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
|
||||
|
||||
|
|
|
|||
2
setup.py
2
setup.py
|
|
@ -160,7 +160,7 @@ setup(name=NAME,
|
|||
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']),
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import random
|
|||
|
||||
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
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ from twisted.words.protocols.jabber import jid
|
|||
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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue