コード例 #1
0
ファイル: dialogs.py プロジェクト: ir1110/noforese
def dialog(
        font_style="Body1",
        theme_text_color="Secondary",
        title="Title",
        text="Text",
        valign="top",
        dismiss=True,
        buttons=None,
        use_check=False,
        text_check="",
        height=300,
        size_hint=(0.85, None),
        ref_callback=None,
        check_callback=None,
):
    """Вывод диалоговых окон."""

    if buttons is None:
        buttons = []

    text_dialog = MDLabel(
        font_style=font_style,
        theme_text_color=theme_text_color,
        text=text,
        valign=valign,
        markup=True,
        size_hint_y=None,
    )
    dialog = MDDialog(
        title=title,
        content=text_dialog,
        size_hint=size_hint,
        auto_dismiss=dismiss,
        height=dp(height),
    )

    text_dialog.bind(texture_size=text_dialog.setter("size"))
    if ref_callback:
        text_dialog.bind(on_ref_press=ref_callback)

    if use_check:
        selection = Selection(text=text_check)
        if check_callback:
            selection.callback = check_callback
        dialog.children[0].children[1].add_widget(selection)

    for list_button in buttons:
        text_button, action_button = list_button
        dialog.add_action_button(text_button, action=action_button)
    dialog.open()

    return dialog
コード例 #2
0
def dialog(font_style='Body1',
           theme_text_color='Secondary',
           title='Title',
           text='Text',
           valign='top',
           dismiss=True,
           buttons=None,
           use_check=False,
           text_check='',
           height=300,
           size_hint=(.85, None),
           ref_callback=None,
           check_callback=None):
    '''Вывод диалоговых окон.'''

    if buttons is None:
        buttons = []

    text_dialog = MDLabel(font_style=font_style,
                          theme_text_color=theme_text_color,
                          text=text,
                          valign=valign,
                          markup=True,
                          size_hint_y=None)
    dialog = MDDialog(title=title,
                      content=text_dialog,
                      size_hint=size_hint,
                      auto_dismiss=dismiss,
                      height=dp(height))

    text_dialog.bind(texture_size=text_dialog.setter('size'))
    if ref_callback:
        text_dialog.bind(on_ref_press=ref_callback)

    if use_check:
        selection = Selection(text=text_check)
        if check_callback:
            selection.callback = check_callback
        dialog.children[0].children[1].add_widget(selection)

    for list_button in buttons:
        text_button, action_button = list_button
        dialog.add_action_button(text_button, action=action_button)
    dialog.open()

    return dialog
コード例 #3
0
ファイル: status_tab.py プロジェクト: poikilos/FinalLobby
class StatusTab(MDTabsBase):
    app = ObjectProperty(None)
    irc_action = ObjectProperty(None)
    irc_action_send_btn = ObjectProperty(None)

    def __init__(self, **kw):
        super(StatusTab, self).__init__(**kw)
        self.app = MDApp.get_running_app()
        Clock.schedule_once(self.__post_init__)

    def __post_init__(self, args):
        pass

    def update_irc_action_text(self, dt):
        self.irc_action.text = ''
        self.irc_action.on_focus()

    def send_action(self):
        Clock.schedule_once(self.update_irc_action_text)
        self.app.connection.sendLine(self.irc_action.text.strip('/'))
        self.msg_list.add_widget(
            MultiLineListItem(
                text="[b][color=1A237E]" +
                self.app.config.get('irc', 'nickname') + "[/color][/b] " +
                self.irc_action.text,
                font_style='Subhead',
            ))
        self.msg_list.parent.scroll_to(self.msg_list.children[0])
        Logger.info(
            "IRC: <%s> %s" %
            (self.app.config.get('irc', 'nickname'), self.irc_action.text))

    def on_irc_unknown(self, prefix, command, params):
        Logger.info("IRC UNKNOWN: <%s> %s %s" % (prefix, command, params))

    def on_noticed(self, user, channel, action):
        user = user.split('!')[0]
        if user == 'ChanServ':
            content = MDLabel(font_style='Body1',
                              theme_text_color='Secondary',
                              text=action,
                              size_hint_y=None,
                              valign='top')
            content.bind(texture_size=content.setter('size'))
            self.dialog = MDDialog(title="Notice: {}".format(user),
                                   content=content,
                                   size_hint=(.8, None),
                                   height=dp(200),
                                   auto_dismiss=False)

            self.dialog.add_action_button(
                "Dismiss", action=lambda *x: self.dialog.dismiss())
            self.dialog.open()
        else:
            self.msg_list.add_widget(
                MultiLineListItem(
                    text="[b][color=F44336]" + user + "[/color][/b] " + action,
                    font_style='Subhead',
                ))
            self.msg_list.parent.scroll_to(self.msg_list.children[0])
        Logger.info("IRC NOTICED: <%s> %s %s" % (user, channel, action))

    def nick_details(self, nick_list_item):
        self.app.connection.signedOn()
        nick_item_data = self.nick_data[nick_list_item.text]
        bs = MDListBottomSheet()
        bs.add_item("Whois ({})".format(nick_list_item.text), lambda x: x)
        bs.add_item(
            "{} ({}@{})".format(nick_item_data[7].split(' ')[1],
                                nick_item_data[3], nick_item_data[2]),
            lambda x: x)
        bs.add_item(
            "{} is connected via {}".format(nick_list_item.text,
                                            nick_item_data[4]), lambda x: x)
        bs.open()

    def __post_connection__(self, connection):
        connection.on_irc_unknown(self.on_irc_unknown)
        connection.on_noticed(self.on_noticed)

    def __post_joined__(self, connection):
        pass