예제 #1
0
 def OpenMatchExplorerCb(self, event):
     pathes = []
     selected = utils.get_selected_items(self)
     for row_id in selected:
         pos = self.GetItemData(row_id)  # 0-based unsorted index
         data = self.listdata[pos]
         pathes += data[config.D_MATCHNAME]
     utils.launch_file_explorer(pathes)
예제 #2
0
 def ActivateCb(self, event):
     row_id = event.GetIndex()
     pos = self.list_ctrl.GetItemData(row_id)  # 0-based unsorted index
     key = self.listdata[pos][1]
     row_id0 = self.mlist.FindItem(-1, key)
     if row_id0 != wx.NOT_FOUND:
         selected = utils.get_selected_items(self.mlist)
         self.mlist.Freeze()
         for row_id1 in selected:
             self.mlist.Select(row_id1, 0)
         self.mlist.Thaw()
         self.mlist.Select(row_id0)
         self.mlist.EnsureVisible(row_id0)
예제 #3
0
    def ReMatchSelectionCb(self, event):
        selected = utils.get_selected_items(self)

        sources = []
        for row_id in selected:
            pos = self.GetItemData(row_id)  # 0-based unsorted index
            sources.append(self.listdata[pos][config.D_FILENAME])

        matches = match.get_matches(sources)

        Qview_fullpath = get_config()["show_fullpath"]
        Qhide_extension = get_config()["hide_extension"]
        count = 0
        self.Freeze()
        for row_id in selected:
            if len(matches) < count + 1:
                break
            f = self.GetItemFont(row_id)
            if not f.IsOk():
                f = self.list_ctrl.GetFont()
            font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
            font.SetWeight(wx.FONTWEIGHT_NORMAL)
            font.SetStyle(f.GetStyle())
            self.SetItemFont(row_id, font)

            if matches[count]:
                matching_results = matches[count][0]["candidates"]
                nb_match = len(matching_results)
                self.RefreshItem(
                    row_id,
                    score=matches[count][0]["score"],
                    matchnames=matching_results,
                    nbmatch=nb_match,
                    status=config.MatchStatus.MATCH,
                    Qview_fullpath=Qview_fullpath,
                    Qhide_extension=Qhide_extension,
                )
            else:
                self.RefreshItem(
                    row_id,
                    score=0,
                    matchnames=[],
                    nbmatch=0,
                    status=config.MatchStatus.NOMATCH,
                    Qview_fullpath=Qview_fullpath,
                    Qhide_extension=Qhide_extension,
                )
            count += 1
        self.Thaw()
예제 #4
0
    def DeleteCb(self, event):
        selected = utils.get_selected_items(self)

        selected.reverse()  # Delete all the items, starting with the last item
        for row_id in selected:
            self.DeleteItem(row_id)

        # renumbering
        row_id = -1
        while 1:
            row_id = self.GetNextItem(row_id)
            if row_id == -1:
                break
            self.SetItemText(row_id, "%2d" % (int(row_id) + 1))
        self.panel.UpdateFilterPreview()
예제 #5
0
    def DeleteSelectionCb(self, event):
        selected = utils.get_selected_items(self)

        selected.reverse()  # Delete all the items + source file, starting with the last item
        self.Freeze()
        for row_id in selected:
            pos = self.GetItemData(row_id)  # 0-based unsorted index
            for f in self.listdata[pos][config.D_FILENAME]:
                if f.is_file():
                    fpath = str(f)
                    try:
                        os.remove(fpath)
                        wx.LogMessage("Deleting : %s" % (fpath))
                    except (OSError, IOError):
                        wx.LogMessage("Error when deleting : %s" % (fpath))
            self.DeleteItem(row_id)
            del self.listdata[pos]
            key = self.listdatanameinv[pos]
            del self.listdatanameinv[pos]
            del self.listdataname[key]
        self.Thaw()
예제 #6
0
    def ActivateCb(self, event):
        row_id = event.GetIndex()
        pos = self.list_ctrl.GetItemData(row_id)  # 0-based unsorted index
        keys = self.listdata[pos][1]

        row_id0 = []
        for key in keys:
            idx = self.mlist.FindItem(-1, key)
            if idx != wx.NOT_FOUND:
                row_id0.append(idx)
        selected = utils.get_selected_items(self.mlist)
        self.mlist.Freeze()
        for row_id1 in selected:
            self.mlist.Select(row_id1, 0)
        self.mlist.Thaw()
        first = True
        for r in row_id0:
            self.mlist.Select(r)
            if first:
                self.mlist.EnsureVisible(r)
                first = False
예제 #7
0
 def NoMatchSelectionCb(self, event):
     Qview_fullpath = get_config()["show_fullpath"]
     Qhide_extension = get_config()["hide_extension"]
     selected = utils.get_selected_items(self)
     self.Freeze()
     for row_id in selected:
         self.RefreshItem(
             row_id,
             score=0,
             matchnames=[],
             nbmatch=0,
             status=config.MatchStatus.NONE,
             Qview_fullpath=Qview_fullpath,
             Qhide_extension=Qhide_extension,
         )
         f = self.GetItemFont(row_id)
         if not f.IsOk():
             f = self.list_ctrl.GetFont()
         font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
         font.SetWeight(wx.FONTWEIGHT_NORMAL)
         font.SetStyle(f.GetStyle())
         self.SetItemFont(row_id, font)
     self.Thaw()
예제 #8
0
    def onKeyPress(self, event):
        keycode = event.GetKeyCode()
        if keycode == wx.WXK_SPACE:
            if self.GetSelectedItemCount() > 1:
                selected = utils.get_selected_items(self)
                focused = utils.get_focused_items(self)
                check = (
                    not self.IsItemChecked(selected[0]) if (not selected[0] in focused) else self.IsItemChecked(selected[0])
                )
                for index in selected:
                    #self.Focus(index)
                    if not index in focused:
                        self.CheckItem(index, check)
                for index in focused:
                    if not index in selected:
                        self.CheckItem(index, not check)
                event.Skip()
            elif self.GetSelectedItemCount() == 1:
                # Select next item
                row_id = self.GetFirstSelected()
                self.CheckItem(row_id, self.IsItemChecked(row_id))
                self.Select(row_id, on=False)
                self.Select(row_id + 1, on=True)
                self.Focus(row_id + 1)
                self.EnsureVisible(row_id + 1)
        elif keycode == wx.WXK_F2:
            if self.GetSelectedItemCount() == 1:
                index = self.GetFirstSelected()
                self.EditLabel(index)
            event.Skip()
        elif keycode == wx.WXK_CONTROL_A:
            self.Freeze()
            item = -1
            while 1:
                item = self.GetNextItem(item)
                if item == -1:
                    break
                self.SetItemState(item, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED)
            self.Thaw()
            event.Skip()
        elif keycode == wx.WXK_DELETE:
            if event.GetModifiers() == wx.MOD_SHIFT:
                self.DeleteSelectionCb(None)
            else:
                selected = utils.get_selected_items(self)

                selected.reverse()  # Delete all the items, starting with the last item
                self.Freeze()
                for row_id in selected:
                    pos = self.GetItemData(row_id)  # 0-based unsorted index
                    self.DeleteItem(row_id)
                    del self.listdata[pos]
                    key = self.listdatanameinv[pos]
                    del self.listdatanameinv[pos]
                    del self.listdataname[key]
                self.Thaw()
            event.Skip()
        elif keycode == wx.WXK_CONTROL_V:
            files = utils.ClipBoardFiles()
            if files:
                dlg = wx.GenericMessageDialog(
                    self.GetParent().GetParent(),
                    "Add the files to source or choice list?",
                    "Paste question",
                    wx.YES_NO | wx.ICON_QUESTION,
                )
                dlg.SetYesNoLabels("Sources", "Choices")
                Qsources = dlg.ShowModal() == wx.ID_YES
                dlg.Destroy()
                if Qsources:
                    self.GetParent().GetParent().GetParent().AddSourcesFromFiles(files)
                else:
                    self.GetParent().GetParent().GetParent().AddChoicesFromFiles(files)
            event.Skip()
        elif keycode == wx.WXK_CONTROL_P:
            if self.GetSelectedItemCount() == 1:
                row_id = self.GetFirstSelected()
                pos_column_match = 0
                for i in self.GetColumnsOrder() if self.HasColumnOrderSupport() else range(0, len(config.default_columns)):
                    if i == 2:
                        break
                    pos_column_match += self.GetColumnWidth(i)
                rect = self.GetItemRect(row_id)
                position = self.ClientToScreen(rect.GetPosition())
                dia = PickCandidate(self, row_id, wx.Point(position.x + pos_column_match, position.y), selectNextOnClose=True)
                dia.Show()
                dia.text.SetFocus()
        elif keycode == wx.WXK_CONTROL_R:
            self.NoMatchSelectionCb(None)
            if self.GetSelectedItemCount() == 1:
                # Select next item
                row_id = self.GetFirstSelected()
                self.Select(row_id, on=False)
                self.Select(row_id + 1, on=True)
                self.Focus(row_id + 1)
                self.EnsureVisible(row_id + 1)
            event.Skip()
        elif keycode == wx.WXK_CONTROL_B:
            self.ReMatchSelectionCb(None)
            if self.GetSelectedItemCount() == 1:
                # Select next item
                row_id = self.GetFirstSelected()
                self.Select(row_id, on=False)
                self.Select(row_id + 1, on=True)
                self.Focus(row_id + 1)
                self.EnsureVisible(row_id + 1)
            event.Skip()
        elif keycode == wx.WXK_RETURN:
            selected = utils.get_selected_items(self)
            for row_id in selected:
                pos = self.GetItemData(row_id)  # 0-based unsorted index
                data = self.listdata[pos]
                filename_path = data[config.D_FILENAME]
                utils.open_file(str(filename_path[0]))
            event.Skip()
        elif keycode:
            event.Skip()