#!/usr/bin/env python3
# coding: utf-8 -*-


import uno
from datetime import datetime
from com.sun.star.awt.MessageBoxType import INFOBOX
from com.sun.star.awt.MessageBoxButtons import BUTTONS_YES_NO_CANCEL, DEFAULT_BUTTON_YES


def msgbox(msg=None, title=None):
    if msg is None:
        msg = "HELLO WORLD"
    else:
        msg = msg

    if title is None:
        title = "ТЕСТОВОЕ ДИАЛОГОВОЕ ОКНО"
    else:
        title = title

    ctx = uno.getComponentContext()
    smgr = ctx.getServiceManager()
    tk = smgr.createInstance("com.sun.star.awt.Toolkit")
    dtp = smgr.createInstance("com.sun.star.frame.Desktop")
    frame = dtp.getCurrentFrame()
    win = frame.getComponentWindow()
    mtyp = INFOBOX
    btn = BUTTONS_YES_NO_CANCEL + DEFAULT_BUTTON_YES
    mb = tk.createMessageBox(win, mtyp, btn, title, msg)

    return mb.execute()


def test():
    return msgbox(
            title="Информация",
            msg=f"Дата и время: {datetime.now()}"
    )


g_exportedScripts = (test,)