|
79 | 79 | if not cfile: |
80 | 80 | cfile = "" |
81 | 81 |
|
| 82 | +class VSCodeIconProvider(QFileIconProvider): |
| 83 | + def __init__(self): |
| 84 | + super().__init__() |
| 85 | + self.icon_cache = {} |
| 86 | + |
| 87 | + def icon(self, file_info): |
| 88 | + if isinstance(file_info, QFileIconProvider.IconType): |
| 89 | + return super().icon(file_info) |
| 90 | + |
| 91 | + path = file_info.absoluteFilePath() |
| 92 | + is_dir = file_info.isDir() |
| 93 | + |
| 94 | + cache_key = (path, is_dir) |
| 95 | + if cache_key in self.icon_cache: |
| 96 | + return self.icon_cache[cache_key] |
| 97 | + |
| 98 | + icon = self._create_icon(file_info, is_dir) |
| 99 | + self.icon_cache[cache_key] = icon |
| 100 | + return icon |
| 101 | + |
| 102 | + def _create_icon(self, file_info, is_dir): |
| 103 | + if is_dir: |
| 104 | + return self._draw_folder_icon() |
| 105 | + else: |
| 106 | + ext = file_info.suffix().lower() |
| 107 | + if ext == "py": |
| 108 | + return self._draw_python_icon() |
| 109 | + elif ext == "json": |
| 110 | + return self._draw_json_icon() |
| 111 | + elif ext in ("db", "sqlite", "sqlite3"): |
| 112 | + return self._draw_db_icon() |
| 113 | + elif ext in ("txt", "log", "md", "qss", "css", "html", "js", "ts"): |
| 114 | + return self._draw_text_icon() |
| 115 | + else: |
| 116 | + return self._draw_default_file_icon() |
| 117 | + |
| 118 | + def _draw_folder_icon(self): |
| 119 | + pixmap = QPixmap(16, 16) |
| 120 | + pixmap.fill(Qt.GlobalColor.transparent) |
| 121 | + painter = QPainter(pixmap) |
| 122 | + painter.setRenderHint(QPainter.RenderHint.Antialiasing) |
| 123 | + |
| 124 | + # Draw outline folder |
| 125 | + pen = QPen(QColor("#70a5eb"), 1.2) |
| 126 | + painter.setPen(pen) |
| 127 | + painter.setBrush(QBrush(QColor(112, 165, 235, 30))) # semi-transparent blue |
| 128 | + |
| 129 | + # Folder tab |
| 130 | + painter.drawRoundedRect(2, 2, 5, 3, 1, 1) |
| 131 | + # Folder body |
| 132 | + painter.drawRoundedRect(2, 4, 12, 9, 1.2, 1.2) |
| 133 | + |
| 134 | + painter.end() |
| 135 | + return QIcon(pixmap) |
| 136 | + |
| 137 | + def _draw_python_icon(self): |
| 138 | + pixmap = QPixmap(16, 16) |
| 139 | + pixmap.fill(Qt.GlobalColor.transparent) |
| 140 | + painter = QPainter(pixmap) |
| 141 | + painter.setRenderHint(QPainter.RenderHint.Antialiasing) |
| 142 | + |
| 143 | + # Python-like snake shapes |
| 144 | + painter.setPen(Qt.PenStyle.NoPen) |
| 145 | + |
| 146 | + # Blue snake |
| 147 | + painter.setBrush(QBrush(QColor("#3572A5"))) |
| 148 | + painter.drawRoundedRect(3, 2, 7, 5, 2, 2) |
| 149 | + painter.drawRoundedRect(5, 5, 5, 4, 2, 2) |
| 150 | + |
| 151 | + # Yellow/Green snake |
| 152 | + painter.setBrush(QBrush(QColor("#FFD43B"))) |
| 153 | + painter.drawRoundedRect(6, 9, 7, 5, 2, 2) |
| 154 | + painter.drawRoundedRect(6, 7, 5, 4, 2, 2) |
| 155 | + |
| 156 | + # Eyes |
| 157 | + painter.setBrush(QBrush(QColor("#ffffff"))) |
| 158 | + painter.drawEllipse(5, 3, 1, 1) |
| 159 | + painter.drawEllipse(10, 12, 1, 1) |
| 160 | + |
| 161 | + painter.end() |
| 162 | + return QIcon(pixmap) |
| 163 | + |
| 164 | + def _draw_json_icon(self): |
| 165 | + pixmap = QPixmap(16, 16) |
| 166 | + pixmap.fill(Qt.GlobalColor.transparent) |
| 167 | + painter = QPainter(pixmap) |
| 168 | + painter.setRenderHint(QPainter.RenderHint.Antialiasing) |
| 169 | + |
| 170 | + # Yellow curly braces |
| 171 | + painter.setPen(QColor("#fbc02d")) |
| 172 | + font = painter.font() |
| 173 | + font.setPixelSize(12) |
| 174 | + font.setBold(True) |
| 175 | + painter.setFont(font) |
| 176 | + painter.drawText(1, 12, "{ }") |
| 177 | + |
| 178 | + painter.end() |
| 179 | + return QIcon(pixmap) |
| 180 | + |
| 181 | + def _draw_db_icon(self): |
| 182 | + pixmap = QPixmap(16, 16) |
| 183 | + pixmap.fill(Qt.GlobalColor.transparent) |
| 184 | + painter = QPainter(pixmap) |
| 185 | + painter.setRenderHint(QPainter.RenderHint.Antialiasing) |
| 186 | + |
| 187 | + color = QColor("#ec407a") |
| 188 | + painter.setPen(QPen(color, 1.2)) |
| 189 | + painter.setBrush(QBrush(QColor(236, 64, 122, 20))) |
| 190 | + |
| 191 | + # Stacked ellipses |
| 192 | + painter.drawEllipse(3, 2, 10, 4) |
| 193 | + painter.drawEllipse(3, 6, 10, 4) |
| 194 | + painter.drawEllipse(3, 10, 10, 4) |
| 195 | + |
| 196 | + # Side lines |
| 197 | + painter.drawLine(3, 4, 3, 12) |
| 198 | + painter.drawLine(13, 4, 13, 12) |
| 199 | + |
| 200 | + painter.end() |
| 201 | + return QIcon(pixmap) |
| 202 | + |
| 203 | + def _draw_text_icon(self): |
| 204 | + pixmap = QPixmap(16, 16) |
| 205 | + pixmap.fill(Qt.GlobalColor.transparent) |
| 206 | + painter = QPainter(pixmap) |
| 207 | + painter.setRenderHint(QPainter.RenderHint.Antialiasing) |
| 208 | + |
| 209 | + painter.setPen(QPen(QColor("#90a4ae"), 1.2)) |
| 210 | + painter.setBrush(QBrush(QColor(144, 164, 174, 20))) |
| 211 | + |
| 212 | + painter.drawRect(3, 2, 10, 12) |
| 213 | + |
| 214 | + painter.setPen(QPen(QColor("#90a4ae"), 1)) |
| 215 | + painter.drawLine(5, 5, 11, 5) |
| 216 | + painter.drawLine(5, 8, 11, 8) |
| 217 | + painter.drawLine(5, 11, 9, 11) |
| 218 | + |
| 219 | + painter.end() |
| 220 | + return QIcon(pixmap) |
| 221 | + |
| 222 | + def _draw_default_file_icon(self): |
| 223 | + pixmap = QPixmap(16, 16) |
| 224 | + pixmap.fill(Qt.GlobalColor.transparent) |
| 225 | + painter = QPainter(pixmap) |
| 226 | + painter.setRenderHint(QPainter.RenderHint.Antialiasing) |
| 227 | + |
| 228 | + painter.setPen(QPen(QColor("#aaaaaa"), 1.2)) |
| 229 | + painter.setBrush(Qt.BrushStyle.NoBrush) |
| 230 | + painter.drawRect(4, 2, 8, 12) |
| 231 | + |
| 232 | + painter.end() |
| 233 | + return QIcon(pixmap) |
| 234 | + |
| 235 | + |
| 236 | +from PyQt6.QtCore import QSortFilterProxyModel |
| 237 | + |
| 238 | +class RootFolderFilterProxyModel(QSortFilterProxyModel): |
| 239 | + def __init__(self, root_path, parent=None): |
| 240 | + super().__init__(parent) |
| 241 | + self.set_root_path(root_path) |
| 242 | + |
| 243 | + def set_root_path(self, root_path): |
| 244 | + self.root_path = os.path.abspath(root_path) |
| 245 | + self.parent_path = os.path.dirname(self.root_path) |
| 246 | + self.invalidateFilter() |
| 247 | + |
| 248 | + def filterAcceptsRow(self, source_row, source_parent): |
| 249 | + source_model = self.sourceModel() |
| 250 | + if not source_model: |
| 251 | + return True |
| 252 | + |
| 253 | + parent_path = os.path.abspath(source_model.filePath(source_parent)) |
| 254 | + file_info = source_model.fileInfo(source_model.index(source_row, 0, source_parent)) |
| 255 | + file_path = os.path.abspath(file_info.absoluteFilePath()) |
| 256 | + |
| 257 | + if parent_path == self.parent_path: |
| 258 | + return file_path == self.root_path |
| 259 | + |
| 260 | + if file_path == self.root_path: |
| 261 | + return True |
| 262 | + if file_path.startswith(self.root_path + os.sep) or file_path.startswith(self.root_path.replace('/', '\\') + '\\'): |
| 263 | + return True |
| 264 | + |
| 265 | + return False |
| 266 | + |
| 267 | + |
82 | 268 | class Sidebar(QDockWidget): |
83 | 269 | def __init__(self, title, parent=None): |
84 | 270 | super().__init__(title, parent) |
@@ -1155,190 +1341,7 @@ def handle_sidebar_button_click(self, button, action): |
1155 | 1341 | # Execute the original action |
1156 | 1342 | action() |
1157 | 1343 |
|
1158 | | -class VSCodeIconProvider(QFileIconProvider): |
1159 | | - def __init__(self): |
1160 | | - super().__init__() |
1161 | | - self.icon_cache = {} |
1162 | | - |
1163 | | - def icon(self, file_info): |
1164 | | - if isinstance(file_info, QFileIconProvider.IconType): |
1165 | | - return super().icon(file_info) |
1166 | | - |
1167 | | - path = file_info.absoluteFilePath() |
1168 | | - is_dir = file_info.isDir() |
1169 | | - |
1170 | | - cache_key = (path, is_dir) |
1171 | | - if cache_key in self.icon_cache: |
1172 | | - return self.icon_cache[cache_key] |
1173 | | - |
1174 | | - icon = self._create_icon(file_info, is_dir) |
1175 | | - self.icon_cache[cache_key] = icon |
1176 | | - return icon |
1177 | | - |
1178 | | - def _create_icon(self, file_info, is_dir): |
1179 | | - if is_dir: |
1180 | | - return self._draw_folder_icon() |
1181 | | - else: |
1182 | | - ext = file_info.suffix().lower() |
1183 | | - if ext == "py": |
1184 | | - return self._draw_python_icon() |
1185 | | - elif ext == "json": |
1186 | | - return self._draw_json_icon() |
1187 | | - elif ext in ("db", "sqlite", "sqlite3"): |
1188 | | - return self._draw_db_icon() |
1189 | | - elif ext in ("txt", "log", "md", "qss", "css", "html", "js", "ts"): |
1190 | | - return self._draw_text_icon() |
1191 | | - else: |
1192 | | - return self._draw_default_file_icon() |
1193 | | - |
1194 | | - def _draw_folder_icon(self): |
1195 | | - pixmap = QPixmap(16, 16) |
1196 | | - pixmap.fill(Qt.GlobalColor.transparent) |
1197 | | - painter = QPainter(pixmap) |
1198 | | - painter.setRenderHint(QPainter.RenderHint.Antialiasing) |
1199 | | - |
1200 | | - # Draw outline folder |
1201 | | - pen = QPen(QColor("#70a5eb"), 1.2) |
1202 | | - painter.setPen(pen) |
1203 | | - painter.setBrush(QBrush(QColor(112, 165, 235, 30))) # semi-transparent blue |
1204 | | - |
1205 | | - # Folder tab |
1206 | | - painter.drawRoundedRect(2, 2, 5, 3, 1, 1) |
1207 | | - # Folder body |
1208 | | - painter.drawRoundedRect(2, 4, 12, 9, 1.2, 1.2) |
1209 | | - |
1210 | | - painter.end() |
1211 | | - return QIcon(pixmap) |
1212 | | - |
1213 | | - def _draw_python_icon(self): |
1214 | | - pixmap = QPixmap(16, 16) |
1215 | | - pixmap.fill(Qt.GlobalColor.transparent) |
1216 | | - painter = QPainter(pixmap) |
1217 | | - painter.setRenderHint(QPainter.RenderHint.Antialiasing) |
1218 | | - |
1219 | | - # Python-like snake shapes |
1220 | | - painter.setPen(Qt.PenStyle.NoPen) |
1221 | | - |
1222 | | - # Blue snake |
1223 | | - painter.setBrush(QBrush(QColor("#3572A5"))) |
1224 | | - painter.drawRoundedRect(3, 2, 7, 5, 2, 2) |
1225 | | - painter.drawRoundedRect(5, 5, 5, 4, 2, 2) |
1226 | | - |
1227 | | - # Yellow/Green snake |
1228 | | - painter.setBrush(QBrush(QColor("#FFD43B"))) |
1229 | | - painter.drawRoundedRect(6, 9, 7, 5, 2, 2) |
1230 | | - painter.drawRoundedRect(6, 7, 5, 4, 2, 2) |
1231 | | - |
1232 | | - # Eyes |
1233 | | - painter.setBrush(QBrush(QColor("#ffffff"))) |
1234 | | - painter.drawEllipse(5, 3, 1, 1) |
1235 | | - painter.drawEllipse(10, 12, 1, 1) |
1236 | | - |
1237 | | - painter.end() |
1238 | | - return QIcon(pixmap) |
1239 | | - |
1240 | | - def _draw_json_icon(self): |
1241 | | - pixmap = QPixmap(16, 16) |
1242 | | - pixmap.fill(Qt.GlobalColor.transparent) |
1243 | | - painter = QPainter(pixmap) |
1244 | | - painter.setRenderHint(QPainter.RenderHint.Antialiasing) |
1245 | | - |
1246 | | - # Yellow curly braces |
1247 | | - painter.setPen(QColor("#fbc02d")) |
1248 | | - font = painter.font() |
1249 | | - font.setPixelSize(12) |
1250 | | - font.setBold(True) |
1251 | | - painter.setFont(font) |
1252 | | - painter.drawText(1, 12, "{ }") |
1253 | | - |
1254 | | - painter.end() |
1255 | | - return QIcon(pixmap) |
1256 | | - |
1257 | | - def _draw_db_icon(self): |
1258 | | - pixmap = QPixmap(16, 16) |
1259 | | - pixmap.fill(Qt.GlobalColor.transparent) |
1260 | | - painter = QPainter(pixmap) |
1261 | | - painter.setRenderHint(QPainter.RenderHint.Antialiasing) |
1262 | | - |
1263 | | - color = QColor("#ec407a") |
1264 | | - painter.setPen(QPen(color, 1.2)) |
1265 | | - painter.setBrush(QBrush(QColor(236, 64, 122, 20))) |
1266 | | - |
1267 | | - # Stacked ellipses |
1268 | | - painter.drawEllipse(3, 2, 10, 4) |
1269 | | - painter.drawEllipse(3, 6, 10, 4) |
1270 | | - painter.drawEllipse(3, 10, 10, 4) |
1271 | | - |
1272 | | - # Side lines |
1273 | | - painter.drawLine(3, 4, 3, 12) |
1274 | | - painter.drawLine(13, 4, 13, 12) |
1275 | | - |
1276 | | - painter.end() |
1277 | | - return QIcon(pixmap) |
1278 | | - |
1279 | | - def _draw_text_icon(self): |
1280 | | - pixmap = QPixmap(16, 16) |
1281 | | - pixmap.fill(Qt.GlobalColor.transparent) |
1282 | | - painter = QPainter(pixmap) |
1283 | | - painter.setRenderHint(QPainter.RenderHint.Antialiasing) |
1284 | | - |
1285 | | - painter.setPen(QPen(QColor("#90a4ae"), 1.2)) |
1286 | | - painter.setBrush(QBrush(QColor(144, 164, 174, 20))) |
1287 | | - |
1288 | | - painter.drawRect(3, 2, 10, 12) |
1289 | | - |
1290 | | - painter.setPen(QPen(QColor("#90a4ae"), 1)) |
1291 | | - painter.drawLine(5, 5, 11, 5) |
1292 | | - painter.drawLine(5, 8, 11, 8) |
1293 | | - painter.drawLine(5, 11, 9, 11) |
1294 | | - |
1295 | | - painter.end() |
1296 | | - return QIcon(pixmap) |
1297 | | - |
1298 | | - def _draw_default_file_icon(self): |
1299 | | - pixmap = QPixmap(16, 16) |
1300 | | - pixmap.fill(Qt.GlobalColor.transparent) |
1301 | | - painter = QPainter(pixmap) |
1302 | | - painter.setRenderHint(QPainter.RenderHint.Antialiasing) |
1303 | | - |
1304 | | - painter.setPen(QPen(QColor("#aaaaaa"), 1.2)) |
1305 | | - painter.setBrush(Qt.BrushStyle.NoBrush) |
1306 | | - painter.drawRect(4, 2, 8, 12) |
1307 | | - |
1308 | | - painter.end() |
1309 | | - return QIcon(pixmap) |
1310 | | - |
1311 | | - |
1312 | | -from PyQt6.QtCore import QSortFilterProxyModel |
1313 | | - |
1314 | | -class RootFolderFilterProxyModel(QSortFilterProxyModel): |
1315 | | - def __init__(self, root_path, parent=None): |
1316 | | - super().__init__(parent) |
1317 | | - self.set_root_path(root_path) |
1318 | 1344 |
|
1319 | | - def set_root_path(self, root_path): |
1320 | | - self.root_path = os.path.abspath(root_path) |
1321 | | - self.parent_path = os.path.dirname(self.root_path) |
1322 | | - self.invalidateFilter() |
1323 | | - |
1324 | | - def filterAcceptsRow(self, source_row, source_parent): |
1325 | | - source_model = self.sourceModel() |
1326 | | - if not source_model: |
1327 | | - return True |
1328 | | - |
1329 | | - parent_path = os.path.abspath(source_model.filePath(source_parent)) |
1330 | | - file_info = source_model.fileInfo(source_model.index(source_row, 0, source_parent)) |
1331 | | - file_path = os.path.abspath(file_info.absoluteFilePath()) |
1332 | | - |
1333 | | - if parent_path == self.parent_path: |
1334 | | - return file_path == self.root_path |
1335 | | - |
1336 | | - if file_path == self.root_path: |
1337 | | - return True |
1338 | | - if file_path.startswith(self.root_path + os.sep) or file_path.startswith(self.root_path.replace('/', '\\') + '\\'): |
1339 | | - return True |
1340 | | - |
1341 | | - return False |
1342 | 1345 |
|
1343 | 1346 |
|
1344 | 1347 | def expandSidebar__Explorer(self, project_path=None): |
|
0 commit comments