Skip to content

Commit

Permalink
LC-115 Change font/size from gui, not css
Browse files Browse the repository at this point in the history
  • Loading branch information
DeForce committed Oct 30, 2016
1 parent 4418db2 commit 5c3488d
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 29 deletions.
23 changes: 22 additions & 1 deletion gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,15 @@ def create_dropdown(self, parent, view, key, section, section_gui, section_item=
item_box.SetSelection(choices.index(item_value))
return item_text, item_box

def create_spin(self, parent, view, key, section, section_gui, section_item=False, short_key=None):
item_text = wx.StaticText(parent, label=translate_key(key),
style=wx.ALIGN_RIGHT)
key = key if section_item else MODULE_KEY.join([key, 'spin'])
value = short_key if section_item else section
item_box = wx.SpinCtrl(parent, id=id_renew(key, update=True), min=section_gui['min'], max=section_gui['max'],
initial=value)
return item_text, item_box

def create_item(self, parent, view, key, section, section_gui):
flex_grid = wx.FlexGridSizer(0, 2, ITEM_SPACING_VERT, ITEM_SPACING_HORZ)
if not section:
Expand All @@ -464,6 +473,11 @@ def create_item(self, parent, view, key, section, section_gui):
section_item=True, short_key=item)
flex_grid.Add(text)
flex_grid.Add(control)
elif 'spin' in section_gui[item].get('view'):
text, control = self.create_spin(parent, view, item_name, section, section_gui[item],
section_item=True, short_key=section[item])
flex_grid.Add(text)
flex_grid.Add(control)
else:
# Checking type of an item
style = wx.ALIGN_CENTER_VERTICAL
Expand All @@ -483,7 +497,7 @@ def create_item(self, parent, view, key, section, section_gui):
item_box = wx.TextCtrl(parent, id=id_renew(item_name, update=True),
value=str(value).decode('utf-8'))
item_text = wx.StaticText(parent, label=translate_key(item_name),
style=wx.ALIGN_RIGHT)
style=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_HORIZONTAL)
flex_grid.Add(item_text)
flex_grid.Add(item_box)
flex_grid.Fit(parent)
Expand All @@ -510,6 +524,9 @@ def button_clicked(self, event):
self.on_exit(event)
else:
event.StopPropagation()
module_class = self.main_class.loaded_modules[module_name].get('class')
if module_class:
module_class.apply_settings()
self.settings_saved = True
elif keys[-1] == 'cancel_button':
self.on_close(event)
Expand Down Expand Up @@ -622,6 +639,10 @@ def save_settings(self, module):
item_value = wx_window.get_key_from_index(item_id)
parser.set(section, item_name, item_value)
module_config[section][item_name] = item_value
elif isinstance(wx_window, wx.SpinCtrl):
item_value = wx_window.GetValue()
parser.set(section, item_name, item_value)
module_config[section][item_name] = item_value
with open(module_settings['file'], 'w') as config_file:
parser.write(config_file)
return non_dynamic_check
Expand Down
2 changes: 1 addition & 1 deletion http/czt/css/czt.css → http/czt/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ body{
.msg{
background-color: rgba( 35, 35, 37, 0.627451 );
font-family: 'Consolas', serif;
font-size: 13pt;
font-size: {{ font_size }}pt;
text-shadow: 0 1px 1px black;
padding-top: 2px;
word-wrap: break-word;
Expand Down
2 changes: 1 addition & 1 deletion http/czt/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />

<script src="js/socket.js"></script>
<link rel="stylesheet" type="text/css" href="css/czt.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>

<body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ body{
.msg{
background-color: rgba( 35, 35, 37, 0.627451 );
font-family: 'Consolas', serif;
font-size: 13pt;
font-size: {{ font_size }}pt;
text-shadow: 0 1px 1px black;
padding-top: 2px;
word-wrap: break-word;
Expand Down
2 changes: 1 addition & 1 deletion http/czt_timed/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />

<link rel="stylesheet" type="text/css" href="css/czt.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script src="js/socket.js"></script>
</head>

Expand Down
3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ def close():
# Actually loading modules
for f_module, f_config in loaded_modules.iteritems():
if 'class' in f_config:
f_config['class'].load_module(main_settings=main_config, loaded_modules=loaded_modules)
f_config['class'].load_module(main_settings=main_config, loaded_modules=loaded_modules,
queue=queue)
try:
load_translations_keys(TRANSLATION_FOLDER, gui_settings['language'])
except:
Expand Down
3 changes: 3 additions & 0 deletions modules/helper/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ def load_module(self, *args, **kwargs):
def gui_button_press(self, *args):
pass

def apply_settings(self):
pass


class MessagingModule(BaseModule):
def __init__(self, *args, **kwargs):
Expand Down
72 changes: 55 additions & 17 deletions modules/messaging/webchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import json
import Queue
import socket
from collections import OrderedDict

import cherrypy
import logging
from collections import OrderedDict
from jinja2 import Template
from cherrypy.lib.static import serve_file
from time import sleep
from ws4py.server.cherrypyserver import WebSocketPlugin, WebSocketTool
Expand Down Expand Up @@ -106,6 +106,18 @@ def get_history(self):
return self.history


class CssRoot(object):
def __init__(self, http_folder, settings):
object.__init__(self)
self.http_folder = http_folder
self.settings = settings

@cherrypy.expose()
def style_css(self):
with open(os.path.join(self.http_folder, 'css', 'style.css'), 'r') as css:
return Template(css.read()).render(**self.settings)


class HttpRoot(object):
def __init__(self, http_folder):
object.__init__(self)
Expand All @@ -132,10 +144,10 @@ def __init__(self, host, port, root_folder, **kwargs):
self.port = port
self.root_folder = root_folder
self.style = kwargs.pop('style')
self.settings = kwargs.pop('settings')

cherrypy.config.update({'server.socket_port': int(self.port), 'server.socket_host': self.host,
'engine.autoreload.on': False
})
'engine.autoreload.on': False})
WebChatPlugin(cherrypy.engine).subscribe()
cherrypy.tools.websocket = WebSocketTool()

Expand All @@ -149,15 +161,27 @@ def run(self):
cherrypy.log.access_log.propagate = False
cherrypy.log.error_log.setLevel(logging.ERROR)

cherrypy.quickstart(HttpRoot(http_folder), '/',
config={'/ws': {'tools.websocket.on': True,
'tools.websocket.handler_cls': WebChatSocketServer},
'/js': {'tools.staticdir.on': True,
'tools.staticdir.dir': os.path.join(http_folder, 'js')},
'/css': {'tools.staticdir.on': True,
'tools.staticdir.dir': os.path.join(http_folder, 'css')},
'/img': {'tools.staticdir.on': True,
'tools.staticdir.dir': os.path.join(http_folder, 'img')}})
config = {
'/ws': {'tools.websocket.on': True,
'tools.websocket.handler_cls': WebChatSocketServer},
'/js': {'tools.staticdir.on': True,
'tools.staticdir.dir': os.path.join(http_folder, 'js')},
'/img': {'tools.staticdir.on': True,
'tools.staticdir.dir': os.path.join(http_folder, 'img')}}

cherrypy.tree.mount(HttpRoot(http_folder), '', config)
cherrypy.tree.mount(CssRoot(http_folder, self.settings), '/css')

cherrypy.engine.start()
cherrypy.engine.block()

# cherrypy.quickstart(HttpRoot(http_folder), '/',
# config={'/ws': {'tools.websocket.on': True,
# 'tools.websocket.handler_cls': WebChatSocketServer},
# '/js': {'tools.staticdir.on': True,
# 'tools.staticdir.dir': os.path.join(http_folder, 'js')},
# '/img': {'tools.staticdir.on': True,
# 'tools.staticdir.dir': os.path.join(http_folder, 'img')}})


def socket_open(host, port):
Expand All @@ -169,7 +193,6 @@ def socket_open(host, port):
class webchat(MessagingModule):
def __init__(self, conf_folder, **kwargs):
MessagingModule.__init__(self)
main_settings = kwargs.get('main_settings')
conf_file = os.path.join(conf_folder, "webchat.cfg")
conf_dict = OrderedDict()
conf_dict['gui_information'] = {
Expand All @@ -180,11 +203,18 @@ def __init__(self, conf_folder, **kwargs):
conf_dict['server']['host'] = '127.0.0.1'
conf_dict['server']['port'] = '8080'
conf_dict['style'] = 'czt'
conf_dict['style_settings'] = {
'font_size': 15
}
conf_gui = {
'style': {
'check': 'http',
'check_type': 'dir',
'view': 'choose_single'},
'style_settings': {
'font_size': {'view': 'spin',
'min': 10,
'max': 100}},
'non_dynamic': ['server.*']}

config = self_heal(conf_file, conf_dict)
Expand All @@ -205,16 +235,18 @@ def __init__(self, conf_folder, **kwargs):
'host': conf_dict['server']['host'],
'port': conf_dict['server']['port'],
'style_location': style_location}

self.queue = None
self.message_threads = []

def load_module(self, *args, **kwargs):
self.queue = kwargs.get('queue')
conf_dict = self._conf_params
host = conf_dict['host']
port = conf_dict['port']

if socket_open(host, port):
s_thread = SocketThread(host, port, CONF_FOLDER, style=self._conf_params['style_location'])
s_thread = SocketThread(host, port, CONF_FOLDER, style=self._conf_params['style_location'],
settings=self._conf_params['config']['style_settings'])
s_thread.start()

for thread in range(THREADS+5):
Expand All @@ -223,11 +255,17 @@ def load_module(self, *args, **kwargs):
else:
log.error("Port is already used, please change webchat port")

def reload_chat(self):
self.queue.put({'command': 'reload'})

def apply_settings(self):
self.reload_chat()

def gui_button_press(self, gui_module, event, list_keys):
log.debug("Received button press for id {0}".format(event.GetId()))
keys = MODULE_KEY.join(list_keys)
if keys == 'menu.reload':
gui_module.queue.put({'command': 'reload'})
self.reload_chat()
event.Skip()

def process_message(self, message, queue, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
name='LalkaChat',
version=VERSION,
packages=['', 'modules', 'modules.helpers', 'modules.messaging'],
requires=['requests', 'cherrypy', 'ws4py', 'irc', 'wxpython', 'cefpython3', 'semantic_version'],
requires=['requests', 'cherrypy', 'ws4py', 'irc', 'wxpython', 'cefpython3', 'semantic_version', 'jinja2'],
url='https://github.com/DeForce/LalkaChat',
license='',
author='CzT/DeForce',
Expand Down
2 changes: 0 additions & 2 deletions translations/en/main.key
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ main.quit.nosave = Are you sure you want to quit?\nWarning, your settings will n
main.save.non_dynamic = Warning, you have saved setting that are not dynamic\nPlease restart program to apply changes
main.language = Program Language
main.language.list_box =
main.style = Available styles
main.style.list_box =

messaging = Message modules
messaging.messaging = List of available modules
Expand Down
5 changes: 4 additions & 1 deletion translations/en/webchat.key
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ webchat.description = WebChat module is a webserver for chat and allows you to s
webchat.server = Local server settings
webchat.server.host = Host
webchat.server.port = Port

webchat.style = Available styles
webchat.style.list_box =
webchat.style_settings = Style Settings
webchat.style_settings.font_size = Font Size (pt)
2 changes: 0 additions & 2 deletions translations/ru/main.key
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ main.quit.nosave = Вы уверены что хотите выйти?\Вним
main.save.non_dynamic = Внимание, сохраненые настройки не будут работать до перезапуска.\nПожалуйста перезапустите программу что бы изменения вступили в силу.
main.language = Язык Интерфейса
main.language.list_box =
main.style = Доступные Стили
main.style.list_box =

messaging = Модули Сообщений
messaging.messaging = Список доступных модулей
Expand Down
4 changes: 4 additions & 0 deletions translations/ru/webchat.key
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ webchat.description = Модуль ВебЧата позволяет вам ви
webchat.server = Настройки локального сервера
webchat.server.host = Хост
webchat.server.port = Порт
webchat.style = Доступные Стили
webchat.style.list_box =
webchat.style_settings = Настройки Стиля
webchat.style_settings.font_size = Размер шрифта

0 comments on commit 5c3488d

Please sign in to comment.