Beispiel #1
0
 def addMask(self, lst, name, regexp, active):
     event = wx.KeyEvent(wx.wxEVT_CHAR)
     event.SetKeyCode(wx.WXK_CONTROL_M)
     lst.GetEventHandler().ProcessEvent(event)
     row_id = lst.GetItemCount() - 1
     lst.SetItem(row_id, 1, name)
     lst.SetItem(row_id, 2, regexp)
     event = wx.ListEvent(wx.wxEVT_LIST_END_LABEL_EDIT)
     event.SetIndex(row_id)
     event.SetColumn(2)
     lst.GetEventHandler().ProcessEvent(event)
     lst.CheckItem(row_id, active)
Beispiel #2
0
 def addItem(self, item):
     if not isinstance(item, wx.Window):
         item = self.ArrayBtn(self, label=item)
     self.sizer.Insert(0,
                       item,
                       border=3,
                       flag=wx.EXPAND | wx.TOP | wx.BOTTOM | wx.RIGHT)
     self.Layout()
     # Raise event
     evt = wx.ListEvent(wx.EVT_LIST_INSERT_ITEM.typeId)
     evt.SetEventObject(self)
     wx.PostEvent(self, evt)
Beispiel #3
0
def test_right_click_transaction(populated_panel):
    event = wx.ListEvent(wx.wxEVT_LIST_ITEM_RIGHT_CLICK,
                         populated_panel.transactions.GetId())
    event.SetItem(populated_panel.transactions.GetItem(0))

    # Patch PopupMenu so that the menu isn't actually created since there
    # doesn't seem to be a good way to cause it to go away
    with patch.object(populated_panel, 'PopupMenu', (lambda _: None)):
        populated_panel.GetEventHandler().ProcessEvent(event)

    event = wx.CommandEvent(
        wx.wxEVT_MENU,
        id=populated_panel.popup_menu.FindItemByPosition(0).GetId())
    populated_panel.GetEventHandler().ProcessEvent(event)
    def ActivateNth(self, nth):
        """activates the nth item in the list and invokes the appropriate 
       event handler.
       
       Note: This  is not the same as self.Select(nth), because the later
       changes the selection without invoking the selection event handler.
       """
        self.Select(nth)
        evt = wx.ListEvent(wx.EVT_COMMAND_LIST_ITEM_ACTIVATED, self.GetId())

        # AD: This fails in wx.Python < 2.5 (m_itemIndex is private attribute)
        evt.m_itemIndex = nth

        self.ProcessEvent(evt)
Beispiel #5
0
 def removeItem(self, item):
     items = self.items.copy()
     # Get value from key if needed
     if item in items:
         item = items[item]
     # Delete object and item in dict
     if item in list(items.values()):
         i = self.sizer.Children.index(self.sizer.GetItem(item))
         self.sizer.Remove(i)
         item.Hide()
     self.Layout()
     # Raise event
     evt = wx.ListEvent(wx.EVT_LIST_DELETE_ITEM.typeId)
     evt.SetEventObject(self)
     wx.PostEvent(self, evt)
Beispiel #6
0
    def OnEndLabelEdit(self, event):
        # return
        if event.GetIndex(
        ) == self.m_listCtrl.GetItemCount() - 1 and event.GetText():
            # The user edited last (empty) line, i.e. added new entry. We have to
            # add new empty line here so that adding one more line is still
            # possible:
            self.m_listCtrl.InsertItem(self.m_listCtrl.GetItemCount(), '')

            # Simulate a wxEVT_LIST_ITEM_SELECTED event for the new item,
            # so that the buttons are enabled/disabled properly
            selectionEvent = wx.ListEvent(wx.wxEVT_LIST_ITEM_SELECTED,
                                          self.m_listCtrl.GetId())
            selectionEvent.SetIndex(event.GetIndex())
            self.m_listCtrl.GetEventHandler().ProcessEvent(selectionEvent)
Beispiel #7
0
 def OnChar(self, e):
     key = e.GetKeyCode()
     up = key in (wx.WXK_UP, wx.WXK_NUMPAD_UP)
     down = key in (wx.WXK_DOWN, wx.WXK_NUMPAD_DOWN)
     if (up or down) and ((self.__noctrl and not e.ControlDown())
                          or e.ControlDown()):
         self._select(down)
     elif key == wx.WXK_NUMPAD_ENTER or (e.AltDown()
                                         and key == wx.WXK_RETURN):
         if self.GetFirstSelected() == -1:
             self.SelectNext()
         wx.PostEvent(
             self,
             wx.ListEvent(wx.wxEVT_COMMAND_LIST_ITEM_ACTIVATED,
                          self.GetId()))
     else:
         e.Skip()
Beispiel #8
0
    def on_menu(self, event):
        menu_item = event.GetId()

        if menu_item == ID_EDIT_JUMP:
            evt = wx.ListEvent(wx.wxEVT_LISTBOX_DCLICK, id=wx.ID_ANY)
            evt.SetInt(self.GetSelection())

            wx.PostEvent(self, evt)
        elif menu_item == ID_ADD_JUMP:
            evt = JumpAdded(id=wx.ID_ANY)

            wx.PostEvent(self, evt)

        elif menu_item == ID_DEL_JUMP:
            evt = JumpRemoved(id=wx.ID_ANY)
            evt.SetInt(self.GetSelection())

            wx.PostEvent(self, evt)
def right_click_item(control, index):
    """ Right clicks on the specified item.
    """

    if is_wx():
        import wx

        event = wx.ListEvent(wx.EVT_LIST_ITEM_RIGHT_CLICK.typeId,
                             control.GetId())
        event.SetIndex(index)
        wx.PostEvent(control, event)

    elif is_qt():
        # Couldn't figure out how to close the context menu programatically
        raise unittest.SkipTest("Test not implemented for this toolkit")

    else:
        raise unittest.SkipTest("Test not implemented for this toolkit")
Beispiel #10
0
    def MovePicture(self, idxFrom, idxTo):
        pic = self.__pictures.pop(idxFrom)
        self.__pictures.insert(idxTo, pic)

        evt = None
        try:
            p = self.__selIdxs.index(idxFrom)
            self.__selIdxs[p] = idxTo
            evt = wx.ListEvent(wx.EVT_LIST_ITEM_SELECTED.typeId, self.GetId())
            evt.m_itemIndex = idxTo
            evt.m_oldItemIndex = idxFrom
        except ValueError:
            pass

        self.Refresh()
        self._SendChangedEvent()
        if evt:
            self.GetEventHandler().ProcessEvent(evt)
Beispiel #11
0
    def Clear(self):
        """
		Removes all items from the control
		"""

        for item in self._items:
            self.sizer_1.Hide(item)
            self.sizer_1.Remove(0)

            item.Destroy()
            self.Layout()

        self._items = []

        event = wx.ListEvent(wx.wxEVT_LIST_DELETE_ALL_ITEMS)
        event.SetEventObject(self)
        wx.PostEvent(self, event)

        return True
Beispiel #12
0
    def SwapPictures(self, idxFrom, idxTo):
        picFrom = self.__pictures[idxFrom]
        picTo = self.__pictures[idxTo]
        self.__pictures[idxFrom] = picTo
        self.__pictures[idxTo] = picFrom

        evt = None
        try:
            p = self.__selIdxs.index(idxFrom)
            self.__selIdxs[p] = idxTo
            evt = wx.ListEvent(wx.EVT_LIST_ITEM_SELECTED.typeId, self.GetId())
            evt.m_itemIndex = idxTo
            evt.m_oldItemIndex = idxFrom
        except ValueError:
            pass

        self.Refresh()
        self._SendChangedEvent()
        if evt:
            self.GetEventHandler().ProcessEvent(evt)
    def CloseEditor(self, event=None):
        """ Close the editor and save the new value to the ListCtrl. """
        
        #single editor mode. opening a new editor closes the previous one
        if not hasattr(self, 'editor'):
            return
                
        try:
            newText = self.editor.ShowModal()            
        except:
            self.editor.Hide()
            newText = self.editor.GetValue()
                        
        self.SetFocus()

        # post wxevent_COMMAND_LIST_END_LABEL_EDIT
        # Event can be vetoed. It doesn't have SetEditCanceled(), what would
        # require passing extra argument to CloseEditor()
        event = wx.ListEvent(wx.wxEVT_COMMAND_LIST_END_LABEL_EDIT, self.GetId())
        item = self.GetItem(self._editorRow, self._editorCol)        
        event.Item.SetId(item.GetId())
        event.Item.SetColumn(item.GetColumn())
        event.Item.SetData(item.GetData())
        event.Item.SetText(str(newText)) #should be empty string if editor was canceled
        ret = self.GetEventHandler().ProcessEvent(event)
        if not ret or event.IsAllowed():
            if self.IsVirtual():
                # replace by whatever you use to populate the virtual ListCtrl
                # data source
                self.SetVirtualData(self._editorRow, self._editorCol, text)
            else:
                self.SetItem(self._editorRow, self._editorCol, str(newText))
        self.RefreshItem(self._editorRow)
        
        self.selectedRow = None
        self.selectedCol = None
        self.editorRow = None
        self.editorCol = None
Beispiel #14
0
 def OnMenu(self, evt):
     """Handle Menu events"""
     e_id = evt.GetId()
     if e_id == ID_BROWSE:
         dlg = wx.FileDialog(self, _("Choose and executable"))
         if dlg.ShowModal() == wx.ID_OK:
             path = dlg.GetPath()
             if self._cindex >= 0:
                 self.SetStringItem(self._cindex, 1, path)
                 levt = wx.ListEvent(wx.wxEVT_COMMAND_LIST_END_LABEL_EDIT,
                                     self.GetId())
                 # TODO: ERR ><! there are no setters for index, column, and label...
                 #                    levt.Index = self._cindex
                 #                    levt.SetInt(self._cindex)
                 #                    levt.Column = 1
                 #                    levt.Label = path
                 # HACK set the member variables directly...
                 levt.m_itemIndex = self._cindex
                 levt.m_col = 1
                 levt.SetString(path)
                 wx.PostEvent(self.GetParent(), levt)
     else:
         evt.Skip()
Beispiel #15
0
 def OnClickDown(self, event):
     itemcount = self.mainlist.GetItemCount()
     if self.CurrentListItem < 0 or self.CurrentListItem == (itemcount - 1):
         return
     item_selected = -1
     for i in range(itemcount):
         if self.mainlist.IsSelected(i):
             item_selected = i
             break
     if item_selected < itemcount - 1:
         item = item_selected + 1
         item_next = item_selected
         t = self.mainlist.GetItem(item_next, 1).GetText()
         ischecked = self.mainlist.IsChecked(item_next)
         self.mainlist.DeleteItem(item_next)
         if IsNotWX4():
             mainlistidx = self.mainlist.InsertStringItem(item, "")
         else:
             mainlistidx = self.mainlist.InsertItem(item, "")
         if ischecked:
             self.mainlist.CheckItem(mainlistidx)
         if IsNotWX4():
             self.mainlist.SetStringItem(mainlistidx, 1, t)
         else:
             self.mainlist.SetItem(mainlistidx, 1, t)
         self.pipelineitems[item], self.pipelineitems[
             item_next] = self.pipelineitems[item_next], self.pipelineitems[
                 item]
         self.mainlist.Select(item, 1)
         cmd = wx.ListEvent(wx.EVT_LIST_ITEM_SELECTED.typeId,
                            self.mainlist.GetId())
         if IsNotWX4():
             cmd.m_itemIndex = item
         else:
             cmd.SetIndex(item)
         self.mainlist.GetEventHandler().ProcessEvent(cmd)
Beispiel #16
0
def dbl_click_list_ctrl(ctrl, idx):
    ctrl.Select(idx)
    evt = wx.ListEvent(wx.EVT_LIST_ITEM_ACTIVATED.typeId)
    evt.SetEventObject(ctrl)
    evt.SetId(ctrl.GetId())
    ctrl.GetEventHandler().ProcessEvent(evt)
    def OpenEditor(self, col, row):
        ''' Opens an editor at the current position. '''

        # give the derived class a chance to Allow/Veto this edit.
        evt = wx.ListEvent(wx.wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT,
                           self.GetId())
        evt.m_itemIndex = row
        evt.m_col = col
        item = self.GetItem(row, col)
        evt.m_item.SetId(item.GetId())
        evt.m_item.SetColumn(item.GetColumn())
        evt.m_item.SetData(item.GetData())
        evt.m_item.SetText(item.GetText())
        ret = self.GetEventHandler().ProcessEvent(evt)
        if ret and not evt.IsAllowed():
            return  # user code doesn't allow the edit.

        if self.GetColumn(col).m_format != self.col_style:
            self.make_editor(self.GetColumn(col).m_format)

        x0 = self.col_locs[col]
        x1 = self.col_locs[col + 1] - x0

        scrolloffset = self.GetScrollPos(wx.HORIZONTAL)

        # scroll forward
        if x0 + x1 - scrolloffset > self.GetSize()[0]:
            if wx.Platform == "__WXMSW__":
                # don't start scrolling unless we really need to
                offset = x0 + x1 - self.GetSize()[0] - scrolloffset
                # scroll a bit more than what is minimum required
                # so we don't have to scroll everytime the user presses TAB
                # which is very tireing to the eye
                addoffset = self.GetSize()[0] / 4
                # but be careful at the end of the list
                if addoffset + scrolloffset < self.GetSize()[0]:
                    offset += addoffset

                self.ScrollList(offset, 0)
                scrolloffset = self.GetScrollPos(wx.HORIZONTAL)
            else:
                # Since we can not programmatically scroll the ListCtrl
                # close the editor so the user can scroll and open the editor
                # again
                self.editor.SetValue(self.GetItem(row, col).GetText())
                self.curRow = row
                self.curCol = col
                self.CloseEditor()
                return

        y0 = self.GetItemRect(row)[1]

        editor = self.editor
        editor.SetDimensions(x0 - scrolloffset, y0, x1, -1)

        editor.SetValue(self.GetItem(row, col).GetText())
        editor.Show()
        editor.Raise()
        editor.SetSelection(-1, -1)
        editor.SetFocus()

        self.curRow = row
        self.curCol = col
Beispiel #18
0
def click_combobox_ctrl(ctrl, idx):
    ctrl.SetSelection(idx)
    evt = wx.ListEvent(wx.EVT_COMBOBOX.typeId)
    evt.SetEventObject(ctrl)
    evt.SetId(ctrl.GetId())
    ctrl.GetEventHandler().ProcessEvent(evt)
Beispiel #19
0
def click_multi_list_ctrl(ctrl, objs):
    ctrl.SelectObjects(objs)
    evt = wx.ListEvent(wx.EVT_LIST_ITEM_ACTIVATED.typeId)
    evt.SetEventObject(ctrl)
    evt.SetId(ctrl.GetId())
    ctrl.GetEventHandler().ProcessEvent(evt)
Beispiel #20
0
	def sendListItemFocusedEvent(self, index):
		evt = wx.ListEvent(wx.wxEVT_LIST_ITEM_FOCUSED, self.Id)
		evt.EventObject = self
		evt.Index = index
		self.ProcessEvent(evt)
Beispiel #21
0
 def __OnLeftDown(self, event):
     evt = wx.ListEvent(wx.EVT_LIST_ITEM_SELECTED.typeId, self.GetId())
     evt.SetEventObject(self)
     self.GetEventHandler().ProcessEvent(evt)
Beispiel #22
0
    def test_match_sort_similarity(self):
        sourcesDir = os.path.abspath(os.path.join(os.path.dirname(__file__), "./data/sources"))
        self.frame.panel.AddSourcesFromDir(sourcesDir)
        choicesDir = os.path.abspath(os.path.join(os.path.dirname(__file__), "./data/choices"))
        self.frame.panel.AddChoicesFromDir(choicesDir)

        for each in self.button_panel.GetChildren():
            if each.GetLabel() == "Best match":
                btn = each
                break

        event = wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, btn.GetId())
        btn.GetEventHandler().ProcessEvent(event)

        lst = self.frame.panel.list_ctrl
        event = wx.ListEvent(wx.wxEVT_LIST_COL_CLICK, lst.GetId())
        event.SetColumn(1)
        lst.GetEventHandler().ProcessEvent(event)

        item = -1
        item = lst.GetNextItem(item)
        self.assertEqual(
            ["Aconit vénéneux.txt", "52", "Aconitum anthora.txt", "Aconitum anthora.txt", "1", "Matched", "True",],
            [lst.GetItemText(item, col) for col in range(0, len(config.default_columns))],
        )
        item = lst.GetNextItem(item)
        self.assertEqual(
            [
                "Volutaire à fleurs tubulées.txt",
                "54",
                "Volutaria tubuliflora.txt",
                "Volutaria tubuliflora.txt",
                "1",
                "Matched",
                "True",
            ],
            [lst.GetItemText(item, col) for col in range(0, len(config.default_columns))],
        )
        item = lst.GetNextItem(item)
        self.assertEqual(
            ["Acanthe à feuilles molles.txt", "70", "Acanthus mollis.txt", "Acanthus mollis.txt", "1", "Matched", "True",],
            [lst.GetItemText(item, col) for col in range(0, len(config.default_columns))],
        )
        item = lst.GetNextItem(item)
        self.assertEqual(
            ["Violette cornue.txt", "71", "Viola cornuta.txt", "Viola cornuta.txt", "1", "Matched", "True",],
            [lst.GetItemText(item, col) for col in range(0, len(config.default_columns))],
        )
        item = lst.GetNextItem(item)
        self.assertEqual(
            ["Acanthe épineuse.txt", "73", "Acanthus spinosus.txt", "Acanthus spinosus.txt", "1", "Matched", "True",],
            [lst.GetItemText(item, col) for col in range(0, len(config.default_columns))],
        )
        item = lst.GetNextItem(item)
        self.assertEqual(
            [
                "Abutilon à feuilles marbrées.txt",
                "86",
                "Abutilon hybridum.txt",
                "Abutilon hybridum.txt",
                "1",
                "Matched",
                "True",
            ],
            [lst.GetItemText(item, col) for col in range(0, len(config.default_columns))],
        )
Beispiel #23
0
 def DeselectItem(self):
     self.selected = False
     self.Refresh()
     event = wx.ListEvent(wx.wxEVT_LIST_ITEM_DESELECTED)
     event.SetEventObject(self)
     wx.PostEvent(self, event)
Beispiel #24
0
    def test_loadsave(self):
        if os.path.exists(self.outdir):
            shutil.rmtree(self.outdir)
        os.makedirs(self.outdir)
        sourcesDir = os.path.abspath(
            os.path.join(os.path.dirname(__file__), "./data/sources"))
        self.frame.panel.AddSourcesFromDir(sourcesDir)
        choicesDir = os.path.abspath(
            os.path.join(os.path.dirname(__file__), "./data/choices"))
        self.frame.panel.AddChoicesFromDir(choicesDir)

        for each in self.button_panel.GetChildren():
            if each.GetLabel() == "Best match":
                btn = each
                break

        event = wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, btn.GetId())
        btn.GetEventHandler().ProcessEvent(event)

        lst = self.frame.panel.list_ctrl
        item = -1
        item = lst.GetNextItem(item)

        def Pick():
            for dlg in lst.GetChildren():
                if isinstance(dlg, main_listctrl.PickCandidate):
                    dlg.text.SetValue("volutaria tubuliflora")
                    event = wx.CommandEvent(wx.wxEVT_TEXT_ENTER,
                                            dlg.text.GetId())
                    dlg.text.GetEventHandler().ProcessEvent(event)

        lst.Select(item)
        event = wx.KeyEvent(wx.wxEVT_CHAR)
        event.SetKeyCode(wx.WXK_CONTROL_P)
        wx.CallAfter(Pick)
        lst.GetEventHandler().ProcessEvent(event)
        lst.Select(item, 0)

        item1 = lst.GetNextItem(item)
        lst.Select(item1)
        item2 = lst.GetNextItem(item1)
        lst.Select(item2)
        event = wx.KeyEvent(wx.wxEVT_CHAR)
        event.SetKeyCode(wx.WXK_CONTROL_R)
        lst.GetEventHandler().ProcessEvent(event)
        lst.Select(item1, 0)
        lst.Select(item2, 0)

        item = lst.GetNextItem(item2)
        lst.CheckItem(item, False)

        sessionFile = os.path.abspath(
            os.path.join(self.outdir, "./session.sav"))
        self.frame.SaveSession(sessionFile)

        for each in self.button_panel.GetChildren():
            if each.GetLabel() == "Reset":
                btn = each
                break

        event = wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, btn.GetId())
        btn.GetEventHandler().ProcessEvent(event)

        self.frame.LoadSession(sessionFile)

        lst = self.frame.panel.list_ctrl
        event = wx.ListEvent(wx.wxEVT_LIST_COL_CLICK, lst.GetId())
        event.SetColumn(3)
        lst.GetEventHandler().ProcessEvent(event)

        item = -1
        item = lst.GetNextItem(item)
        self.assertEqual(
            ["Acanthe à feuilles molles.txt", "", "", "", "", "", "True"],
            [
                lst.GetItemText(item, col)
                for col in range(0, len(config.default_columns))
            ],
        )
        item = lst.GetNextItem(item)
        self.assertEqual(
            ["Acanthe épineuse.txt", "", "", "", "", "", "True"],
            [
                lst.GetItemText(item, col)
                for col in range(0, len(config.default_columns))
            ],
        )
        item = lst.GetNextItem(item)
        self.assertEqual(
            [
                "Abutilon à feuilles marbrées.txt",
                "86",
                "Abutilon hybridum.txt",
                "Abutilon hybridum.txt",
                "1",
                "Matched",
                "True",
            ],
            [
                lst.GetItemText(item, col)
                for col in range(0, len(config.default_columns))
            ],
        )
        item = lst.GetNextItem(item)
        self.assertEqual(
            [
                "Aconit vénéneux.txt",
                "52",
                "Aconitum anthora.txt",
                "Aconitum anthora.txt",
                "1",
                "Matched",
                "False",
            ],
            [
                lst.GetItemText(item, col)
                for col in range(0, len(config.default_columns))
            ],
        )
        item = lst.GetNextItem(item)
        self.assertEqual(
            [
                "Violette cornue.txt",
                "71",
                "Viola cornuta.txt",
                "Viola cornuta.txt",
                "1",
                "Matched",
                "True",
            ],
            [
                lst.GetItemText(item, col)
                for col in range(0, len(config.default_columns))
            ],
        )
        item = lst.GetNextItem(item)
        self.assertEqual(
            [
                "Volutaire à fleurs tubulées.txt",
                "54",
                "Volutaria tubuliflora.txt",
                "Volutaria tubuliflora.txt",
                "1",
                "Matched",
                "True",
            ],
            [
                lst.GetItemText(item, col)
                for col in range(0, len(config.default_columns))
            ],
        )

        shutil.rmtree(self.outdir)
Beispiel #25
0
 def OnMiddleClick(self, _) -> None:
     event = wx.ListEvent(wx.wxEVT_LIST_ITEM_RIGHT_CLICK)
     event.SetEventObject(self)
     wx.PostEvent(self, event)
Beispiel #26
0
 def __OnLeftDown(self, event):  # pylint: disable=unused-argument
     evt = wx.ListEvent(wx.EVT_LIST_ITEM_SELECTED.typeId, self.GetId())
     evt.SetEventObject(self)
     self.GetEventHandler().ProcessEvent(evt)
     if isinstance(event.GetEventObject(), wx.Control):
         event.Skip()
Beispiel #27
0
 def OnClick(self, _) -> None:
     event = wx.ListEvent(wx.wxEVT_LIST_ITEM_SELECTED)
     event.SetEventObject(self)
     wx.PostEvent(self, event)
Beispiel #28
0
 def OnDoubleClick(self, _) -> None:
     event = wx.ListEvent(wx.wxEVT_LIST_ITEM_ACTIVATED)
     event.SetEventObject(self)
     wx.PostEvent(self, event)