• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zelazna / nw_bot / 16733416968

04 Aug 2025 08:23PM UTC coverage: 98.557% (+0.2%) from 98.394%
16733416968

push

github

web-flow
Merge pull request #7 from zelazna/ui-improvement

[UI] Add recents files and save as

54 of 54 new or added lines in 4 files covered. (100.0%)

6 existing lines in 2 files now uncovered.

956 of 970 relevant lines covered (98.56%)

0.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.93
/bot/models/command_list.py
1
import logging
1✔
2
import pickle
1✔
3
from typing import Any, List, Sequence
1✔
4

5
from PySide6.QtCore import (
1✔
6
    QAbstractListModel,
7
    QMimeData,
8
    Qt,
9
    QModelIndex,
10
    QPersistentModelIndex,
11
    QByteArray,
12
)
13

14
from bot.core.constants import MIME_TYPE
1✔
15
from bot.models.base_command import BaseCommand
1✔
16

17
Index = QModelIndex | QPersistentModelIndex
1✔
18

19

20
class CommandListModel(QAbstractListModel):
1✔
21
    def __init__(
1✔
22
        self,
23
        commands: list[BaseCommand] | None = None,
24
        *args: Any,
25
        **kwargs: Any,
26
    ):
27
        super().__init__(*args, **kwargs)
1✔
28
        self.commands = commands if commands else []
1✔
29

30
    def data(self, index: Index, role: int = 0) -> str | None:
1✔
31
        if role == Qt.ItemDataRole.DisplayRole:
1✔
32
            command = self.commands[index.row()]
1✔
33
            return repr(command)
1✔
34

35
    def rowCount(self, parent: Index = QModelIndex()) -> int:
1✔
36
        return len(self.commands)
1✔
37

38
    def flags(self, index: Index) -> Qt.ItemFlag:
1✔
39
        flags = super().flags(index)
1✔
40
        if index.isValid():
1✔
41
            flags |= Qt.ItemFlag.ItemIsDragEnabled | Qt.ItemFlag.ItemIsDropEnabled
1✔
42
        return flags
1✔
43

44
    def mimeTypes(self) -> List[str]:
1✔
45
        types = super().mimeTypes()
1✔
46
        types.append(MIME_TYPE)
1✔
47
        return types
1✔
48

49
    def mimeData(self, indexes: Sequence[QModelIndex]) -> QMimeData:
1✔
50
        mimeData = QMimeData()
1✔
51
        data = QByteArray()
1✔
52

53
        for idx in indexes:
1✔
54
            if idx.isValid():
1✔
55
                idx = idx.row()
1✔
56
                data.append(pickle.dumps((idx, self.commands[idx])))
1✔
57

58
        mimeData.setData(MIME_TYPE, data)
1✔
59
        return mimeData
1✔
60

61
    def canDropMimeData(
1✔
62
        self,
63
        data: QMimeData,
64
        action: Qt.DropAction,
65
        row: int,
66
        column: int,
67
        parent: Index,
68
    ) -> bool:
69
        if not data.hasFormat(MIME_TYPE):
1✔
70
            return False
×
71
        if column > 0:
1✔
UNCOV
72
            return False
×
73
        return True
1✔
74

75
    def dropMimeData(
1✔
76
        self,
77
        data: QMimeData,
78
        action: Qt.DropAction,
79
        row: int,
80
        column: int,
81
        parent: Index,
82
    ) -> bool:
83
        if not self.canDropMimeData(data, action, row, column, parent):
1✔
UNCOV
84
            return False
×
85
        if action is Qt.DropAction.IgnoreAction:
1✔
UNCOV
86
            return True
×
87
        if row != -1:
1✔
88
            after_index = row
1✔
89
        elif parent.isValid():
×
90
            after_index = parent.row()
×
91
        else:
92
            after_index = self.rowCount(QModelIndex())
×
93
        before_index, command = pickle.loads(data.data(MIME_TYPE).data())
1✔
94
        
95
        logging.debug(f"Item {command} from idx {before_index} to idx {after_index}")
1✔
96

97
        self.beginResetModel()
1✔
98
        item = self.commands.pop(before_index)
1✔
99
        self.commands.insert(after_index + 1, item)
1✔
100
        self.endResetModel()
1✔
101

102
        return True
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc