|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing utility functions for the code style checker dialogs. |
|
8 """ |
|
9 |
|
10 import UI.PixmapCache |
|
11 |
|
12 |
|
13 def setItemIcon(itm, column, msgCode, severity=None): |
|
14 """ |
|
15 Function to set the icon of the passed message item. |
|
16 |
|
17 @param itm reference to the message item |
|
18 @type QTreeWidgetItem |
|
19 @param column column for the icon |
|
20 @type int |
|
21 @param msgCode message code |
|
22 @type str |
|
23 @param severity severity for message code 'S' (defaults to None) |
|
24 @type str (optional) |
|
25 """ |
|
26 if msgCode.startswith(("W", "-", "C", "M")): |
|
27 itm.setIcon(column, UI.PixmapCache.getIcon("warning")) |
|
28 elif msgCode.startswith("E"): |
|
29 itm.setIcon(column, UI.PixmapCache.getIcon("syntaxError")) |
|
30 elif msgCode.startswith(("A", "N")): |
|
31 itm.setIcon(column, UI.PixmapCache.getIcon("namingError")) |
|
32 elif msgCode.startswith("D"): |
|
33 itm.setIcon(column, UI.PixmapCache.getIcon("docstringError")) |
|
34 elif msgCode.startswith("I"): |
|
35 itm.setIcon(column, UI.PixmapCache.getIcon("imports")) |
|
36 elif msgCode.startswith("P"): |
|
37 itm.setIcon(column, UI.PixmapCache.getIcon("dirClosed")) |
|
38 elif msgCode.startswith("Y"): |
|
39 itm.setIcon(column, UI.PixmapCache.getIcon("filePython")) |
|
40 elif msgCode.startswith("S"): |
|
41 if severity is None: |
|
42 itm.setIcon(column, UI.PixmapCache.getIcon("securityLow")) |
|
43 else: |
|
44 if severity == "H": |
|
45 itm.setIcon(column, UI.PixmapCache.getIcon("securityLow")) |
|
46 elif severity == "M": |
|
47 itm.setIcon(column, UI.PixmapCache.getIcon("securityMedium")) |
|
48 elif severity == "L": |
|
49 itm.setIcon(column, UI.PixmapCache.getIcon("securityHigh")) |
|
50 else: |
|
51 itm.setIcon(column, UI.PixmapCache.getIcon("securityLow")) |
|
52 else: |
|
53 # unknown category prefix => warning |
|
54 itm.setIcon(column, UI.PixmapCache.getIcon("warning")) |