smileys settings

This commit is contained in:
ingvar1995 2016-06-11 15:37:52 +03:00
parent a0b23b0faa
commit 94eb292b16
9 changed files with 73 additions and 41 deletions

View File

@ -65,7 +65,7 @@ class MessageEdit(QtGui.QTextBrowser):
self.setLineWrapColumnOrWidth(self.lineWrapColumnOrWidth()) self.setLineWrapColumnOrWidth(self.lineWrapColumnOrWidth())
def setDecoratedText(self, text): def setDecoratedText(self, text):
text = cgi.escape(text) text = cgi.escape(text) # replace < and >
exp = QtCore.QRegExp( exp = QtCore.QRegExp(
'(' '('
'(?:\\b)((www\\.)|(http[s]?|ftp)://)' '(?:\\b)((www\\.)|(http[s]?|ftp)://)'
@ -75,7 +75,7 @@ class MessageEdit(QtGui.QTextBrowser):
'|(?:\\b)(mailto:\\S+@\\S+\\.\\S+)' '|(?:\\b)(mailto:\\S+@\\S+\\.\\S+)'
'|(?:\\b)(tox:\\S+@\\S+)') '|(?:\\b)(tox:\\S+@\\S+)')
offset = exp.indexIn(text, 0) offset = exp.indexIn(text, 0)
while offset != -1: while offset != -1: # add links
url = exp.cap() url = exp.cap()
if exp.cap(2) == 'www.': if exp.cap(2) == 'www.':
html = '<a href="http://{0}">{0}</a>'.format(url) html = '<a href="http://{0}">{0}</a>'.format(url)
@ -85,11 +85,11 @@ class MessageEdit(QtGui.QTextBrowser):
offset += len(html) offset += len(html)
offset = exp.indexIn(text, offset) offset = exp.indexIn(text, offset)
arr = text.split('\n') arr = text.split('\n')
for i in range(len(arr)): for i in range(len(arr)): # quotes
if arr[i].startswith('&gt;'): if arr[i].startswith('&gt;'):
arr[i] = '<font color="green">' + arr[i][4:] + '</font>' arr[i] = '<font color="green">' + arr[i][4:] + '</font>'
text = '<br>'.join(arr) text = '<br>'.join(arr)
text = smileys.SmileyLoader.get_instance().add_smileys_to_text(text, self) text = smileys.SmileyLoader.get_instance().add_smileys_to_text(text, self) # smileys
self.setHtml(text) self.setHtml(text)

View File

@ -9,7 +9,7 @@ from bootstrap import node_generator
from mainscreen import MainWindow from mainscreen import MainWindow
from profile import tox_factory from profile import tox_factory
from callbacks import init_callbacks from callbacks import init_callbacks
from util import curr_directory, get_style from util import curr_directory
import styles.style import styles.style
import locale import locale
import toxencryptsave import toxencryptsave
@ -198,7 +198,6 @@ class Toxygen(object):
self.tray.show() self.tray.show()
self.ms.show() self.ms.show()
QtGui.QApplication.setStyle(get_style(settings['theme'])) # set application style
plugin_helper = PluginLoader(self.tox, settings) # plugin support plugin_helper = PluginLoader(self.tox, settings) # plugin support
plugin_helper.load() plugin_helper.load()

View File

@ -65,6 +65,7 @@ class MessageArea(QtGui.QPlainTextEdit):
class MainWindow(QtGui.QMainWindow): class MainWindow(QtGui.QMainWindow):
# TODO: add mirror mode
def __init__(self, tox, reset, tray): def __init__(self, tox, reset, tray):
super(MainWindow, self).__init__() super(MainWindow, self).__init__()

View File

@ -4,7 +4,7 @@ except ImportError:
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from settings import * from settings import *
from profile import Profile from profile import Profile
from util import get_style, curr_directory from util import curr_directory
from widgets import CenteredWidget, DataLabel from widgets import CenteredWidget, DataLabel
import pyaudio import pyaudio
import toxencryptsave import toxencryptsave
@ -481,7 +481,6 @@ class NotificationsSettings(CenteredWidget):
class InterfaceSettings(CenteredWidget): class InterfaceSettings(CenteredWidget):
"""Interface settings form""" """Interface settings form"""
# TODO: add smileys support and drop themes support
def __init__(self): def __init__(self):
super(InterfaceSettings, self).__init__() super(InterfaceSettings, self).__init__()
self.initUI() self.initUI()
@ -489,12 +488,12 @@ class InterfaceSettings(CenteredWidget):
def initUI(self): def initUI(self):
self.setObjectName("interfaceForm") self.setObjectName("interfaceForm")
self.resize(300, 300) self.resize(300, 320)
self.setMinimumSize(QtCore.QSize(300, 300)) self.setMinimumSize(QtCore.QSize(300, 320))
self.setMaximumSize(QtCore.QSize(300, 300)) self.setMaximumSize(QtCore.QSize(300, 320))
self.setBaseSize(QtCore.QSize(300, 300)) self.setBaseSize(QtCore.QSize(300, 320))
self.label = QtGui.QLabel(self) self.label = QtGui.QLabel(self)
self.label.setGeometry(QtCore.QRect(30, 20, 91, 21)) self.label.setGeometry(QtCore.QRect(30, 10, 100, 20))
font = QtGui.QFont() font = QtGui.QFont()
font.setPointSize(16) font.setPointSize(16)
font.setWeight(75) font.setWeight(75)
@ -502,16 +501,19 @@ class InterfaceSettings(CenteredWidget):
self.label.setFont(font) self.label.setFont(font)
self.label.setObjectName("label") self.label.setObjectName("label")
self.themeSelect = QtGui.QComboBox(self) self.themeSelect = QtGui.QComboBox(self)
self.themeSelect.setGeometry(QtCore.QRect(30, 60, 160, 30)) self.themeSelect.setGeometry(QtCore.QRect(30, 40, 160, 30))
self.themeSelect.setObjectName("themeSelect") self.themeSelect.setObjectName("themeSelect")
list_of_themes = ['default', 'windows', 'gtk', 'cde', 'plastique', 'motif'] list_of_themes = ['dark']
self.themeSelect.addItems(list_of_themes) self.themeSelect.addItems(list_of_themes)
settings = Settings.get_instance() settings = Settings.get_instance()
theme = settings['theme'] theme = settings['theme']
if theme in list_of_themes:
index = list_of_themes.index(theme) index = list_of_themes.index(theme)
else:
index = 0
self.themeSelect.setCurrentIndex(index) self.themeSelect.setCurrentIndex(index)
self.lang_choose = QtGui.QComboBox(self) self.lang_choose = QtGui.QComboBox(self)
self.lang_choose.setGeometry(QtCore.QRect(30, 150, 160, 30)) self.lang_choose.setGeometry(QtCore.QRect(30, 110, 160, 30))
self.lang_choose.setObjectName("comboBox") self.lang_choose.setObjectName("comboBox")
supported = Settings.supported_languages() supported = Settings.supported_languages()
for elem in supported: for elem in supported:
@ -520,8 +522,27 @@ class InterfaceSettings(CenteredWidget):
index = map(lambda x: x[0], supported).index(lang) index = map(lambda x: x[0], supported).index(lang)
self.lang_choose.setCurrentIndex(index) self.lang_choose.setCurrentIndex(index)
self.lang = QtGui.QLabel(self) self.lang = QtGui.QLabel(self)
self.lang.setGeometry(QtCore.QRect(30, 110, 121, 31)) self.lang.setGeometry(QtCore.QRect(30, 80, 121, 20))
self.lang.setFont(font) self.lang.setFont(font)
self.mirror_mode = QtGui.QCheckBox(self)
self.mirror_mode.setGeometry(QtCore.QRect(30, 160, 120, 20))
self.mirror_mode.setChecked(settings['mirror_mode'])
self.smileys = QtGui.QCheckBox(self)
self.smileys.setGeometry(QtCore.QRect(30, 190, 120, 20))
self.smileys.setChecked(settings['smileys'])
self.smiley_pack_label = QtGui.QLabel(self)
self.smiley_pack_label.setGeometry(QtCore.QRect(30, 230, 120, 20))
self.smiley_pack_label.setFont(font)
self.smiley_pack = QtGui.QComboBox(self)
self.smiley_pack.setGeometry(QtCore.QRect(30, 260, 160, 30))
sm = smileys.SmileyLoader.get_instance()
self.smiley_pack.addItems(sm.get_packs_list())
print sm.get_packs_list()
try:
ind = sm.get_packs_list().index(settings['smiley_pack'])
except:
ind = sm.get_packs_list().index('default')
self.smiley_pack.setCurrentIndex(ind)
self.retranslateUi() self.retranslateUi()
QtCore.QMetaObject.connectSlotsByName(self) QtCore.QMetaObject.connectSlotsByName(self)
@ -529,12 +550,17 @@ class InterfaceSettings(CenteredWidget):
self.setWindowTitle(QtGui.QApplication.translate("interfaceForm", "Interface settings", None, QtGui.QApplication.UnicodeUTF8)) self.setWindowTitle(QtGui.QApplication.translate("interfaceForm", "Interface settings", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("interfaceForm", "Theme:", None, QtGui.QApplication.UnicodeUTF8)) self.label.setText(QtGui.QApplication.translate("interfaceForm", "Theme:", None, QtGui.QApplication.UnicodeUTF8))
self.lang.setText(QtGui.QApplication.translate("interfaceForm", "Language:", None, QtGui.QApplication.UnicodeUTF8)) self.lang.setText(QtGui.QApplication.translate("interfaceForm", "Language:", None, QtGui.QApplication.UnicodeUTF8))
self.smileys.setText(QtGui.QApplication.translate("interfaceForm", "Smileys", None, QtGui.QApplication.UnicodeUTF8))
self.smiley_pack_label.setText(QtGui.QApplication.translate("interfaceForm", "Smiley pack:", None, QtGui.QApplication.UnicodeUTF8))
self.mirror_mode.setText(QtGui.QApplication.translate("interfaceForm", "Mirror mode", None, QtGui.QApplication.UnicodeUTF8))
def closeEvent(self, event): def closeEvent(self, event):
settings = Settings.get_instance() settings = Settings.get_instance()
style = str(self.themeSelect.currentText()) settings['theme'] = str(self.themeSelect.currentText())
settings['theme'] = style settings['smileys'] = self.smileys.isChecked()
QtGui.QApplication.setStyle(get_style(style)) settings['mirror_mode'] = self.mirror_mode.isChecked()
settings['smiley_pack'] = self.smiley_pack.currentText()
smileys.SmileyLoader.get_instance().load_pack()
language = self.lang_choose.currentText() language = self.lang_choose.currentText()
if settings['language'] != language: if settings['language'] != language:
settings['language'] = language settings['language'] = language

View File

@ -85,7 +85,8 @@ class Settings(Singleton, dict):
'plugins': [], 'plugins': [],
'notes': {}, 'notes': {},
'smileys': True, 'smileys': True,
'smiley_pack': 'default' 'smiley_pack': 'default',
'mirror_mode': False
} }
@staticmethod @staticmethod

View File

@ -1,5 +1,6 @@
import util import util
import json import json
import os
try: try:
from PySide import QtCore from PySide import QtCore
except ImportError: except ImportError:
@ -7,21 +8,27 @@ except ImportError:
class SmileyLoader(util.Singleton): class SmileyLoader(util.Singleton):
"""
Class which loads smileys packs and insert smileys into messages
"""
def __init__(self, settings): def __init__(self, settings):
self.settings = settings self.settings = settings
self.curr_pack = None self.curr_pack = None # current pack name
self.smiles = {} self.smileys = {} # smileys dict. key - smiley (str), value - path to image (str)
self.load_pack() self.load_pack()
def load_pack(self): def load_pack(self):
"""
Loads smiley pack
"""
pack_name = self.settings['smiley_pack'] pack_name = self.settings['smiley_pack']
if self.settings['smileys'] and self.curr_pack != pack_name: if self.settings['smileys'] and self.curr_pack != pack_name:
self.curr_pack = pack_name self.curr_pack = pack_name
path = self.get_smileys_path() + 'config.json' path = self.get_smileys_path() + 'config.json'
try: try:
with open(path) as fl: with open(path) as fl:
self.smiles = json.loads(fl.read()) self.smileys = json.loads(fl.read())
print 'Smiley pack', pack_name, 'loaded' print 'Smiley pack', pack_name, 'loaded'
except: except:
print 'Smiley pack', pack_name, 'was not loaded' print 'Smiley pack', pack_name, 'was not loaded'
@ -29,14 +36,24 @@ class SmileyLoader(util.Singleton):
def get_smileys_path(self): def get_smileys_path(self):
return util.curr_directory() + '/smileys/' + self.curr_pack + '/' return util.curr_directory() + '/smileys/' + self.curr_pack + '/'
def get_packs_list(self):
d = util.curr_directory() + '/smileys/'
return [x[1] for x in os.walk(d)][0]
def add_smileys_to_text(self, text, edit): def add_smileys_to_text(self, text, edit):
"""
Adds smileys to text
:param text: message
:param edit: MessageEdit instance
:return text with smileys
"""
if not self.settings['smileys']: if not self.settings['smileys']:
return text return text
arr = text.split(' ') arr = text.split(' ')
for i in range(len(arr)): for i in range(len(arr)):
if arr[i] in self.smiles: if arr[i] in self.smileys:
file_name = self.smiles[arr[i]] file_name = self.smileys[arr[i]] # image name
arr[i] = u'<img title=\"{}\" src=\"{}\" />'.format(arr[i], file_name) arr[i] = u'<img title=\"{}\" src=\"{}\" />'.format(arr[i], file_name)
if file_name.endswith('.gif'): if file_name.endswith('.gif'): # animated smiley
edit.addAnimation(QtCore.QUrl(file_name), self.get_smileys_path() + file_name) edit.addAnimation(QtCore.QUrl(file_name), self.get_smileys_path() + file_name)
return ' '.join(arr) return ' '.join(arr)

File diff suppressed because one or more lines are too long

BIN
src/smileys/default/tox.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

@ -1,6 +1,5 @@
import os import os
import time import time
from platform import system
program_version = '0.1.3' program_version = '0.1.3'
@ -27,17 +26,6 @@ def convert_time(t):
return '%02d:%02d' % (h, m) return '%02d:%02d' % (h, m)
# obsolete
def get_style(style):
if style != 'default':
return style
else:
if system() == 'Windows':
return 'windows'
else:
return 'gtk'
class Singleton(object): class Singleton(object):
def __new__(cls, *args, **kwargs): def __new__(cls, *args, **kwargs):