From 5c3488d435e00d6ad8382399fa49e94208a9a8a0 Mon Sep 17 00:00:00 2001 From: Vladislav Ivanov Date: Sun, 30 Oct 2016 22:40:14 +0200 Subject: [PATCH] LC-115 Change font/size from gui, not css --- gui.py | 23 +++++++- http/czt/css/{czt.css => style.css} | 2 +- http/czt/index.html | 2 +- http/czt_timed/css/{czt.css => style.css} | 2 +- http/czt_timed/index.html | 2 +- main.py | 3 +- modules/helper/modules.py | 3 + modules/messaging/webchat.py | 72 +++++++++++++++++------ setup.py | 2 +- translations/en/main.key | 2 - translations/en/webchat.key | 5 +- translations/ru/main.key | 2 - translations/ru/webchat.key | 4 ++ 13 files changed, 95 insertions(+), 29 deletions(-) rename http/czt/css/{czt.css => style.css} (97%) rename http/czt_timed/css/{czt.css => style.css} (97%) diff --git a/gui.py b/gui.py index 762753e..58477af 100644 --- a/gui.py +++ b/gui.py @@ -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: @@ -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 @@ -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) @@ -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) @@ -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 diff --git a/http/czt/css/czt.css b/http/czt/css/style.css similarity index 97% rename from http/czt/css/czt.css rename to http/czt/css/style.css index ec1ea2c..b43106f 100644 --- a/http/czt/css/czt.css +++ b/http/czt/css/style.css @@ -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; diff --git a/http/czt/index.html b/http/czt/index.html index a257d0f..cf8d366 100644 --- a/http/czt/index.html +++ b/http/czt/index.html @@ -4,7 +4,7 @@ - + diff --git a/http/czt_timed/css/czt.css b/http/czt_timed/css/style.css similarity index 97% rename from http/czt_timed/css/czt.css rename to http/czt_timed/css/style.css index ec1ea2c..b43106f 100644 --- a/http/czt_timed/css/czt.css +++ b/http/czt_timed/css/style.css @@ -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; diff --git a/http/czt_timed/index.html b/http/czt_timed/index.html index b20a9a2..72ee1e2 100644 --- a/http/czt_timed/index.html +++ b/http/czt_timed/index.html @@ -3,7 +3,7 @@ - + diff --git a/main.py b/main.py index e36c9db..06d5325 100644 --- a/main.py +++ b/main.py @@ -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: diff --git a/modules/helper/modules.py b/modules/helper/modules.py index 8aaeca5..ab02447 100644 --- a/modules/helper/modules.py +++ b/modules/helper/modules.py @@ -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): diff --git a/modules/messaging/webchat.py b/modules/messaging/webchat.py index d1ae358..de3bf15 100644 --- a/modules/messaging/webchat.py +++ b/modules/messaging/webchat.py @@ -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 @@ -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) @@ -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() @@ -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): @@ -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'] = { @@ -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) @@ -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): @@ -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): diff --git a/setup.py b/setup.py index 4f31333..720ea60 100644 --- a/setup.py +++ b/setup.py @@ -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', diff --git a/translations/en/main.key b/translations/en/main.key index 0c071da..5f3ff33 100644 --- a/translations/en/main.key +++ b/translations/en/main.key @@ -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 diff --git a/translations/en/webchat.key b/translations/en/webchat.key index 27f8788..810c058 100644 --- a/translations/en/webchat.key +++ b/translations/en/webchat.key @@ -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) \ No newline at end of file diff --git a/translations/ru/main.key b/translations/ru/main.key index 5548b3b..39c5fc2 100644 --- a/translations/ru/main.key +++ b/translations/ru/main.key @@ -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 = Список доступных модулей diff --git a/translations/ru/webchat.key b/translations/ru/webchat.key index 83018e6..14e5dd4 100644 --- a/translations/ru/webchat.key +++ b/translations/ru/webchat.key @@ -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 = Размер шрифта