@@ -1464,7 +1464,11 @@ def showEvent(self, event: QShowEvent) -> None:
1464
1464
1465
1465
class PackageImporter (MovableFramelessWindow ):
1466
1466
1467
- pendingPackages : dict [str :QTreeWidgetItem ] = []
1467
+ pendingPackages : dict [str :QTreeWidgetItem ] = {}
1468
+ setLoadBarValue = Signal (str )
1469
+ startAnim = Signal (QVariantAnimation )
1470
+ changeBarOrientation = Signal ()
1471
+
1468
1472
1469
1473
def __init__ (self , parent : QWidget | None = ...) -> None :
1470
1474
super ().__init__ (parent )
@@ -1490,6 +1494,43 @@ def __init__(self, parent: QWidget | None = ...) -> None:
1490
1494
self .setWindowTitle ("\x20 " )
1491
1495
self .setMinimumSize (QSize (650 , 400 ))
1492
1496
self .treewidget = TreeWidget (_ ("No packages found" ))
1497
+
1498
+ self .loadingProgressBar = QProgressBar (self )
1499
+ self .loadingProgressBar .setRange (0 , 1000 )
1500
+ self .loadingProgressBar .setValue (0 )
1501
+ self .loadingProgressBar .setFixedHeight (4 )
1502
+ self .loadingProgressBar .setTextVisible (False )
1503
+ self .setLoadBarValue .connect (self .loadingProgressBar .setValue )
1504
+ self .startAnim .connect (lambda anim : anim .start ())
1505
+ self .changeBarOrientation .connect (lambda : self .loadingProgressBar .setInvertedAppearance (not (self .loadingProgressBar .invertedAppearance ())))
1506
+
1507
+ self .leftSlow = QPropertyAnimation (self .loadingProgressBar , b"value" )
1508
+ self .leftSlow .setStartValue (0 )
1509
+ self .leftSlow .setEndValue (1000 )
1510
+ self .leftSlow .setDuration (700 )
1511
+ self .leftSlow .finished .connect (lambda : (self .rightSlow .start (), self .changeBarOrientation .emit ()))
1512
+
1513
+ self .rightSlow = QPropertyAnimation (self .loadingProgressBar , b"value" )
1514
+ self .rightSlow .setStartValue (1000 )
1515
+ self .rightSlow .setEndValue (0 )
1516
+ self .rightSlow .setDuration (700 )
1517
+ self .rightSlow .finished .connect (lambda : (self .leftFast .start (), self .changeBarOrientation .emit ()))
1518
+
1519
+ self .leftFast = QPropertyAnimation (self .loadingProgressBar , b"value" )
1520
+ self .leftFast .setStartValue (0 )
1521
+ self .leftFast .setEndValue (1000 )
1522
+ self .leftFast .setDuration (300 )
1523
+ self .leftFast .finished .connect (lambda : (self .rightFast .start (), self .changeBarOrientation .emit ()))
1524
+
1525
+ self .rightFast = QPropertyAnimation (self .loadingProgressBar , b"value" )
1526
+ self .rightFast .setStartValue (1000 )
1527
+ self .rightFast .setEndValue (0 )
1528
+ self .rightFast .setDuration (300 )
1529
+ self .rightFast .finished .connect (lambda : (self .leftSlow .start (), self .changeBarOrientation .emit ()))
1530
+
1531
+ self .leftSlow .start ()
1532
+
1533
+ self .layout ().addWidget (self .loadingProgressBar )
1493
1534
self .layout ().addWidget (self .treewidget )
1494
1535
self .treewidget .setColumnCount (4 )
1495
1536
self .treewidget .header ().setStretchLastSection (False )
@@ -1521,16 +1562,20 @@ def __init__(self, parent: QWidget | None = ...) -> None:
1521
1562
self .idIcon = QIcon (getMedia ("ID" ))
1522
1563
self .removeIcon = QIcon (getMedia ("menu_uninstall" ))
1523
1564
self .versionIcon = QIcon (getMedia ("version" ))
1565
+
1524
1566
self .showImportUI ()
1525
1567
1526
1568
def showImportUI (self ):
1527
1569
"""
1528
1570
Starts the process of installinf selected packages from a file.
1529
1571
"""
1530
1572
try :
1573
+ self .loadingProgressBar .show ()
1574
+ self .pendingPackages = {}
1531
1575
DISCOVER_SECTION : SoftwareSection = globals .discover
1532
1576
self .treewidget .clear ()
1533
1577
packageList : list [str ] = []
1578
+ self .show ()
1534
1579
file = QFileDialog .getOpenFileName (None , _ ("Select package file" ), filter = "JSON (*.json)" )[0 ]
1535
1580
if file != "" :
1536
1581
f = open (file , "r" )
@@ -1542,18 +1587,13 @@ def showImportUI(self):
1542
1587
packageList .append (pkg ["PackageIdentifier" ])
1543
1588
except KeyError as e :
1544
1589
print ("🟠 Invalid winget section" )
1545
- try :
1546
- packages = contents ["scoop" ]["apps" ]
1547
- for pkg in packages :
1548
- packageList .append (pkg ["Name" ])
1549
- except KeyError as e :
1550
- print ("🟠 Invalid scoop section" )
1551
- try :
1552
- packages = contents ["chocolatey" ]["apps" ]
1553
- for pkg in packages :
1554
- packageList .append (pkg ["Name" ])
1555
- except KeyError as e :
1556
- print ("🟠 Invalid chocolatey section" )
1590
+ for manager in ["chocolatey" , "scoop" , "pip" , "npm" ]:
1591
+ try :
1592
+ packages = contents [manager ]["apps" ]
1593
+ for pkg in packages :
1594
+ packageList .append (pkg ["Name" ])
1595
+ except KeyError as e :
1596
+ print (f"🟠 Invalid { manager } section" )
1557
1597
for packageId in packageList :
1558
1598
item = QTreeWidgetItem ()
1559
1599
unknownIcon = QIcon (getMedia ("question" ))
@@ -1574,8 +1614,11 @@ def showImportUI(self):
1574
1614
item .setDisabled (True )
1575
1615
self .pendingPackages [packageId ] = item
1576
1616
self .treewidget .label .setVisible (self .treewidget .topLevelItemCount () == 0 )
1577
- Thread (target = self .loadDynamicPackages ).Start ()
1578
- self .show ()
1617
+ Thread (target = self .loadDynamicPackages ).start ()
1618
+ self .loadingProgressBar .hide ()
1619
+ else :
1620
+ self .close ()
1621
+ self .loadingProgressBar .hide ()
1579
1622
except Exception as e :
1580
1623
report (e )
1581
1624
@@ -1587,6 +1630,7 @@ def addItemFromPackage(self, package: Package, item: QTreeWidgetItem) -> None:
1587
1630
item .setIcon (0 , self .installIcon )
1588
1631
item .setIcon (1 , self .idIcon )
1589
1632
item .setIcon (2 , self .versionIcon )
1633
+ item .setDisabled (False )
1590
1634
item .setIcon (3 , package .getSourceIcon ())
1591
1635
removeButton = QPushButton ()
1592
1636
removeButton .setIcon (self .removeIcon )
@@ -1597,20 +1641,21 @@ def addItemFromPackage(self, package: Package, item: QTreeWidgetItem) -> None:
1597
1641
def loadDynamicPackages (self ):
1598
1642
DISCOVER_SECTION : SoftwareSection = globals .discover
1599
1643
DISCOVER_SECTION .callInMain .emit (lambda : DISCOVER_SECTION .packageList .setEnabled (False ))
1644
+ DISCOVER_SECTION .callInMain .emit (lambda : self .loadingProgressBar .show ())
1600
1645
for packageId in self .pendingPackages .keys ():
1646
+ print (packageId )
1601
1647
DISCOVER_SECTION .callInMain .emit (lambda : DISCOVER_SECTION .query .setText (packageId ))
1602
- DISCOVER_SECTION .callInMain .emit (lambda : DISCOVER_SECTION .finishFiltering (self .query .text ()))
1648
+ DISCOVER_SECTION .callInMain .emit (lambda : DISCOVER_SECTION .finishFiltering (DISCOVER_SECTION .query .text ()))
1649
+ while not DISCOVER_SECTION .isLoadingDynamic : # Make time before packages actually start loading
1650
+ time .sleep (0.001 )
1603
1651
while DISCOVER_SECTION .isLoadingDynamic :
1604
1652
time .sleep (0.01 )
1605
1653
if packageId in DISCOVER_SECTION .IdPackageReference :
1606
1654
package = DISCOVER_SECTION .IdPackageReference [packageId ]
1607
- self .addItemFromPackage (package , self .pendingPackages [packageId ])
1655
+ DISCOVER_SECTION .callInMain .emit (lambda : self .addItemFromPackage (package , self .pendingPackages [packageId ]))
1656
+ DISCOVER_SECTION .callInMain .emit (lambda : self .treewidget .label .setVisible (self .treewidget .topLevelItemCount () == 0 ))
1657
+ DISCOVER_SECTION .callInMain .emit (lambda : self .loadingProgressBar .hide ())
1608
1658
DISCOVER_SECTION .callInMain .emit (lambda : DISCOVER_SECTION .packageList .setEnabled (True ))
1609
-
1610
-
1611
-
1612
-
1613
-
1614
1659
1615
1660
def installPackages (self ) -> None :
1616
1661
DISCOVER_SECTION : SoftwareSection = globals .discover
0 commit comments