Python wx.LIST_STATE_SELECTED Examples

The following are 23 code examples of wx.LIST_STATE_SELECTED(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module wx , or try the search function .
Example #1
Source File: ObjectListView.py    From bookhub with MIT License 6 votes vote down vote up
def SelectObject(self, modelObject, deselectOthers=True, ensureVisible=False):
        """
        Select the given modelObject. If deselectOthers is True, all other rows will be deselected
        """
        i = self.GetIndexOf(modelObject)
        if i == -1:
            return

        if deselectOthers:
            self.DeselectAll()

        realIndex = self._MapModelIndexToListIndex(i)
        self.SetItemState(realIndex, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED)

        if ensureVisible:
            self.EnsureVisible(realIndex) 
Example #2
Source File: ListCtrl.py    From BitTorrent with GNU General Public License v3.0 6 votes vote down vote up
def selectBeforePopup(ctrl, pos):
    """Ensures the item the mouse is pointing at is selected before a popup.

    Works with both single-select and multi-select lists."""

    if not isinstance(ctrl, wx.ListCtrl):
        return

    n, flags = ctrl.HitTest(pos)
    if n < 0:
        return

    if not ctrl.GetItemState(n, wx.LIST_STATE_SELECTED):
        for i in xrange(ctrl.GetItemCount()):
            ctrl.SetItemState(i, 0, SEL_FOC)
        ctrl.SetItemState(n, SEL_FOC, SEL_FOC) 
Example #3
Source File: menubar.py    From wxGlade with MIT License 6 votes vote down vote up
def move_item_right(self, event):
        """moves the selected menu item one level down in the hierarchy, i.e.
        shifts its label 4 spaces right in self.menu_items"""
        index = self.selected_index
        if index <= 0:
            wx.Bell()
            return
        level = self.item_level(index)
        if level > self.item_level(index-1):
            wx.Bell()
            return
        level += 1
        label = self._get_item_text(index, "label")
        self._set_item_string(index, "label", misc.wxstr(" "*4) + label)
        self._set_item_string(index, "level", level)
        self.items.SetItemState(index, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED)
        self._enable_buttons() 
Example #4
Source File: menubar.py    From wxGlade with MIT License 6 votes vote down vote up
def move_item_left(self, event=None, index=None):
        """moves the selected menu item one level up in the hierarchy, i.e.
        shifts its label 4 spaces left in self.menu_items"""
        if index is None:
            index = self.selected_index
        if index <= 0:
            wx.Bell()
            return
        level = self.item_level(index)
        if level==0 or ( index+1 < self.items.GetItemCount() and (level < self.item_level(index+1)) ):
            wx.Bell()
            return
        level -= 1
        label = self._get_item_text(index, "label")
        self._set_item_string(index, "label", label[4:])
        self._set_item_string(index, "level", level)
        self.items.SetItemState(index, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED)
        self._enable_buttons() 
Example #5
Source File: menubar.py    From wxGlade with MIT License 5 votes vote down vote up
def _insert_item(self, index, item):
        self._insert_item_string(index, item[0])
        for col, value in enumerate(item):
            if col==0: continue
            value = compat.unicode(value) if value is not None else ""
            self._set_item_string(index, col, value)
        self.items.SetItemState(index, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED)  # fix bug 698074 
Example #6
Source File: ObjectListView.py    From bookhub with MIT License 5 votes vote down vote up
def YieldSelectedObjects(self):
        """
        Progressively yield the selected modelObjects.

        Only return model objects, not blank lines or ListGroups
        """
        i = self.GetNextItem(-1, wx.LIST_NEXT_ALL, wx.LIST_STATE_SELECTED)
        while i != -1:
            model = self.GetObjectAt(i)
            if model is not None:
                yield model
            i = self.GetNextItem(i, wx.LIST_NEXT_ALL, wx.LIST_STATE_SELECTED) 
Example #7
Source File: ObjectListView.py    From bookhub with MIT License 5 votes vote down vote up
def SelectAll(self):
        """
        Selected all model objects in the control.

        In a GroupListView, this does not select blank lines or groups
        """
        self.SetItemState(-1, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED)

        for (i, x) in enumerate(self.innerList):
            if x is None or isinstance(x, ListGroup):
                self.SetItemState(i, 0, wx.LIST_STATE_SELECTED)

    # With the current implemetation, these are synonyms 
Example #8
Source File: ObjectListView.py    From bookhub with MIT License 5 votes vote down vote up
def DeselectAll(self):
        """
        De-selected all rows in the control
        """
        # -1 indicates 'all items'
        self.SetItemState(-1, 0, wx.LIST_STATE_SELECTED) 
Example #9
Source File: ObjectListView.py    From bookhub with MIT License 5 votes vote down vote up
def SelectAll(self):
        """
        Selected all rows in the control
        """
        # -1 indicates 'all items'
        self.SetItemState(-1, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED) 
Example #10
Source File: ObjectListView.py    From bookhub with MIT License 5 votes vote down vote up
def YieldSelectedObjects(self):
        """
        Progressively yield the selected modelObjects
        """
        i = self.GetNextItem(-1, wx.LIST_NEXT_ALL, wx.LIST_STATE_SELECTED)
        while i != -1:
            yield self.GetObjectAt(i)
            i = self.GetNextItem(i, wx.LIST_NEXT_ALL, wx.LIST_STATE_SELECTED)


    #----------------------------------------------------------------------------
    # Calculating 
Example #11
Source File: LogCtrl.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def OnCmdCopy(self, dummyEvent=None):
        text = ""
        lines = 1
        firstItem = item = self.GetNextItem(
            -1,
            wx.LIST_NEXT_ALL,
            wx.LIST_STATE_SELECTED
        )
        if item != -1:
            text = self.OnGetItemText(item, 0)[1:]
            item = self.GetNextItem(
                item,
                wx.LIST_NEXT_ALL,
                wx.LIST_STATE_SELECTED
            )
            while item != -1:
                lines += 1
                text += "\r\n" + self.OnGetItemText(item, 0)[1:]
                item = self.GetNextItem(
                    item,
                    wx.LIST_NEXT_ALL,
                    wx.LIST_STATE_SELECTED
                )
        if text != "" and wx.TheClipboard.Open():
            textDataObject = wx.TextDataObject(text)
            dataObjectComposite = wx.DataObjectComposite()
            dataObjectComposite.Add(textDataObject)
            if lines == 1:
                eventstring, icon = self.GetItemData(firstItem)[:2]
                if icon == EVENT_ICON:
                    customDataObject = wx.CustomDataObject("DragEventItem")
                    customDataObject.SetData(eventstring.encode("UTF-8"))
                    dataObjectComposite.Add(customDataObject)

            wx.TheClipboard.SetData(dataObjectComposite)
            wx.TheClipboard.Close()
            wx.TheClipboard.Flush() 
Example #12
Source File: LogCtrl.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def FocusLastItem(self):
        if self.GetFocusedItem() == -1:
            item = len(self.data) - 1
            self.Focus(item)
            self.SetItemState(item, 0, wx.LIST_STATE_SELECTED) 
Example #13
Source File: toolbar.py    From wxGlade with MIT License 5 votes vote down vote up
def _select_item(self, index, force=False):
        item_count = self.items.GetItemCount()
        if index == -1 and item_count: index = 0
        if index >= item_count and item_count: index = item_count-1
        if index==self.selected_index and not force: return
        self.selected_index = index
        if index == -1:
            self._enable_fields(False, clear=True)
            self._enable_buttons()
            return

        self._ignore_events = True
        self.items.Select(index)

        if self._get_item_text(index, "label") != '---':
            # skip if the selected item is a separator
            for i,colname in enumerate(self.columns):
                s = getattr(self, colname)
                coltype = self.coltypes.get(colname,None)
                value = self._get_item_text(index, i)
                if coltype is None:
                    # at this point, the value should be validated already
                    s.SetBackgroundColour( compat.wx_SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW) )
                    s.SetValue(value)
                elif coltype is int:
                    s.SetSelection( int(value) )
            self.label.SetValue(self.label.GetValue().lstrip())
            self._enable_fields(True)
        else:
            self._enable_fields(False, clear=True)
        self._enable_buttons()
        state = wx.LIST_STATE_SELECTED | wx.LIST_STATE_FOCUSED
        self.items.SetItemState(index, state, state)  # fix bug 698071 
Example #14
Source File: namesdlg.py    From trelby with GNU General Public License v2.0 5 votes vote down vote up
def selectAllTypes(self, event = None):
        for i in range(len(nameArr.typeNamesById)):
            self.typeList.SetItemState(i, wx.LIST_STATE_SELECTED,
                                       wx.LIST_STATE_SELECTED) 
Example #15
Source File: menubar.py    From wxGlade with MIT License 5 votes vote down vote up
def _select_item(self, index, force=False):
        item_count = self.items.GetItemCount()
        if index == -1 and item_count: index = 0
        if index >= item_count and item_count: index = item_count-1
        if index==self.selected_index and not force: return
        self.selected_index = index
        if index == -1:
            self._enable_fields(False, clear=True)
            self._enable_buttons()
            return

        self._ignore_events = True
        self.items.Select(index)

        if self._get_item_text(index, "name") != '---':
            # skip if the selected item is a separator
            for i,colname in enumerate(self.columns):
                s = getattr(self, colname, None)
                if not s: continue
                coltype = self.coltypes.get(colname,None)
                value = self._get_item_text(index, i)
                if coltype is None:
                    # at this point, the value should be validated already
                    s.SetBackgroundColour( compat.wx_SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW) )
                    s.SetValue(value)
                elif coltype is int:
                    s.SetSelection( int(value) )
            self.label.SetValue(self.label.GetValue().lstrip())
            self._enable_fields(True)
        else:
            self._enable_fields(False, clear=True)
        self._enable_buttons()
        state = wx.LIST_STATE_SELECTED | wx.LIST_STATE_FOCUSED
        self.items.SetItemState(index, state, state)  # fix bug 698071 
Example #16
Source File: ListCtrl.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def DeselectAll(self):
        self.SetItemState(-1, 0, wx.LIST_STATE_SELECTED)
        # fallback. for extremely long lists a generator should be used
        #for i in xrange(self.GetItemCount()):
        #    self.SetItemState(i, 0, wx.LIST_STATE_SELECTED) 
Example #17
Source File: mainframe.py    From youtube-dl-gui with The Unlicense 5 votes vote down vote up
def get_selected(self):
        return self.GetNextItem(-1, wx.LIST_NEXT_ALL, wx.LIST_STATE_SELECTED) 
Example #18
Source File: dfgui.py    From PandasDataFrameGUI with MIT License 5 votes vote down vote up
def get_selected_items(self):
        """
        Gets the selected items for the list control.
        Selection is returned as a list of selected indices,
        low to high.
        """
        selection = []
        current = -1    # start at -1 to get the first selected item
        while True:
            next = self.GetNextItem(current, wx.LIST_NEXT_ALL, wx.LIST_STATE_SELECTED)
            if next == -1:
                return selection
            else:
                selection.append(next)
                current = next 
Example #19
Source File: core.py    From wafer_map with GNU General Public License v3.0 5 votes vote down vote up
def _ListCtrl_IsSelected(self, idx):
    """
    Returns ``True`` if the item is selected.
    """
    return (self.GetItemState(idx, wx.LIST_STATE_SELECTED) & wx.LIST_STATE_SELECTED) != 0 
Example #20
Source File: core.py    From wafer_map with GNU General Public License v3.0 5 votes vote down vote up
def _ListCtrl_GetNextSelected(self, item):
    """
    Returns subsequent selected items, or -1 when no more are selected.
    """
    return self.GetNextItem(item, wx.LIST_NEXT_ALL, wx.LIST_STATE_SELECTED) 
Example #21
Source File: core.py    From wafer_map with GNU General Public License v3.0 5 votes vote down vote up
def _ListCtrl_Select(self, idx, on=1):
    """
    Selects/deselects an item.
    """
    if on: state = wx.LIST_STATE_SELECTED
    else: state = 0
    self.SetItemState(idx, state, wx.LIST_STATE_SELECTED) 
Example #22
Source File: namesdlg.py    From trelby with GNU General Public License v2.0 5 votes vote down vote up
def OnInsertName(self, event):
        item = self.list.GetNextItem(-1, wx.LIST_NEXT_ALL,
                                     wx.LIST_STATE_SELECTED)

        if item == -1:
            return

        # this seems to return column 0's text, which is lucky, because I
        # don't see a way of getting other columns' texts...
        name = self.list.GetItemText(item)

        for ch in name:
            self.ctrl.OnKeyChar(util.MyKeyEvent(ord(ch))) 
Example #23
Source File: namesdlg.py    From trelby with GNU General Public License v2.0 4 votes vote down vote up
def OnSearch(self, event = None):
        l = []

        wx.BeginBusyCursor()

        s = util.lower(misc.fromGUI(self.searchEntry.GetValue()))
        sex = self.sexRb.GetSelection()
        nt = self.nameRb.GetSelection()

        selTypes = {}
        item = -1

        while 1:
            item = self.typeList.GetNextItem(item, wx.LIST_NEXT_ALL,
                wx.LIST_STATE_SELECTED)

            if item == -1:
                break

            selTypes[self.typeList.GetItemData(item)] = True

        if len(selTypes) == len(nameArr.typeNamesCnt):
            doTypes = False
        else:
            doTypes = True

        for i in xrange(nameArr.count):
            if (sex != 2) and (sex == nameArr.sex[i]):
                continue

            if doTypes and nameArr.type[i] not in selTypes:
                continue

            if s:
                name = util.lower(nameArr.name[i])

                if nt == 0:
                    if not name.startswith(s):
                        continue
                elif nt == 1:
                    if name.find(s) == -1:
                        continue
                elif nt == 2:
                    if not name.endswith(s):
                        continue

            l.append(i)

        self.list.items = l
        self.list.SetItemCount(len(l))
        self.list.EnsureVisible(0)

        wx.EndBusyCursor()

        self.foundLabel.SetLabel("%d names found." % len(l))