smileys settings
This commit is contained in:
parent
a0b23b0faa
commit
94eb292b16
@ -65,7 +65,7 @@ class MessageEdit(QtGui.QTextBrowser):
|
||||
self.setLineWrapColumnOrWidth(self.lineWrapColumnOrWidth())
|
||||
|
||||
def setDecoratedText(self, text):
|
||||
text = cgi.escape(text)
|
||||
text = cgi.escape(text) # replace < and >
|
||||
exp = QtCore.QRegExp(
|
||||
'('
|
||||
'(?:\\b)((www\\.)|(http[s]?|ftp)://)'
|
||||
@ -75,7 +75,7 @@ class MessageEdit(QtGui.QTextBrowser):
|
||||
'|(?:\\b)(mailto:\\S+@\\S+\\.\\S+)'
|
||||
'|(?:\\b)(tox:\\S+@\\S+)')
|
||||
offset = exp.indexIn(text, 0)
|
||||
while offset != -1:
|
||||
while offset != -1: # add links
|
||||
url = exp.cap()
|
||||
if exp.cap(2) == 'www.':
|
||||
html = '<a href="http://{0}">{0}</a>'.format(url)
|
||||
@ -85,11 +85,11 @@ class MessageEdit(QtGui.QTextBrowser):
|
||||
offset += len(html)
|
||||
offset = exp.indexIn(text, offset)
|
||||
arr = text.split('\n')
|
||||
for i in range(len(arr)):
|
||||
for i in range(len(arr)): # quotes
|
||||
if arr[i].startswith('>'):
|
||||
arr[i] = '<font color="green">' + arr[i][4:] + '</font>'
|
||||
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)
|
||||
|
||||
|
||||
|
@ -9,7 +9,7 @@ from bootstrap import node_generator
|
||||
from mainscreen import MainWindow
|
||||
from profile import tox_factory
|
||||
from callbacks import init_callbacks
|
||||
from util import curr_directory, get_style
|
||||
from util import curr_directory
|
||||
import styles.style
|
||||
import locale
|
||||
import toxencryptsave
|
||||
@ -198,7 +198,6 @@ class Toxygen(object):
|
||||
self.tray.show()
|
||||
|
||||
self.ms.show()
|
||||
QtGui.QApplication.setStyle(get_style(settings['theme'])) # set application style
|
||||
|
||||
plugin_helper = PluginLoader(self.tox, settings) # plugin support
|
||||
plugin_helper.load()
|
||||
|
@ -65,6 +65,7 @@ class MessageArea(QtGui.QPlainTextEdit):
|
||||
|
||||
|
||||
class MainWindow(QtGui.QMainWindow):
|
||||
# TODO: add mirror mode
|
||||
|
||||
def __init__(self, tox, reset, tray):
|
||||
super(MainWindow, self).__init__()
|
||||
|
54
src/menu.py
54
src/menu.py
@ -4,7 +4,7 @@ except ImportError:
|
||||
from PyQt4 import QtCore, QtGui
|
||||
from settings import *
|
||||
from profile import Profile
|
||||
from util import get_style, curr_directory
|
||||
from util import curr_directory
|
||||
from widgets import CenteredWidget, DataLabel
|
||||
import pyaudio
|
||||
import toxencryptsave
|
||||
@ -481,7 +481,6 @@ class NotificationsSettings(CenteredWidget):
|
||||
|
||||
class InterfaceSettings(CenteredWidget):
|
||||
"""Interface settings form"""
|
||||
# TODO: add smileys support and drop themes support
|
||||
def __init__(self):
|
||||
super(InterfaceSettings, self).__init__()
|
||||
self.initUI()
|
||||
@ -489,12 +488,12 @@ class InterfaceSettings(CenteredWidget):
|
||||
|
||||
def initUI(self):
|
||||
self.setObjectName("interfaceForm")
|
||||
self.resize(300, 300)
|
||||
self.setMinimumSize(QtCore.QSize(300, 300))
|
||||
self.setMaximumSize(QtCore.QSize(300, 300))
|
||||
self.setBaseSize(QtCore.QSize(300, 300))
|
||||
self.resize(300, 320)
|
||||
self.setMinimumSize(QtCore.QSize(300, 320))
|
||||
self.setMaximumSize(QtCore.QSize(300, 320))
|
||||
self.setBaseSize(QtCore.QSize(300, 320))
|
||||
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.setPointSize(16)
|
||||
font.setWeight(75)
|
||||
@ -502,16 +501,19 @@ class InterfaceSettings(CenteredWidget):
|
||||
self.label.setFont(font)
|
||||
self.label.setObjectName("label")
|
||||
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")
|
||||
list_of_themes = ['default', 'windows', 'gtk', 'cde', 'plastique', 'motif']
|
||||
list_of_themes = ['dark']
|
||||
self.themeSelect.addItems(list_of_themes)
|
||||
settings = Settings.get_instance()
|
||||
theme = settings['theme']
|
||||
if theme in list_of_themes:
|
||||
index = list_of_themes.index(theme)
|
||||
else:
|
||||
index = 0
|
||||
self.themeSelect.setCurrentIndex(index)
|
||||
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")
|
||||
supported = Settings.supported_languages()
|
||||
for elem in supported:
|
||||
@ -520,8 +522,27 @@ class InterfaceSettings(CenteredWidget):
|
||||
index = map(lambda x: x[0], supported).index(lang)
|
||||
self.lang_choose.setCurrentIndex(index)
|
||||
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.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()
|
||||
QtCore.QMetaObject.connectSlotsByName(self)
|
||||
|
||||
@ -529,12 +550,17 @@ class InterfaceSettings(CenteredWidget):
|
||||
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.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):
|
||||
settings = Settings.get_instance()
|
||||
style = str(self.themeSelect.currentText())
|
||||
settings['theme'] = style
|
||||
QtGui.QApplication.setStyle(get_style(style))
|
||||
settings['theme'] = str(self.themeSelect.currentText())
|
||||
settings['smileys'] = self.smileys.isChecked()
|
||||
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()
|
||||
if settings['language'] != language:
|
||||
settings['language'] = language
|
||||
|
@ -85,7 +85,8 @@ class Settings(Singleton, dict):
|
||||
'plugins': [],
|
||||
'notes': {},
|
||||
'smileys': True,
|
||||
'smiley_pack': 'default'
|
||||
'smiley_pack': 'default',
|
||||
'mirror_mode': False
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
|
@ -1,5 +1,6 @@
|
||||
import util
|
||||
import json
|
||||
import os
|
||||
try:
|
||||
from PySide import QtCore
|
||||
except ImportError:
|
||||
@ -7,21 +8,27 @@ except ImportError:
|
||||
|
||||
|
||||
class SmileyLoader(util.Singleton):
|
||||
"""
|
||||
Class which loads smileys packs and insert smileys into messages
|
||||
"""
|
||||
|
||||
def __init__(self, settings):
|
||||
self.settings = settings
|
||||
self.curr_pack = None
|
||||
self.smiles = {}
|
||||
self.curr_pack = None # current pack name
|
||||
self.smileys = {} # smileys dict. key - smiley (str), value - path to image (str)
|
||||
self.load_pack()
|
||||
|
||||
def load_pack(self):
|
||||
"""
|
||||
Loads smiley pack
|
||||
"""
|
||||
pack_name = self.settings['smiley_pack']
|
||||
if self.settings['smileys'] and self.curr_pack != pack_name:
|
||||
self.curr_pack = pack_name
|
||||
path = self.get_smileys_path() + 'config.json'
|
||||
try:
|
||||
with open(path) as fl:
|
||||
self.smiles = json.loads(fl.read())
|
||||
self.smileys = json.loads(fl.read())
|
||||
print 'Smiley pack', pack_name, 'loaded'
|
||||
except:
|
||||
print 'Smiley pack', pack_name, 'was not loaded'
|
||||
@ -29,14 +36,24 @@ class SmileyLoader(util.Singleton):
|
||||
def get_smileys_path(self):
|
||||
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):
|
||||
"""
|
||||
Adds smileys to text
|
||||
:param text: message
|
||||
:param edit: MessageEdit instance
|
||||
:return text with smileys
|
||||
"""
|
||||
if not self.settings['smileys']:
|
||||
return text
|
||||
arr = text.split(' ')
|
||||
for i in range(len(arr)):
|
||||
if arr[i] in self.smiles:
|
||||
file_name = self.smiles[arr[i]]
|
||||
if arr[i] in self.smileys:
|
||||
file_name = self.smileys[arr[i]] # image 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)
|
||||
return ' '.join(arr)
|
||||
|
File diff suppressed because one or more lines are too long
BIN
src/smileys/default/tox.png
Executable file
BIN
src/smileys/default/tox.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 3.3 KiB |
12
src/util.py
12
src/util.py
@ -1,6 +1,5 @@
|
||||
import os
|
||||
import time
|
||||
from platform import system
|
||||
|
||||
|
||||
program_version = '0.1.3'
|
||||
@ -27,17 +26,6 @@ def convert_time(t):
|
||||
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):
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
|
Loading…
Reference in New Issue
Block a user