/
kuzant24
/
libre-macros
Обзор
Документация
Войти
/
kuzant24
/
libre-macros
Код
Запросы
1
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
new_source_processing
macro-lib/pythonpath/libre_macros_ui_theme.py
248 строк
8 KB
direct-dev.ru
fixed for home work
04 авг 2026, 16:06
04 авг 2026, 16:06
eb53100
Код
Авторство
О чём код?
# -*- coding: utf-8 -*- from __future__ import print_function, unicode_literals MACRO_VERSION = "3.10.359" """ Общая soft-gray тема диалогов (визард параметров, collect_workbooks, ВПР и т.п.). Системный TitleBar (GTK/WM) через UNO обычно не красится — рисуем SoftGrayTitleBar. """ try: unicode except NameError: unicode = str # UNO 0x00RRGGBB SOFT_GRAY_FORM_BG = 0xE6E6E6 SOFT_GRAY_TITLE_BG = 0x4A4A4A SOFT_GRAY_TITLE_FG = 0xF5F5F5 SOFT_GRAY_LABEL_FG = 0x2A2A2A SOFT_GRAY_FIELD_BG = 0xF4F4F4 SOFT_GRAY_BTN_BG = 0xD4D4D4 SOFT_GRAY_TITLE_H = 28 SOFT_GRAY_BAR_NAME = "SoftGrayTitleBar" def soft_gray_theme_applied(dm): if dm is None: return False try: return SOFT_GRAY_BAR_NAME in list(dm.getElementNames()) except Exception: return False def apply_soft_gray_theme(dm, title_text=None): """ Серый фон формы + тёмно-серая полоса-титл внутри диалога. Сдвигает контролы вниз. Идемпотентно (повторный вызов — no-op). """ if dm is None: return False if soft_gray_theme_applied(dm): return True form_bg = int(SOFT_GRAY_FORM_BG) title_bg = int(SOFT_GRAY_TITLE_BG) title_fg = int(SOFT_GRAY_TITLE_FG) label_fg = int(SOFT_GRAY_LABEL_FG) field_bg = int(SOFT_GRAY_FIELD_BG) btn_bg = int(SOFT_GRAY_BTN_BG) title_h = int(SOFT_GRAY_TITLE_H) try: dm.BackgroundColor = form_bg except Exception: pass names = [] try: names = list(dm.getElementNames()) except Exception: names = [] for name in names: try: ctl = dm.getByName(name) except Exception: continue try: ctl.PositionY = int(ctl.PositionY) + title_h except Exception: pass kind = u"" try: if ctl.supportsService("com.sun.star.awt.UnoControlFixedTextModel"): kind = u"fixed" elif ctl.supportsService("com.sun.star.awt.UnoControlEditModel"): kind = u"edit" elif ctl.supportsService("com.sun.star.awt.UnoControlListBoxModel"): kind = u"list" elif ctl.supportsService("com.sun.star.awt.UnoControlComboBoxModel"): kind = u"combo" elif ctl.supportsService("com.sun.star.awt.UnoControlCheckBoxModel"): kind = u"check" elif ctl.supportsService("com.sun.star.awt.UnoControlButtonModel"): kind = u"button" elif ctl.supportsService("com.sun.star.awt.UnoControlProgressBarModel"): kind = u"progress" elif ctl.supportsService("com.sun.star.awt.UnoControlGroupBoxModel"): kind = u"group" except Exception: ncf = unicode(name or u"").casefold() if ncf.endswith(u"lbl") or u"hint" in ncf or u"label" in ncf: kind = u"fixed" elif ncf.endswith(u"ed") or ncf.endswith(u"edit"): kind = u"edit" elif ncf.endswith(u"lb") or u"list" in ncf: kind = u"list" elif ncf.endswith(u"cb") or u"combo" in ncf: kind = u"combo" elif ncf.endswith(u"chk"): kind = u"check" elif ncf.endswith(u"btn") or u"button" in ncf: kind = u"button" elif u"progress" in ncf: kind = u"progress" elif u"frame" in ncf or u"group" in ncf: kind = u"group" try: if kind == u"fixed": ctl.BackgroundColor = form_bg ctl.TextColor = label_fg elif kind in (u"edit", u"list", u"combo"): ctl.BackgroundColor = field_bg ctl.TextColor = label_fg elif kind == u"check": ctl.BackgroundColor = form_bg ctl.TextColor = label_fg elif kind == u"button": ctl.BackgroundColor = btn_bg ctl.TextColor = label_fg elif kind in (u"progress", u"group"): ctl.BackgroundColor = form_bg except Exception: pass try: dm.Height = int(dm.Height) + title_h except Exception: pass caption = unicode(title_text or getattr(dm, "Title", u"") or u"").strip() if caption == u"": caption = u"Диалог" try: bar = dm.createInstance("com.sun.star.awt.UnoControlFixedTextModel") bar.Name = SOFT_GRAY_BAR_NAME bar.Label = u" " + caption bar.PositionX = 0 bar.PositionY = 0 bar.Width = int(dm.Width) bar.Height = title_h bar.BackgroundColor = title_bg bar.TextColor = title_fg try: bar.Align = 0 except Exception: pass try: bar.VerticalAlign = 1 except Exception: pass try: bar.Border = 0 except Exception: pass try: fd = bar.FontDescriptor fd.Weight = 150 try: fd.Height = 11 except Exception: pass bar.FontDescriptor = fd except Exception: pass dm.insertByName(SOFT_GRAY_BAR_NAME, bar) except Exception: pass try: dm.Title = caption except Exception: pass return True def try_paint_titlebar(dlg, title_bg=None, title_fg=None): """Попытка покрасить OS titlebar через StyleSettings (на GTK часто no-op).""" if dlg is None: return False title_bg = int(title_bg if title_bg is not None else SOFT_GRAY_TITLE_BG) title_fg = int(title_fg if title_fg is not None else SOFT_GRAY_TITLE_FG) form_bg = int(SOFT_GRAY_FORM_BG) painted = False peers = [] try: peers.append(dlg.getPeer()) except Exception: pass try: peers.append(dlg.getPeer().getContainerWindow()) except Exception: pass try: import uno ctx = uno.getComponentContext() toolkit = ctx.getServiceManager().createInstanceWithContext( "com.sun.star.awt.Toolkit", ctx ) if toolkit is not None: peers.append(toolkit) except Exception: pass attrs = ( ("TitleBarColor", title_bg), ("TitleBarTextColor", title_fg), ("InactiveTitleBarColor", title_bg), ("InactiveTitleBarTextColor", title_fg), ("DialogColor", form_bg), ("WorkspaceColor", form_bg), ("FaceColor", form_bg), ("WindowColor", form_bg), ) for peer in peers: if peer is None: continue ss = None try: ss = peer.StyleSettings except Exception: try: ss = peer.getStyleSettings() except Exception: ss = None if ss is None: continue for attr, val in attrs: try: setattr(ss, attr, val) painted = True except Exception: try: ss.setPropertyValue(attr, val) painted = True except Exception: pass return painted def prepare_dialog_soft_gray(dlg, title_text=None): """Применить тему к модели диалога (до или после setModel, до createPeer).""" if dlg is None: return False try: dm = dlg.getModel() except Exception: return False caption = title_text if caption is None: try: caption = getattr(dm, "Title", None) except Exception: caption = None return apply_soft_gray_theme(dm, title_text=caption)