Exemplo n.º 1
0
 def on_disconnect(self, connection, event):
     if 'CLOSE_OK' in event.arguments:
         log.info("Connection closed")
         self.system_message(translate_key(
             MODULE_KEY.join(['twitch',
                              'connection_closed'])).format(self.nick),
                             category='connection')
         raise TwitchNormalDisconnect()
     else:
         log.info("Connection lost")
         log.debug("connection: {}".format(connection))
         log.debug("event: {}".format(event))
         self.chat_module.set_offline(self.nick)
         self.system_message(translate_key(
             MODULE_KEY.join(['twitch',
                              'connection_died'])).format(self.nick),
                             category='connection')
         timer = threading.Timer(5.0,
                                 self.reconnect,
                                 args=[
                                     self.main_class.host,
                                     self.main_class.port,
                                     self.main_class.nickname
                                 ])
         timer.start()
Exemplo n.º 2
0
    def create_list(self, parent, view, key, section, section_gui):
        is_dual = True if 'dual' in view else False
        style = wx.ALIGN_CENTER_VERTICAL
        item_sizer = wx.BoxSizer(wx.VERTICAL)
        addable_sizer = None
        if section_gui.get('addable', False):
            addable_sizer = wx.BoxSizer(wx.HORIZONTAL)
            item_input_key = MODULE_KEY.join([key, 'list_input'])
            addable_sizer.Add(wx.TextCtrl(parent, id=id_renew(item_input_key, update=True)), 0, style)
            if is_dual:
                item_input2_key = MODULE_KEY.join([key, 'list_input2'])
                addable_sizer.Add(wx.TextCtrl(parent, id=id_renew(item_input2_key, update=True)), 0, style)

            item_apply_key = MODULE_KEY.join([key, 'list_add'])
            item_apply_id = id_renew(item_apply_key, update=True)
            addable_sizer.Add(wx.Button(parent, id=item_apply_id, label=translate_key(item_apply_key)), 0, style)
            self.Bind(wx.EVT_BUTTON, self.button_clicked, id=item_apply_id)

            item_remove_key = MODULE_KEY.join([key, 'list_remove'])
            item_remove_id = id_renew(item_remove_key, update=True)
            addable_sizer.Add(wx.Button(parent, id=item_remove_id, label=translate_key(item_remove_key)), 0, style)
            self.Bind(wx.EVT_BUTTON, self.button_clicked, id=item_remove_id)

            item_sizer.Add(addable_sizer, 0, wx.EXPAND)
        list_box = wx.grid.Grid(parent, id=id_renew(MODULE_KEY.join([key, 'list_box']), update=True))
        list_box.CreateGrid(0, 2 if is_dual else 1)
        list_box.DisableDragColSize()
        list_box.DisableDragRowSize()
        list_box.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.select_cell)
        list_box.SetMinSize(wx.Size(-1, 100))

        for index, (item, value) in enumerate(section.items()):
            list_box.AppendRows(1)
            if is_dual:
                list_box.SetCellValue(index, 0, item.decode('utf-8'))
                list_box.SetCellValue(index, 1, value.decode('utf-8'))
            else:
                list_box.SetCellValue(index, 0, item.decode('utf-8'))
        list_box.SetColLabelSize(1)
        list_box.SetRowLabelSize(1)
        if addable_sizer:
            col_size = addable_sizer.GetMinSize()[0] - 2
            if is_dual:
                first_col_size = list_box.GetColSize(0)
                second_col_size = col_size - first_col_size if first_col_size < col_size else -1
                list_box.SetColSize(1, second_col_size)
            else:
                list_box.SetDefaultColSize(col_size, resizeExistingCols=True)
        else:
            list_box.AutoSize()

        # Adding size of scrollbars
        size = list_box.GetEffectiveMinSize()
        size[0] += 18
        size[1] += 18
        list_box.SetMinSize(size)
        item_sizer.Add(list_box, 1, wx.EXPAND)
        return item_sizer
Exemplo n.º 3
0
 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:
         return wx.Sizer()
     for item, value in section.items():
         if not self.show_hidden and item in section_gui.get('hidden', []):
             continue
         item_name = MODULE_KEY.join([key, item])
         if item in section_gui:
             if 'list' in section_gui[item].get('view'):
                 flex_grid.Add(self.create_list(parent, view, item_name, section, section_gui[item]))
                 flex_grid.AddSpacer(wx.Size(0, 0))
             elif 'choose' in section_gui[item].get('view'):
                 flex_grid.Add(self.create_choose(parent, view, item_name, section, section_gui[item]))
                 flex_grid.AddSpacer(wx.Size(0, 0))
             elif 'dropdown' in section_gui[item].get('view'):
                 text, control = self.create_dropdown(parent, view, item_name, section, section_gui[item],
                                                      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
             if value is None:  # Button
                 button_id = id_renew(item_name, update=True)
                 item_button = wx.Button(parent, id=button_id, label=translate_key(item_name))
                 flex_grid.Add(item_button, 0, wx.ALIGN_LEFT)
                 flex_grid.AddSpacer(wx.Size(0, 0))
                 self.main_class.Bind(wx.EVT_BUTTON, self.button_clicked, id=button_id)
             elif isinstance(value, bool):  # Checkbox
                 item_box = wx.CheckBox(parent, id=id_renew(item_name, update=True),
                                        label=translate_key(item_name), style=style)
                 item_box.SetValue(value)
                 flex_grid.Add(item_box, 0, wx.ALIGN_LEFT)
                 flex_grid.AddSpacer(wx.Size(0, 0))
             else:  # TextCtrl
                 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 | wx.ALIGN_CENTER_HORIZONTAL)
                 flex_grid.Add(item_text)
                 flex_grid.Add(item_box)
     flex_grid.Fit(parent)
     return flex_grid
Exemplo n.º 4
0
 def button_clicked(self, event):
     log.debug("[Settings] Button clicked: {0}".format(
         modules.interface.controls.IDS[event.GetId()]))
     button_id = event.GetId()
     keys = modules.interface.controls.IDS[button_id].split(MODULE_KEY)
     last_key = keys[-1]
     if last_key in ['list_add', 'list_remove']:
         self.on_list_operation(MODULE_KEY.join(keys[:-1]), action=last_key)
     elif last_key in ['ok_button', 'apply_button']:
         if self.save_settings():
             log.debug('Got non-dynamic changes')
             dialog = wx.MessageDialog(
                 self,
                 message=translate_key(
                     MODULE_KEY.join(['main', 'save', 'non_dynamic'])),
                 caption="Caption",
                 style=wx.OK_DEFAULT,
                 pos=wx.DefaultPosition)
             dialog.ShowModal()
         if last_key == 'ok_button':
             self.on_exit(event)
         self.settings_saved = True
     elif last_key == 'cancel_button':
         self.on_close(event)
     event.Skip()
Exemplo n.º 5
0
    def on_listbox_change(self, event):
        item_object = event.EventObject
        selection = item_object.get_key_from_index(item_object.GetSelection())
        description = translate_key(MODULE_KEY.join([selection,
                                                     'description']))

        item_key = modules.interface.controls.IDS[event.GetId()].split(
            MODULE_KEY)
        config_item_path = get_config_item_path(item_key[:-1])
        module_class = deep_get(self.main_class.loaded_modules,
                                *config_item_path)
        show_description = module_class.description

        if isinstance(item_object, KeyListBox):
            self.on_change(modules.interface.controls.IDS[event.GetId()],
                           selection,
                           item_type='listbox',
                           section=True)

        if show_description:
            item_id_key = MODULE_KEY.join(item_key[:-1])
            descr_static_text = wx.FindWindowById(
                modules.interface.controls.get_id_from_name(
                    MODULE_KEY.join([item_id_key, 'descr_explain'])))
            descr_static_text.SetLabel(description)
            descr_static_text.Wrap(descr_static_text.GetSize()[0])
Exemplo n.º 6
0
    def button_clicked(self, event):
        log.debug("[Settings] Button clicked: {0}".format(IDS[event.GetId()]))
        button_id = event.GetId()
        keys = IDS[button_id].split(MODULE_KEY)
        if keys[-1] in ['list_add', 'list_remove']:
            self.list_operation(MODULE_KEY.join(keys[:-1]), action=keys[-1])
        elif keys[-1] == 'apply_button':
            module_name = MODULE_KEY.join(keys[1:-1])
            if self.save_settings(module_name):
                log.debug('Got non-dynamic changes')
                dialog = wx.MessageDialog(
                    self,
                    message=translate_key(
                        MODULE_KEY.join(['main', 'save', 'non_dynamic'])),
                    caption="Caption",
                    style=wx.OK_DEFAULT,
                    pos=wx.DefaultPosition)
                response = dialog.ShowModal()

                if response == wx.ID_YES:
                    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)
        event.Skip()
Exemplo n.º 7
0
 def opened(self):
     success_msg = "Connection Successful"
     log.info(success_msg)
     self.chat_module.set_online(self.main_thread.nick)
     try:
         self.chat_module.set_viewers(
             self.main_thread.nick,
             self.chat_module.get_viewers(self.main_thread.nick))
     except Exception as exc:
         log.exception(exc)
     self.system_message(translate_key(
         MODULE_KEY.join(['goodgame', 'connection_success'
                          ])).format(self.main_thread.nick),
                         category='connection')
     # Sending join channel command to goodgame websocket
     join = json.dumps(
         {
             'type': "join",
             'data': {
                 'channel_id': self.ch_id,
                 'hidden': "true"
             }
         },
         sort_keys=False)
     self.send(join)
     # self.ggPing()
     log.info("Sent join message")
Exemplo n.º 8
0
 def on_join(self, connection, event):
     log.debug("connection: {}".format(connection))
     log.debug("event: {}".format(event))
     msg = translate_key(MODULE_KEY.join(['twitch', 'join_success'
                                          ])).format(self.channel)
     log.info(msg)
     self.system_message(msg, category='connection')
Exemplo n.º 9
0
    def fill_sc_with_config(self, panel, category_config, category_item):
        page_sc_window = wx.ScrolledWindow(panel,
                                           id=id_renew(category_item),
                                           style=wx.VSCROLL)
        page_sc_window.SetScrollbars(5, 5, 10, 10)
        border_all = 5
        sizer = wx.BoxSizer(wx.VERTICAL)
        for section_key, section_items in category_config['config'].items():
            if section_key in SKIP_TAGS:
                continue

            static_key = MODULE_KEY.join([category_item, section_key])
            static_box = wx.StaticBox(page_sc_window,
                                      label=translate_key(static_key))
            static_sizer = wx.StaticBoxSizer(static_box, wx.VERTICAL)

            log.debug("Working on {0}".format(static_key))

            static_sizer.Add(
                self.create_items(
                    static_box, static_key, section_items,
                    category_config.get('gui', {}).get(section_key, {})), 0,
                wx.EXPAND | wx.ALL, border_all)

            sizer.Add(static_sizer, 0, wx.EXPAND)
        page_sc_window.SetSizer(sizer)
        return page_sc_window
Exemplo n.º 10
0
    def button_clicked(self, event):
        log.debug("[Settings] Button clicked: {0}".format(IDS[event.GetId()]))
        button_id = event.GetId()
        keys = IDS[button_id].split(MODULE_KEY)
        if keys[-1] in ['list_add', 'list_remove']:
            self.list_operation(MODULE_KEY.join(keys[:-1]), action=keys[-1])
        elif keys[-1] == 'apply_button':
            module_name = MODULE_KEY.join(keys[1:-1])
            if self.save_settings(module_name):
                log.debug('Got non-dynamic changes')
                dialog = wx.MessageDialog(self,
                                          message=translate_key(MODULE_KEY.join(['main', 'save', 'non_dynamic'])),
                                          caption="Caption",
                                          style=wx.OK_DEFAULT,
                                          pos=wx.DefaultPosition)
                response = dialog.ShowModal()

                if response == wx.ID_YES:
                    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)
        event.Skip()
Exemplo n.º 11
0
 def create_button(button_key, function):
     button_id = id_renew(button_key, update=True)
     c_button = wx.Button(panel,
                          id=button_id,
                          label=translate_key(button_key))
     self.Bind(wx.EVT_BUTTON, function, id=button_id)
     return c_button
Exemplo n.º 12
0
    def create(self, panel, value="#FFFFFF", orientation=wx.HORIZONTAL, event=None, key=None,
               *args, **kwargs):
        item_sizer = wx.BoxSizer(orientation)

        self.event = event
        self.key = key
        label_panel = wx.Panel(panel, style=wx.BORDER_SIMPLE)
        label_sizer = wx.BoxSizer(wx.HORIZONTAL)
        label_sizer2 = wx.BoxSizer(wx.VERTICAL)
        label_text = wx.StaticText(label_panel, label=unicode(value), style=wx.ALIGN_CENTER)
        self.text = label_text
        label_sizer.Add(label_text, 1, wx.ALIGN_CENTER)
        label_sizer2.Add(label_sizer, 1, wx.ALIGN_CENTER)
        label_panel.SetSizer(label_sizer2)
        label_panel.SetBackgroundColour(str(value))
        self.panel = label_panel

        button = wx.Button(panel, label=translate_key(MODULE_KEY.join(key + ['button'])))
        button.Bind(wx.EVT_BUTTON, self.on_button_press)
        border_size = wx.SystemSettings_GetMetric(wx.SYS_BORDER_Y)
        button_size = button.GetSize()
        if button_size[0] > 150:
            button_size[0] = 150
        button_size[1] -= border_size*2
        self.button = button

        label_panel.SetMinSize(button_size)
        label_panel.SetSize(button_size)

        item_sizer.Add(label_panel, 0, wx.ALIGN_CENTER)
        item_sizer.AddSpacer(2)
        item_sizer.Add(button, 0, wx.EXPAND)
        return item_sizer
Exemplo n.º 13
0
 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
Exemplo n.º 14
0
 def get_tree_item(self, key, node, image=-1, name_key=None):
     item_data = wx.TreeItemData()
     item_data.SetData(key)
     return self.tree_ctrl.AppendItem(
         node,
         translate_key(name_key if name_key else key),
         data=item_data,
         image=image)
Exemplo n.º 15
0
 def create_tool(self, name, binding=None, style=wx.ITEM_NORMAL, s_help="", l_help=""):
     l_id = id_renew(name)
     IDS[l_id] = name
     label_text = translate_key(IDS[l_id])
     button = self.AddLabelTool(l_id, label_text, wx.NullBitmap, wx.NullBitmap,
                                style, s_help, l_help)
     if binding:
         self.main_class.Bind(wx.EVT_TOOL, binding, id=l_id)
     return button
Exemplo n.º 16
0
 def create_tool(self, name, binding=None, style=wx.ITEM_NORMAL, s_help="", l_help=""):
     l_id = id_renew(name)
     IDS[l_id] = name
     label_text = translate_key(IDS[l_id])
     button = self.AddLabelTool(l_id, label_text, wx.NullBitmap, wx.NullBitmap,
                                style, s_help, l_help)
     if binding:
         self.main_class.Bind(wx.EVT_TOOL, binding, id=l_id)
     return button
Exemplo n.º 17
0
def create_checkbox(panel=None, value=None, key=None, bind=None, **kwargs):
    item_sizer = wx.BoxSizer(wx.HORIZONTAL)
    style = wx.ALIGN_CENTER_VERTICAL
    item_key = MODULE_KEY.join(key)
    item_box = wx.CheckBox(panel, id=id_renew(item_key, update=True),
                           label=translate_key(item_key), style=style)
    item_box.SetValue(bool(value))
    item_box.Bind(wx.EVT_CHECKBOX, bind)
    item_sizer.Add(item_box, 0, wx.ALIGN_LEFT)
    return {'item': item_sizer}
Exemplo n.º 18
0
def create_textctrl(panel=None, value=None, key=None, bind=None, **kwargs):
    item_sizer = wx.BoxSizer(wx.HORIZONTAL)
    item_name = MODULE_KEY.join(key)
    item_box = wx.TextCtrl(panel, id=id_renew(item_name, update=True),
                           value=unicode(value))
    item_box.Bind(wx.EVT_TEXT, bind)
    item_text = wx.StaticText(panel, label=translate_key(item_name))
    item_sizer.Add(item_text, 0, wx.ALIGN_CENTER)
    item_sizer.Add(item_box)
    return {'item': item_sizer, 'text_size': item_text.GetSize()[0], 'text_ctrl': item_text}
Exemplo n.º 19
0
 def create_dropdown(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)
     choices = section_gui.get('choices')
     key = key if section_item else MODULE_KEY.join([key, 'dropdown'])
     item_box = KeyChoice(parent, id=id_renew(key, update=True),
                          keys=choices, choices=choices)
     item_value = section[short_key] if section_item else section
     item_box.SetSelection(choices.index(item_value))
     return item_text, item_box
Exemplo n.º 20
0
    def closed(self, code, reason=None):
        """
        Codes used by LC
        4000 - Normal disconnect by LC

        :param code: 
        :param reason: 
        """
        log.debug("%s %s", code, reason)
        log.info("Connection closed")
        self._viewers_th.close()
        if code in [4000]:
            self.system_message(
                translate_key('hitbox.connection_closed').format(self.channel))
            self.exited = True
        else:
            self.system_message(
                translate_key('hitbox.connection_died').format(self.channel))
        self.main_class.set_offline(self.channel)
Exemplo n.º 21
0
    def create_layout(self):
        self.main_grid = wx.BoxSizer(wx.HORIZONTAL)
        tree_ctrl_size = wx.Size(220, -1)
        style = wx.TR_DEFAULT_STYLE | wx.TR_HIDE_ROOT | wx.TR_TWIST_BUTTONS | wx.TR_NO_LINES
        # style = wx.TR_HAS_BUTTONS | wx.TR_SINGLE | wx.TR_HIDE_ROOT

        tree_ctrl_id = id_renew('settings.tree', update=True)
        tree_ctrl = wx.TreeCtrl(self, id=tree_ctrl_id, style=style)
        tree_ctrl.SetMinSize(tree_ctrl_size)
        root_key = MODULE_KEY.join(['settings', 'tree', 'root'])
        root_node = tree_ctrl.AddRoot(translate_key(root_key))
        for item, value in self.categories.iteritems():
            item_key = MODULE_KEY.join(['settings', item])
            item_data = wx.TreeItemData()
            item_data.SetData(item_key)

            item_node = tree_ctrl.AppendItem(root_node,
                                             translate_key(item_key),
                                             data=item_data)
            for f_item, f_value in value.iteritems():
                if not f_item == item:
                    f_item_key = MODULE_KEY.join([item_key, f_item])
                    f_item_data = wx.TreeItemData()
                    f_item_data.SetData(f_item_key)
                    tree_ctrl.AppendItem(item_node,
                                         translate_key(f_item),
                                         data=f_item_data)
        tree_ctrl.ExpandAll()

        self.tree_ctrl = tree_ctrl
        self.Bind(wx.EVT_TREE_SEL_CHANGED,
                  self.tree_ctrl_changed,
                  id=tree_ctrl_id)
        self.main_grid.Add(self.tree_ctrl, 0, wx.EXPAND | wx.ALL, 7)

        content_page_id = id_renew(MODULE_KEY.join(['settings', 'content']))
        self.content_page = wx.Panel(self, id=content_page_id)
        self.main_grid.Add(self.content_page, 1, wx.EXPAND)

        self.main_grid.Layout()
        self.SetSizer(self.main_grid)
        tree_ctrl.SelectItem(tree_ctrl.GetFirstChild(root_node)[0])
Exemplo n.º 22
0
    def on_close(self, event):
        dialog = wx.MessageDialog(self, message=translate_key(MODULE_KEY.join(['main', 'quit'])),
                                  caption="Caption",
                                  style=wx.YES_NO | wx.CANCEL,
                                  pos=wx.DefaultPosition)
        response = dialog.ShowModal()

        if response == wx.ID_YES:
            self.on_exit(event)
        else:
            event.StopPropagation()
Exemplo n.º 23
0
def create_colour_picker(panel=None, value=None, key=None, bind=None, **kwargs):
    item_sizer = wx.BoxSizer(wx.HORIZONTAL)

    item_name = MODULE_KEY.join(key)
    colour_picker = CustomColourPickerCtrl()
    item_box = colour_picker.create(panel, value=value, event=bind, key=key)

    item_text = wx.StaticText(panel, label=translate_key(item_name))
    item_sizer.Add(item_text, 0, wx.ALIGN_CENTER)
    item_sizer.Add(item_box, 1, wx.EXPAND)
    return {'item': item_sizer, 'text_size': item_text.GetSize()[0], 'text_ctrl': item_text}
Exemplo n.º 24
0
 def opened(self):
     log.info("Connection Successful")
     payload = {
         "type": "method",
         "method": "auth",
         "arguments": [self.channel_id]
     }
     self.send_payload(payload)
     self.system_message(
         translate_key('beampro.connection_success').format(
             self.channel_nick))
Exemplo n.º 25
0
def create_dropdown(panel=None, value=None, key=None, bind=None, gui=None, **kwargs):
    item_sizer = wx.BoxSizer(wx.HORIZONTAL)
    choices = value.list
    item_name = MODULE_KEY.join(key)
    item_text = wx.StaticText(panel, label=translate_key(item_name))
    item_box = KeyChoice(panel, id=id_renew(item_name, update=True),
                         keys=choices, choices=choices)
    item_box.Bind(wx.EVT_CHOICE, bind)
    item_box.SetSelection(choices.index(str(value)))
    item_sizer.Add(item_text, 0, wx.ALIGN_CENTER)
    item_sizer.Add(item_box)
    return {'item': item_sizer, 'text_size': item_text.GetSize()[0], 'text_ctrl': item_text}
Exemplo n.º 26
0
def create_static_box(source_class, panel=None, value=None,
                      gui=None, key=None, show_hidden=None, **kwargs):
    if isinstance(value, LCPanel):
        return wx.BoxSizer(wx.VERTICAL)
    item_value = value

    static_box = wx.StaticBox(panel, label=translate_key(MODULE_KEY.join(key)))
    static_sizer = wx.StaticBoxSizer(static_box, wx.VERTICAL)
    instatic_sizer = wx.BoxSizer(wx.VERTICAL)
    spacer_size = 7

    max_text_size = 0
    text_ctrls = []
    log.debug("Working on {0}".format(MODULE_KEY.join(key)))
    spacer = False
    hidden_items = gui.get('hidden', [])

    for item, value in item_value.items():
        if item in hidden_items and not show_hidden:
            continue

        view = type(value)
        if view in source_class.controls.keys():
            bind_fn = source_class.controls[view]
        elif callable(value):
            bind_fn = source_class.controls['button']
        else:
            # bind_fn = {'function': create_empty}
            raise GuiCreationError('Unable to create item, bad value map')
        item_dict = bind_fn['function'](source_class=source_class, panel=static_box, item=item,
                                        value=value, key=key + [item],
                                        bind=bind_fn.get('bind'), gui=gui.get(item, {}),
                                        from_sb=True)
        if 'text_size' in item_dict:
            if max_text_size < item_dict.get('text_size'):
                max_text_size = item_dict['text_size']

            text_ctrls.append(item_dict['text_ctrl'])
        spacer = True if not spacer else instatic_sizer.AddSpacer(spacer_size)
        instatic_sizer.Add(item_dict['item'], 0, wx.EXPAND, 5)

    if max_text_size:
        for ctrl in text_ctrls:
            ctrl.SetMinSize((max_text_size + 50, ctrl.GetSize()[1]))

    item_count = instatic_sizer.GetItemCount()
    if not item_count:
        static_sizer.Destroy()
        return wx.BoxSizer(wx.VERTICAL)

    static_sizer.Add(instatic_sizer, 0, wx.EXPAND | wx.ALL, 5)
    return static_sizer
Exemplo n.º 27
0
 def _process_user_ban(self, msg):
     if msg['data']['duration']:
         self.ws_class.system_message(translate_key(
             MODULE_KEY.join(['goodgame',
                              'ban'])).format(msg['data']['moder_name'],
                                              msg['data']['user_name'],
                                              msg['data']['duration'] / 60,
                                              msg['data']['reason']),
                                      category='chat')
     else:
         if msg['data']['permanent']:
             self.ws_class.system_message(translate_key(
                 MODULE_KEY.join(['goodgame', 'ban_permanent'
                                  ])).format(msg['data']['moder_name'],
                                             msg['data']['user_name']),
                                          category='chat')
         else:
             self.ws_class.system_message(translate_key(
                 MODULE_KEY.join(['goodgame', 'unban'
                                  ])).format(msg['data']['moder_name'],
                                             msg['data']['user_name']),
                                          category='chat')
Exemplo n.º 28
0
    def closed(self, code, reason=None):
        """
        Codes used by LC
        4000 - Normal disconnect by LC
        4001 - Invalid Channel ID

        :param code: 
        :param reason: 
        """
        self.chat_module.set_offline(self.channel_name)
        if code in [4000, 4001]:
            self.crit_error = True
            self.fs_system_message(translate_key(
                MODULE_KEY.join(['sc2tv', 'connection_closed'])).format(self.channel_name),
                                category='connection')
        else:
            log.info("Websocket Connection Closed Down")
            self.fs_system_message(
                translate_key(MODULE_KEY.join(['sc2tv', 'connection_died'])).format(self.channel_name),
                category='connection')
            timer = threading.Timer(5.0, self.main_thread.connect)
            timer.start()
Exemplo n.º 29
0
    def on_close(self, event):
        dialog = wx.MessageDialog(self,
                                  message=translate_key(
                                      MODULE_KEY.join(['main', 'quit'])),
                                  caption="Caption",
                                  style=wx.YES_NO | wx.CANCEL,
                                  pos=wx.DefaultPosition)
        response = dialog.ShowModal()

        if response == wx.ID_YES:
            self.on_exit(event)
        else:
            event.StopPropagation()
Exemplo n.º 30
0
    def on_listbox_change(self, event):
        item_object = event.EventObject
        selection = item_object.get_key_from_index(item_object.GetSelection())
        description = translate_key(MODULE_KEY.join([selection, 'description']))

        item_key = IDS[event.GetId()].split(MODULE_KEY)
        show_description = self.main_class.loaded_modules[item_key[0]]['gui'][item_key[1]].get('description', False)

        if show_description:
            item_id_key = MODULE_KEY.join(item_key[:-1])
            descr_static_text = wx.FindWindowById(get_id_from_name(MODULE_KEY.join([item_id_key, 'descr_explain'])))
            descr_static_text.SetLabel(description)
            descr_static_text.Wrap(descr_static_text.GetSize()[0])
Exemplo n.º 31
0
 def on_settings(self, event):
     log.debug("Got event from {0}".format(IDS[event.GetId()]))
     module_groups = IDS[event.GetId()].split(MODULE_KEY)
     settings_category = MODULE_KEY.join(module_groups[1:-1])
     settings_menu_id = id_renew(settings_category, update=True)
     if self.settings_window:
         self.settings_window.SetFocus()
     else:
         self.settings_window = SettingsWindow(self,
                                               id=settings_menu_id,
                                               title=translate_key('settings'),
                                               size=(700, 400),
                                               main_class=self,
                                               categories=self.sorted_categories)
Exemplo n.º 32
0
def create_spin(panel=None, value=None, key=None, bind=None, **kwargs):
    item_class = value
    item_sizer = wx.BoxSizer(wx.HORIZONTAL)
    item_name = MODULE_KEY.join(key)
    style = wx.ALIGN_LEFT
    item_box = wx.SpinCtrl(panel, id=id_renew(item_name, update=True),
                           min=item_class.min, max=item_class.max,
                           initial=value.simple(), style=style)
    item_text = wx.StaticText(panel, label=translate_key(item_name))
    item_box.Bind(wx.EVT_SPINCTRL, bind)
    item_box.Bind(wx.EVT_TEXT, bind)
    item_sizer.Add(item_text, 0, wx.ALIGN_CENTER)
    item_sizer.Add(item_box)
    return {'item': item_sizer, 'text_size': item_text.GetSize()[0], 'text_ctrl': item_text}
Exemplo n.º 33
0
def create_slider(panel=None, value=None, key=None, bind=None, gui=None, **kwargs):
    item_sizer = wx.BoxSizer(wx.HORIZONTAL)
    item_name = MODULE_KEY.join(key)
    style = wx.SL_VALUE_LABEL | wx.SL_AUTOTICKS
    item_box = wx.Slider(panel, id=id_renew(item_name, update=True),
                         minValue=gui['min'], maxValue=gui['max'],
                         value=int(value), style=style)
    freq = (gui['max'] - gui['min'])/5
    item_box.SetTickFreq(freq)
    item_box.SetLineSize(4)
    item_box.Bind(wx.EVT_SCROLL, bind)
    item_text = wx.StaticText(panel, label=translate_key(item_name))
    item_sizer.Add(item_text, 0, wx.ALIGN_CENTER)
    item_sizer.Add(item_box, 1, wx.EXPAND)
    return {'item': item_sizer, 'text_size': item_text.GetSize()[0], 'text_ctrl': item_text}
Exemplo n.º 34
0
 def on_settings(self, event):
     log.debug("Got event from {0}".format(IDS[event.GetId()]))
     module_groups = IDS[event.GetId()].split(MODULE_KEY)
     settings_category = MODULE_KEY.join(module_groups[1:-1])
     settings_menu_id = id_renew(settings_category, update=True)
     if self.settings_window:
         self.settings_window.SetFocus()
     else:
         self.settings_window = SettingsWindow(
             self,
             id=settings_menu_id,
             title=translate_key('settings'),
             size=(700, 400),
             main_class=self,
             categories=self.sorted_categories)
Exemplo n.º 35
0
 def on_welcome(self, connection, event):
     log.info("Welcome Received, joining {0} channel".format(self.channel))
     log.debug("event: {}".format(event))
     self.tw_connection = connection
     self.system_message(translate_key(
         MODULE_KEY.join(['twitch', 'joining'])).format(self.channel),
                         category='connection')
     # After we receive IRC Welcome we send request for join and
     #  request for Capabilities (Twitch color, Display Name,
     #  Subscriber, etc)
     connection.join(self.channel)
     connection.cap('REQ', ':twitch.tv/tags')
     connection.cap('REQ', ':twitch.tv/commands')
     ping_handler = TwitchPingHandler(connection, self.chat_module, self)
     ping_handler.start()
Exemplo n.º 36
0
    def create_layout(self):
        self.main_grid = wx.BoxSizer(wx.HORIZONTAL)
        tree_ctrl_size = wx.Size(220, -1)
        style = wx.TR_DEFAULT_STYLE | wx.TR_HIDE_ROOT | wx.TR_TWIST_BUTTONS | wx.TR_NO_LINES
        # style = wx.TR_HAS_BUTTONS | wx.TR_SINGLE | wx.TR_HIDE_ROOT

        tree_ctrl_id = id_renew('settings.tree', update=True)
        tree_ctrl = wx.TreeCtrl(self, id=tree_ctrl_id, style=style)
        tree_ctrl.SetMinSize(tree_ctrl_size)
        root_key = MODULE_KEY.join(['settings', 'tree', 'root'])
        root_node = tree_ctrl.AddRoot(translate_key(root_key))
        for item, value in self.categories.iteritems():
            item_key = MODULE_KEY.join(['settings', item])
            item_data = wx.TreeItemData()
            item_data.SetData(item_key)

            item_node = tree_ctrl.AppendItem(root_node, translate_key(item_key), data=item_data)
            for f_item, f_value in value.iteritems():
                if not f_item == item:
                    f_item_key = MODULE_KEY.join([item_key, f_item])
                    f_item_data = wx.TreeItemData()
                    f_item_data.SetData(f_item_key)
                    tree_ctrl.AppendItem(item_node, translate_key(f_item), data=f_item_data)
        tree_ctrl.ExpandAll()

        self.tree_ctrl = tree_ctrl
        self.Bind(wx.EVT_TREE_SEL_CHANGED, self.tree_ctrl_changed, id=tree_ctrl_id)
        self.main_grid.Add(self.tree_ctrl, 0, wx.EXPAND | wx.ALL, 7)

        content_page_id = id_renew(MODULE_KEY.join(['settings', 'content']))
        self.content_page = wx.Panel(self, id=content_page_id)
        self.main_grid.Add(self.content_page, 1, wx.EXPAND)

        self.main_grid.Layout()
        self.SetSizer(self.main_grid)
        tree_ctrl.SelectItem(tree_ctrl.GetFirstChild(root_node)[0])
Exemplo n.º 37
0
    def fs_join(self):
        # Then we send the message acording to needed format and
        #  hope it joins us
        if self.channel_id:
            payload = [
                '/chat/join',
                {
                    'channel': 'stream/{0}'.format(str(self.channel_id))
                }
            ]
            self.fs_send(payload)

            msg_joining = translate_key(MODULE_KEY.join(['sc2tv', 'joining']))
            self.fs_system_message(msg_joining.format(self.channel_name), category='connection')
            log.info(msg_joining.format(self.channel_id))
Exemplo n.º 38
0
    def on_listbox_change(self, event):
        item_object = event.EventObject
        selection = item_object.get_key_from_index(item_object.GetSelection())
        description = translate_key(MODULE_KEY.join([selection,
                                                     'description']))

        item_key = IDS[event.GetId()].split(MODULE_KEY)
        show_description = self.main_class.loaded_modules[item_key[0]]['gui'][
            item_key[1]].get('description', False)

        if show_description:
            item_id_key = MODULE_KEY.join(item_key[:-1])
            descr_static_text = wx.FindWindowById(
                get_id_from_name(
                    MODULE_KEY.join([item_id_key, 'descr_explain'])))
            descr_static_text.SetLabel(description)
            descr_static_text.Wrap(descr_static_text.GetSize()[0])
Exemplo n.º 39
0
 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
Exemplo n.º 40
0
 def create_dropdown(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)
     choices = section_gui.get('choices')
     key = key if section_item else MODULE_KEY.join([key, 'dropdown'])
     item_box = KeyChoice(parent,
                          id=id_renew(key, update=True),
                          keys=choices,
                          choices=choices)
     item_value = section[short_key] if section_item else section
     item_box.SetSelection(choices.index(item_value))
     return item_text, item_box
Exemplo n.º 41
0
    def fill_sc_with_config(self, panel, category_config, category_item):
        page_sc_window = wx.ScrolledWindow(panel, id=id_renew(category_item), style=wx.VSCROLL)
        page_sc_window.SetScrollbars(5, 5, 10, 10)
        border_all = 5
        sizer = wx.BoxSizer(wx.VERTICAL)
        for section_key, section_items in category_config['config'].items():
            if section_key in SKIP_TAGS:
                continue

            static_key = MODULE_KEY.join([category_item, section_key])
            static_box = wx.StaticBox(page_sc_window, label=translate_key(static_key))
            static_sizer = wx.StaticBoxSizer(static_box, wx.VERTICAL)

            log.debug("Working on {0}".format(static_key))

            static_sizer.Add(self.create_items(static_box, static_key,
                                               section_items, category_config.get('gui', {}).get(section_key, {})),
                             0, wx.EXPAND | wx.ALL, border_all)

            sizer.Add(static_sizer, 0, wx.EXPAND)
        page_sc_window.SetSizer(sizer)
        return page_sc_window
Exemplo n.º 42
0
    def create_choose(self, parent, view, key, section, section_gui):
        is_single = True if 'single' in view else False
        description = section_gui.get('description', False)
        style = wx.LB_SINGLE if is_single else wx.LB_EXTENDED
        item_sizer = wx.BoxSizer(wx.VERTICAL)
        list_items = []
        translated_items = []

        if section_gui['check_type'] in ['dir', 'folder', 'files']:
            check_type = section_gui['check_type']
            keep_extension = section_gui['file_extension'] if 'file_extension' in section_gui else False
            for item_in_list in os.listdir(os.path.join(self.main_class.main_config['root_folder'],
                                                        section_gui['check'])):
                item_path = os.path.join(self.main_class.main_config['root_folder'],
                                         section_gui['check'], item_in_list)
                if check_type in ['dir', 'folder'] and os.path.isdir(item_path):
                    list_items.append(item_in_list)
                elif check_type == 'files' and os.path.isfile(item_path):
                    if not keep_extension:
                        item_in_list = ''.join(os.path.basename(item_path).split('.')[:-1])
                    if '__init__' not in item_in_list:
                        if item_in_list not in list_items:
                            list_items.append(item_in_list)
                            translated_items.append(translate_key(item_in_list))
        elif section_gui['check_type'] == 'sections':
            parser = ConfigParser(allow_no_value=True)
            parser.read(section_gui.get('check', ''))
            for item in parser.sections():
                list_items.append(translate_key(item))

        item_key = MODULE_KEY.join([key, 'list_box'])
        label_text = translate_key(item_key)
        if label_text:
            item_sizer.Add(wx.StaticText(parent, label=label_text, style=wx.ALIGN_RIGHT))
        if is_single:
            item_list_box = KeyListBox(parent, id=id_renew(item_key, update=True), keys=list_items,
                                       choices=translated_items if translated_items else list_items, style=style)
        else:
            item_list_box = KeyCheckListBox(parent, id=id_renew(item_key, update=True), keys=list_items,
                                            choices=translated_items if translated_items else list_items)
        self.Bind(wx.EVT_LISTBOX, self.on_listbox_change, item_list_box)

        section_for = section if not is_single else {section: None}
        if is_single:
            [item_list_box.SetSelection(list_items.index(item)) for item, value in section_for.items()]
        else:
            check_items = [list_items.index(item) for item, value in section_for.items()]
            item_list_box.SetChecked(check_items)
        if description:
            adv_sizer = wx.BoxSizer(wx.HORIZONTAL)
            adv_sizer.Add(item_list_box, 0, wx.EXPAND)

            descr_key = MODULE_KEY.join([key, 'descr_explain'])
            descr_text = wx.StaticText(parent, id=id_renew(descr_key, update=True),
                                       label=translate_key(descr_key), style=wx.ST_NO_AUTORESIZE)
            adv_sizer.Add(descr_text, 0, wx.EXPAND | wx.LEFT, 10)

            sizes = descr_text.GetSize()
            sizes[0] -= 20
            descr_text.SetMinSize(sizes)
            descr_text.Fit()
            # descr_text.Wrap(descr_text.GetSize()[0])
            item_sizer.Add(adv_sizer)
        else:
            item_sizer.Add(item_list_box)
        return item_sizer
Exemplo n.º 43
0
 def create_button(button_key, function):
     button_id = id_renew(button_key, update=True)
     c_button = wx.Button(panel, id=button_id, label=translate_key(button_key))
     self.Bind(wx.EVT_BUTTON, function, id=button_id)
     return c_button