FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
winpython/winpython/controlpanel.py at master · sofibox/winpython · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
sofibox
/
winpython
Public
forked from
winpython/winpython
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
winpython
/
winpython
/
controlpanel.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
987 lines (882 loc) · 32.1 KB
Breadcrumbs
winpython
/
winpython
/
controlpanel.py
Copy path
File metadata and controls
987 lines (882 loc) · 32.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
# -*- coding: utf-8 -*-
#
# Copyright © 2012 Pierre Raybaut
# Licensed under the terms of the MIT License
# (see winpython/__init__.py for details)
"""
WinPython Package Manager GUI
Created on Mon Aug 13 11:40:01 2012
"""
from
pathlib
import
Path
import
os
import
sys
import
platform
import
locale
# winpython.qt becomes winpython._vendor.qtpy
from
winpython
.
_vendor
.
qtpy
.
QtWidgets
import
(
QApplication
,
QMainWindow
,
QWidget
,
QLineEdit
,
QHBoxLayout
,
QVBoxLayout
,
QMessageBox
,
QAbstractItemView
,
QProgressDialog
,
QTableView
,
QPushButton
,
QLabel
,
QTabWidget
,
QToolTip
,
)
from
winpython
.
_vendor
.
qtpy
.
QtGui
import
(
QColor
,
QDesktopServices
,
)
from
winpython
.
_vendor
.
qtpy
.
QtCore
import
(
Qt
,
QAbstractTableModel
,
QModelIndex
,
Signal
,
QThread
,
QTimer
,
QUrl
,
)
from
winpython
.
_vendor
.
qtpy
.
compat
import
(
to_qvariant
,
getopenfilenames
,
getexistingdirectory
,
)
import
winpython
.
_vendor
.
qtpy
from
winpython
.
qthelpers
import
(
get_icon
,
add_actions
,
create_action
,
keybinding
,
get_std_icon
,
action2button
,
mimedata2url
,
)
# Local imports
from
winpython
import
__version__
,
__project_url__
from
winpython
import
wppm
,
associate
,
utils
COLUMNS
=
ACTION
,
CHECK
,
NAME
,
VERSION
,
DESCRIPTION
=
list
(
range
(
5
)
)
class
PackagesModel
(
QAbstractTableModel
):
# Signals after PyQt4 old SIGNAL removal
dataChanged
=
Signal
(
QModelIndex
,
QModelIndex
)
def
__init__
(
self
):
QAbstractTableModel
.
__init__
(
self
)
self
.
packages
=
[]
self
.
checked
=
set
()
self
.
actions
=
{}
def
sortByName
(
self
):
self
.
packages
=
sorted
(
self
.
packages
,
key
=
lambda
x
:
x
.
name
)
self
.
reset
()
def
flags
(
self
,
index
):
if
not
index
.
isValid
():
return
Qt
.
ItemIsEnabled
column
=
index
.
column
()
if
column
in
(
NAME
,
VERSION
,
ACTION
,
DESCRIPTION
):
return
Qt
.
ItemFlags
(
QAbstractTableModel
.
flags
(
self
,
index
)
)
else
:
return
Qt
.
ItemFlags
(
QAbstractTableModel
.
flags
(
self
,
index
)
|
Qt
.
ItemIsUserCheckable
|
Qt
.
ItemIsEditable
)
def
data
(
self
,
index
,
role
=
Qt
.
DisplayRole
):
if
not
index
.
isValid
()
or
not
(
0
<=
index
.
row
()
<
len
(
self
.
packages
)
):
return
to_qvariant
()
package
=
self
.
packages
[
index
.
row
()]
column
=
index
.
column
()
if
role
==
Qt
.
CheckStateRole
and
column
==
CHECK
:
return
int
(
package
in
self
.
checked
)
elif
role
==
Qt
.
DisplayRole
:
if
column
==
NAME
:
return
to_qvariant
(
package
.
name
)
elif
column
==
VERSION
:
return
to_qvariant
(
package
.
version
)
elif
column
==
ACTION
:
action
=
self
.
actions
.
get
(
package
)
if
action
is
not
None
:
return
to_qvariant
(
action
)
elif
column
==
DESCRIPTION
:
return
to_qvariant
(
package
.
description
)
elif
role
==
Qt
.
TextAlignmentRole
:
if
column
==
ACTION
:
return
to_qvariant
(
int
(
Qt
.
AlignRight
|
Qt
.
AlignVCenter
)
)
else
:
return
to_qvariant
(
int
(
Qt
.
AlignLeft
|
Qt
.
AlignVCenter
)
)
elif
role
==
Qt
.
BackgroundColorRole
:
if
package
in
self
.
checked
:
color
=
QColor
(
Qt
.
darkGreen
)
color
.
setAlphaF
(
0.1
)
return
to_qvariant
(
color
)
else
:
color
=
QColor
(
Qt
.
lightGray
)
color
.
setAlphaF
(
0.3
)
return
to_qvariant
(
color
)
return
to_qvariant
()
def
headerData
(
self
,
section
,
orientation
,
role
=
Qt
.
DisplayRole
):
if
role
==
Qt
.
TextAlignmentRole
:
if
orientation
==
Qt
.
Horizontal
:
return
to_qvariant
(
int
(
Qt
.
AlignHCenter
|
Qt
.
AlignVCenter
)
)
return
to_qvariant
(
int
(
Qt
.
AlignRight
|
Qt
.
AlignVCenter
)
)
if
role
!=
Qt
.
DisplayRole
:
return
to_qvariant
()
if
orientation
==
Qt
.
Horizontal
:
if
section
==
NAME
:
return
to_qvariant
(
"Name"
)
elif
section
==
VERSION
:
return
to_qvariant
(
"Version"
)
elif
section
==
ACTION
:
return
to_qvariant
(
"Action"
)
elif
section
==
DESCRIPTION
:
return
to_qvariant
(
"Description"
)
return
to_qvariant
()
def
rowCount
(
self
,
index
=
QModelIndex
()):
return
len
(
self
.
packages
)
def
columnCount
(
self
,
index
=
QModelIndex
()):
return
len
(
COLUMNS
)
def
setData
(
self
,
index
,
value
,
role
=
Qt
.
EditRole
):
if
(
index
.
isValid
()
and
0
<=
index
.
row
()
<
len
(
self
.
packages
)
and
role
==
Qt
.
CheckStateRole
):
package
=
self
.
packages
[
index
.
row
()]
if
package
in
self
.
checked
:
self
.
checked
.
remove
(
package
)
else
:
self
.
checked
.
add
(
package
)
# PyQt4 old SIGNAL: self.emit(SIGNAL("dataChanged(QModelIndex,QModelIndex)"),
# PyQt4 old SIGNAL: index, index)
self
.
dataChanged
.
emit
(
index
,
index
)
return
True
return
False
INSTALL_ACTION
=
'Install'
REPAIR_ACTION
=
'Repair (reinstall)'
NO_REPAIR_ACTION
=
'None (Already installed)'
UPGRADE_ACTION
=
'Upgrade from v'
NONE_ACTION
=
'-'
class
PackagesTable
(
QTableView
):
# Signals after PyQt4 old SIGNAL removal, to be emitted after package_added event
package_added
=
Signal
()
def
__init__
(
self
,
parent
,
process
,
winname
):
QTableView
.
__init__
(
self
,
parent
)
assert
process
in
(
'install'
,
'uninstall'
)
self
.
process
=
process
self
.
model
=
PackagesModel
()
self
.
setModel
(
self
.
model
)
self
.
winname
=
winname
self
.
repair
=
False
self
.
resizeColumnToContents
(
0
)
self
.
setAcceptDrops
(
process
==
'install'
)
if
process
==
'uninstall'
:
self
.
hideColumn
(
0
)
self
.
distribution
=
None
self
.
setSelectionBehavior
(
QAbstractItemView
.
SelectRows
)
self
.
verticalHeader
().
hide
()
self
.
setShowGrid
(
False
)
def
reset_model
(
self
):
# self.model.reset() is deprecated in Qt5
self
.
model
.
beginResetModel
()
self
.
model
.
endResetModel
()
self
.
horizontalHeader
().
setStretchLastSection
(
True
)
for
colnb
in
(
ACTION
,
CHECK
,
NAME
,
VERSION
):
self
.
resizeColumnToContents
(
colnb
)
def
get_selected_packages
(
self
):
"""Return selected packages"""
return
[
pack
for
pack
in
self
.
model
.
packages
if
pack
in
self
.
model
.
checked
]
def
add_packages
(
self
,
fnames
):
"""Add packages"""
notsupported
=
[]
notcompatible
=
[]
dist
=
self
.
distribution
for
fname
in
fnames
:
bname
=
Path
(
fname
).
name
try
:
package
=
wppm
.
Package
(
fname
)
if
package
.
is_compatible_with
(
dist
):
self
.
add_package
(
package
)
else
:
notcompatible
.
append
(
bname
)
except
NotImplementedError
:
notsupported
.
append
(
bname
)
# PyQt4 old SIGNAL: self.emit(SIGNAL('package_added()'))
self
.
package_added
.
emit
()
if
notsupported
:
QMessageBox
.
warning
(
self
,
"Warning"
,
"The following packages filenaming are <b>not "
"recognized</b> by %s:
\n
\n
%s"
%
(
self
.
winname
,
"<br>"
.
join
(
notsupported
)),
QMessageBox
.
Ok
,
)
if
notcompatible
:
QMessageBox
.
warning
(
self
,
"Warning"
,
"The following packages "
"are <b>not compatible</b> with "
"Python <u>%s %dbit</u>:
\n
\n
%s"
%
(
dist
.
version
,
dist
.
architecture
,
"<br>"
.
join
(
notcompatible
),
),
QMessageBox
.
Ok
,
)
def
add_package
(
self
,
package
):
for
pack
in
self
.
model
.
packages
:
if
pack
.
name
==
package
.
name
:
return
self
.
model
.
packages
.
append
(
package
)
self
.
model
.
packages
.
sort
(
key
=
lambda
x
:
x
.
name
)
self
.
model
.
checked
.
add
(
package
)
self
.
reset_model
()
def
remove_package
(
self
,
package
):
self
.
model
.
packages
=
[
pack
for
pack
in
self
.
model
.
packages
if
pack
.
fname
!=
package
.
fname
]
if
package
in
self
.
model
.
checked
:
self
.
model
.
checked
.
remove
(
package
)
if
package
in
self
.
model
.
actions
:
self
.
model
.
actions
.
pop
(
package
)
self
.
reset_model
()
def
refresh_distribution
(
self
,
dist
):
self
.
distribution
=
dist
if
self
.
process
==
'install'
:
for
package
in
self
.
model
.
packages
:
pack
=
dist
.
find_package
(
package
.
name
)
if
pack
is
None
:
action
=
INSTALL_ACTION
elif
pack
.
version
==
package
.
version
:
if
self
.
repair
:
action
=
REPAIR_ACTION
else
:
action
=
NO_REPAIR_ACTION
else
:
action
=
UPGRADE_ACTION
+
pack
.
version
self
.
model
.
actions
[
package
]
=
action
else
:
self
.
model
.
packages
=
(
self
.
distribution
.
get_installed_packages
()
)
for
package
in
self
.
model
.
packages
:
self
.
model
.
actions
[
package
]
=
NONE_ACTION
self
.
reset_model
()
def
select_all
(
self
):
allpk
=
set
(
self
.
model
.
packages
)
if
self
.
model
.
checked
==
allpk
:
self
.
model
.
checked
=
set
()
else
:
self
.
model
.
checked
=
allpk
self
.
model
.
reset
()
def
dragMoveEvent
(
self
,
event
):
"""Reimplement Qt method, just to avoid default drag'n drop
implementation of QTableView to handle events"""
event
.
acceptProposedAction
()
def
dragEnterEvent
(
self
,
event
):
"""Reimplement Qt method
Inform Qt about the types of data that the widget accepts"""
source
=
event
.
mimeData
()
if
source
.
hasUrls
()
and
mimedata2url
(
source
):
event
.
acceptProposedAction
()
def
dropEvent
(
self
,
event
):
"""Reimplement Qt method
Unpack dropped data and handle it"""
source
=
event
.
mimeData
()
fnames
=
[
path
for
path
in
mimedata2url
(
source
)
if
Path
(
path
).
is_file
()
]
self
.
add_packages
(
fnames
)
event
.
acceptProposedAction
()
class
DistributionSelector
(
QWidget
):
"""Python distribution selector widget"""
TITLE
=
'Select a Python distribution path'
# Signals after PyQt4 old SIGNAL removal
selected_distribution
=
Signal
(
str
)
def
__init__
(
self
,
parent
):
super
(
DistributionSelector
,
self
).
__init__
(
parent
)
self
.
browse_btn
=
None
self
.
label
=
None
self
.
line_edit
=
None
self
.
setup_widget
()
def
set_distribution
(
self
,
path
):
"""Set distribution directory"""
self
.
line_edit
.
setText
(
path
)
def
setup_widget
(
self
):
"""Setup workspace selector widget"""
self
.
label
=
QLabel
()
self
.
line_edit
=
QLineEdit
()
self
.
line_edit
.
setAlignment
(
Qt
.
AlignRight
)
self
.
line_edit
.
setReadOnly
(
True
)
# self.line_edit.setDisabled(True)
self
.
browse_btn
=
QPushButton
(
get_std_icon
(
'DirOpenIcon'
),
""
,
self
)
self
.
browse_btn
.
setToolTip
(
self
.
TITLE
)
# PyQt4 old SIGNAL:self.connect(self.browse_btn, SIGNAL("clicked()"),
# PyQt4 old SIGNAL: self.select_directory)
self
.
browse_btn
.
clicked
.
connect
(
self
.
select_directory
)
layout
=
QHBoxLayout
()
layout
.
addWidget
(
self
.
label
)
layout
.
addWidget
(
self
.
line_edit
)
layout
.
addWidget
(
self
.
browse_btn
)
layout
.
setContentsMargins
(
0
,
0
,
0
,
0
)
self
.
setLayout
(
layout
)
def
select_directory
(
self
):
"""Select directory"""
# basedir = to_text_string(self.line_edit.text())
basedir
=
str
(
self
.
line_edit
.
text
())
if
not
Path
(
basedir
).
is_dir
():
basedir
=
str
(
Path
.
cwd
())
# getcwd()
while
True
:
directory
=
getexistingdirectory
(
self
,
self
.
TITLE
,
basedir
)
if
not
directory
:
break
if
not
utils
.
is_python_distribution
(
directory
):
QMessageBox
.
warning
(
self
,
self
.
TITLE
,
"The following directory is not a Python distribution."
,
QMessageBox
.
Ok
,
)
basedir
=
directory
continue
directory
=
str
(
Path
(
directory
).
resolve
(
strict
=
False
))
self
.
set_distribution
(
directory
)
# PyQt4 old SIGNAL: self.emit(SIGNAL('selected_distribution(QString)'), directory)
self
.
selected_distribution
.
emit
(
directory
)
break
class
Thread
(
QThread
):
"""Installation/Uninstallation thread"""
def
__init__
(
self
,
parent
):
QThread
.
__init__
(
self
,
parent
)
self
.
callback
=
None
self
.
error
=
None
def
run
(
self
):
try
:
self
.
callback
()
except
Exception
as
error
:
error_str
=
str
(
error
)
fs_encoding
=
(
sys
.
getfilesystemencoding
()
or
locale
.
getpreferredencoding
()
)
try
:
error_str
=
error_str
.
decode
(
fs_encoding
)
except
(
UnicodeError
,
TypeError
,
AttributeError
,
):
pass
self
.
error
=
error_str
def
python_distribution_infos
():
"""Return Python distribution infos (not selected distribution but
the one used to run this script)"""
winpyver
=
os
.
environ
.
get
(
'WINPYVER'
)
if
winpyver
is
None
:
return
'Unknown Python distribution'
else
:
return
'WinPython '
+
winpyver
class
PMWindow
(
QMainWindow
):
NAME
=
'WinPython Control Panel'
def
__init__
(
self
):
QMainWindow
.
__init__
(
self
)
self
.
setAttribute
(
Qt
.
WA_DeleteOnClose
)
self
.
distribution
=
None
self
.
tabwidget
=
None
self
.
selector
=
None
self
.
table
=
None
self
.
untable
=
None
self
.
basedir
=
None
self
.
select_all_action
=
None
self
.
install_action
=
None
self
.
uninstall_action
=
None
self
.
remove_action
=
None
self
.
packages_icon
=
get_std_icon
(
'FileDialogContentsView'
)
self
.
setup_window
()
def
_add_table
(
self
,
table
,
title
,
icon
):
"""Add table tab to main tab widget, return button layout"""
widget
=
QWidget
()
tabvlayout
=
QVBoxLayout
()
widget
.
setLayout
(
tabvlayout
)
tabvlayout
.
addWidget
(
table
)
btn_layout
=
QHBoxLayout
()
tabvlayout
.
addLayout
(
btn_layout
)
self
.
tabwidget
.
addTab
(
widget
,
icon
,
title
)
return
btn_layout
def
setup_window
(
self
):
"""Setup main window"""
self
.
setWindowTitle
(
self
.
NAME
)
self
.
setWindowIcon
(
get_icon
(
'winpython.svg'
))
self
.
selector
=
DistributionSelector
(
self
)
# PyQt4 old SIGNAL: self.connect(self.selector, SIGNAL('selected_distribution(QString)'),
# PyQt4 old SIGNAL: self.distribution_changed)
self
.
selector
.
selected_distribution
.
connect
(
self
.
distribution_changed
)
self
.
table
=
PackagesTable
(
self
,
'install'
,
self
.
NAME
)
# PyQt4 old SIGNAL:self.connect(self.table, SIGNAL('package_added()'),
# PyQt4 old SIGNAL: self.refresh_install_button)
self
.
table
.
package_added
.
connect
(
self
.
refresh_install_button
)
# PyQt4 old SIGNAL: self.connect(self.table, SIGNAL("clicked(QModelIndex)"),
# PyQt4 old SIGNAL: lambda index: self.refresh_install_button())
self
.
table
.
clicked
.
connect
(
lambda
index
:
self
.
refresh_install_button
()
)
self
.
untable
=
PackagesTable
(
self
,
'uninstall'
,
self
.
NAME
)
# PyQt4 old SIGNAL:self.connect(self.untable, SIGNAL("clicked(QModelIndex)"),
# PyQt4 old SIGNAL: lambda index: self.refresh_uninstall_button())
self
.
untable
.
clicked
.
connect
(
lambda
index
:
self
.
refresh_uninstall_button
()
)
self
.
selector
.
set_distribution
(
sys
.
prefix
)
self
.
distribution_changed
(
sys
.
prefix
)
self
.
tabwidget
=
QTabWidget
()
# PyQt4 old SIGNAL:self.connect(self.tabwidget, SIGNAL('currentChanged(int)'),
# PyQt4 old SIGNAL: self.current_tab_changed)
self
.
tabwidget
.
currentChanged
.
connect
(
self
.
current_tab_changed
)
btn_layout
=
self
.
_add_table
(
self
.
table
,
"Install/upgrade packages"
,
get_std_icon
(
"ArrowDown"
),
)
unbtn_layout
=
self
.
_add_table
(
self
.
untable
,
"Uninstall packages"
,
get_std_icon
(
"DialogResetButton"
),
)
central_widget
=
QWidget
()
vlayout
=
QVBoxLayout
()
vlayout
.
addWidget
(
self
.
selector
)
vlayout
.
addWidget
(
self
.
tabwidget
)
central_widget
.
setLayout
(
vlayout
)
self
.
setCentralWidget
(
central_widget
)
# Install tab
add_action
=
create_action
(
self
,
"&Add packages..."
,
icon
=
get_std_icon
(
'DialogOpenButton'
),
triggered
=
self
.
add_packages
,
)
self
.
remove_action
=
create_action
(
self
,
"Remove"
,
shortcut
=
keybinding
(
'Delete'
),
icon
=
get_std_icon
(
'TrashIcon'
),
triggered
=
self
.
remove_packages
,
)
self
.
remove_action
.
setEnabled
(
False
)
self
.
select_all_action
=
create_action
(
self
,
"(Un)Select all"
,
shortcut
=
keybinding
(
'SelectAll'
),
icon
=
get_std_icon
(
'DialogYesButton'
),
triggered
=
self
.
table
.
select_all
,
)
self
.
install_action
=
create_action
(
self
,
"&Install packages"
,
icon
=
get_std_icon
(
'DialogApplyButton'
),
triggered
=
lambda
:
self
.
process_packages
(
'install'
),
)
self
.
install_action
.
setEnabled
(
False
)
quit_action
=
create_action
(
self
,
"&Quit"
,
icon
=
get_std_icon
(
'DialogCloseButton'
),
triggered
=
self
.
close
,
)
packages_menu
=
self
.
menuBar
().
addMenu
(
"&Packages"
)
add_actions
(
packages_menu
,
[
add_action
,
self
.
remove_action
,
self
.
install_action
,
None
,
quit_action
,
],
)
# Uninstall tab
self
.
uninstall_action
=
create_action
(
self
,
"&Uninstall packages"
,
icon
=
get_std_icon
(
'DialogCancelButton'
),
triggered
=
lambda
:
self
.
process_packages
(
'uninstall'
),
)
self
.
uninstall_action
.
setEnabled
(
False
)
uninstall_btn
=
action2button
(
self
.
uninstall_action
,
autoraise
=
False
,
text_beside_icon
=
True
,
)
# Option menu
option_menu
=
self
.
menuBar
().
addMenu
(
"&Options"
)
repair_action
=
create_action
(
self
,
"Repair packages"
,
tip
=
"Reinstall packages even if version is unchanged"
,
toggled
=
self
.
toggle_repair
,
)
add_actions
(
option_menu
, (
repair_action
,))
# Advanced menu
option_menu
=
self
.
menuBar
().
addMenu
(
"&Advanced"
)
register_action
=
create_action
(
self
,
"Register distribution..."
,
tip
=
"Register file extensions, icons and context menu"
,
triggered
=
self
.
register_distribution
,
)
unregister_action
=
create_action
(
self
,
"Unregister distribution..."
,
tip
=
"Unregister file extensions, icons and context menu"
,
triggered
=
self
.
unregister_distribution
,
)
open_console_action
=
create_action
(
self
,
"Open console here"
,
triggered
=
lambda
:
os
.
startfile
(
self
.
command_prompt_path
),
)
open_console_action
.
setEnabled
(
Path
(
self
.
command_prompt_path
).
exists
()
)
add_actions
(
option_menu
,
(
register_action
,
unregister_action
,
None
,
open_console_action
,
),
)
# # View menu
# view_menu = self.menuBar().addMenu("&View")
# popmenu = self.createPopupMenu()
# add_actions(view_menu, popmenu.actions())
# Help menu
about_action
=
create_action
(
self
,
f"About
{
self
.
NAME
}
..."
,
icon
=
get_std_icon
(
'MessageBoxInformation'
),
triggered
=
self
.
about
,
)
report_action
=
create_action
(
self
,
"Report issue..."
,
icon
=
get_icon
(
'bug.png'
),
triggered
=
self
.
report_issue
,
)
help_menu
=
self
.
menuBar
().
addMenu
(
"?"
)
add_actions
(
help_menu
, [
about_action
,
None
,
report_action
]
)
# Status bar
status
=
self
.
statusBar
()
status
.
setObjectName
(
"StatusBar"
)
status
.
showMessage
(
f"Welcome to
{
self
.
NAME
}
!"
,
5000
)
# Button layouts
for
act
in
(
add_action
,
self
.
remove_action
,
None
,
self
.
select_all_action
,
self
.
install_action
,
):
if
act
is
None
:
btn_layout
.
addStretch
()
else
:
btn_layout
.
addWidget
(
action2button
(
act
,
autoraise
=
False
,
text_beside_icon
=
True
,
)
)
unbtn_layout
.
addWidget
(
uninstall_btn
)
unbtn_layout
.
addStretch
()
self
.
resize
(
400
,
500
)
def
current_tab_changed
(
self
,
index
):
"""Current tab has just changed"""
if
index
==
0
:
self
.
show_drop_tip
()
def
refresh_install_button
(
self
):
"""Refresh install button enable state"""
self
.
table
.
refresh_distribution
(
self
.
distribution
)
self
.
install_action
.
setEnabled
(
len
(
self
.
get_packages_to_be_installed
())
>
0
)
nbp
=
len
(
self
.
table
.
get_selected_packages
())
for
act
in
(
self
.
remove_action
,
self
.
select_all_action
,
):
act
.
setEnabled
(
nbp
>
0
)
self
.
show_drop_tip
()
def
show_drop_tip
(
self
):
"""Show drop tip on install table"""
callback
=
lambda
:
QToolTip
.
showText
(
self
.
table
.
mapToGlobal
(
self
.
table
.
pos
()),
'<b>Drop files here</b><br>'
'Executable installers (distutils) or source packages'
,
self
,
)
QTimer
.
singleShot
(
500
,
callback
)
def
refresh_uninstall_button
(
self
):
"""Refresh uninstall button enable state"""
nbp
=
len
(
self
.
untable
.
get_selected_packages
())
self
.
uninstall_action
.
setEnabled
(
nbp
>
0
)
def
toggle_repair
(
self
,
state
):
"""Toggle repair mode"""
self
.
table
.
repair
=
state
self
.
refresh_install_button
()
def
register_distribution
(
self
):
"""Register distribution"""
answer
=
QMessageBox
.
warning
(
self
,
"Register distribution"
,
"(experimental)
\n
"
"This will associate file extensions, icons and "
"Windows explorer's context menu entries ('Edit with IDLE', ...) "
"with selected Python distribution in Windows registry. "
"
\n
\n
Shortcuts for all WinPython launchers will be installed "
"in WinPython Start menu group (replacing existing "
"shortcuts)."
"
\n
\n
Note: these actions are similar to those performed"
"when installing old Pythons with the official installer before 'py' "
"for Windows.
\n
\n
Do you want to continue? "
,
QMessageBox
.
Yes
|
QMessageBox
.
No
,
)
if
answer
==
QMessageBox
.
Yes
:
associate
.
register
(
self
.
distribution
.
target
)
def
unregister_distribution
(
self
):
"""Unregister distribution"""
answer
=
QMessageBox
.
warning
(
self
,
"Unregister distribution"
,
"(experimental)
\n
"
"This will remove file extensions associations, icons and "
"Windows explorer's context menu entries ('Edit with IDLE', ...) "
"with selected Python distribution in Windows registry. "
"
\n
\n
Shortcuts for all WinPython launchers will be removed "
"from WinPython Start menu group."
"
\n
\n
Do you want to continue? "
,
QMessageBox
.
Yes
|
QMessageBox
.
No
,
)
if
answer
==
QMessageBox
.
Yes
:
associate
.
unregister
(
self
.
distribution
.
target
)
@
property
def
command_prompt_path
(
self
):
return
str
(
Path
(
self
.
distribution
.
target
).
parent
/
"WinPython Command Prompt.exe"
)
def
distribution_changed
(
self
,
path
):
"""Distribution path has just changed"""
for
package
in
self
.
table
.
model
.
packages
:
self
.
table
.
remove_package
(
package
)
# dist = wppm.Distribution(to_text_string(path))
dist
=
wppm
.
Distribution
(
str
(
path
))
self
.
table
.
refresh_distribution
(
dist
)
self
.
untable
.
refresh_distribution
(
dist
)
self
.
distribution
=
dist
self
.
selector
.
label
.
setText
(
f'Python
{
dist
.
version
}
{
dist
.
architecture
}
bit:'
)
def
add_packages
(
self
):
"""Add packages"""
basedir
=
(
self
.
basedir
if
self
.
basedir
is
not
None
else
''
)
fnames
,
_selfilter
=
getopenfilenames
(
parent
=
self
,
basedir
=
basedir
,
caption
=
'Add packages'
,
filters
=
'*.exe *.zip *.tar.gz *.whl'
,
)
if
fnames
:
self
.
basedir
=
str
(
Path
(
fnames
[
0
]).
parent
)
self
.
table
.
add_packages
(
fnames
)
def
get_packages_to_be_installed
(
self
):
"""Return packages to be installed"""
return
[
pack
for
pack
in
self
.
table
.
get_selected_packages
()
if
self
.
table
.
model
.
actions
[
pack
]
not
in
(
NO_REPAIR_ACTION
,
NONE_ACTION
)
]
def
remove_packages
(
self
):
"""Remove selected packages"""
for
package
in
self
.
table
.
get_selected_packages
():
self
.
table
.
remove_package
(
package
)
def
process_packages
(
self
,
action
):
"""Install/uninstall packages"""
if
action
==
'install'
:
text
,
table
=
'Installing'
,
self
.
table
if
not
self
.
get_packages_to_be_installed
():
return
elif
action
==
'uninstall'
:
text
,
table
=
'Uninstalling'
,
self
.
untable
else
:
raise
AssertionError
packages
=
table
.
get_selected_packages
()
if
not
packages
:
return
func
=
getattr
(
self
.
distribution
,
action
)
thread
=
Thread
(
self
)
for
widget
in
self
.
children
():
if
isinstance
(
widget
,
QWidget
):
widget
.
setEnabled
(
False
)
try
:
status
=
self
.
statusBar
()
except
AttributeError
:
status
=
self
.
parent
().
statusBar
()
progress
=
QProgressDialog
(
self
,
Qt
.
FramelessWindowHint
)
progress
.
setMaximum
(
len
(
packages
)
)
# old vicious bug:len(packages)-1
for
index
,
package
in
enumerate
(
packages
):
progress
.
setValue
(
index
)
progress
.
setLabelText
(
f"
{
text
}
{
package
.
name
}
{
package
.
version
}
..."
)
QApplication
.
processEvents
()
if
progress
.
wasCanceled
():
break
if
package
in
table
.
model
.
actions
:
try
:
thread
.
callback
=
lambda
:
func
(
package
)
thread
.
start
()
while
thread
.
isRunning
():
QApplication
.
processEvents
()
if
progress
.
wasCanceled
():
status
.
setEnabled
(
True
)
status
.
showMessage
(
"Cancelling operation..."
)
table
.
remove_package
(
package
)
error
=
thread
.
error
except
Exception
as
error
:
error
=
str
(
error
)
# to_text_string(error)
if
error
is
not
None
:
pstr
=
(
package
.
name
+
' '
+
package
.
version
)
QMessageBox
.
critical
(
self
,
"Error"
,
f"<b>Unable to
{
action
}
<i>
{
pstr
}
/i></b>"
f"<br><br>Error message:<br>
{
error
}
"
,
)
progress
.
setValue
(
progress
.
maximum
())
status
.
clearMessage
()
for
widget
in
self
.
children
():
if
isinstance
(
widget
,
QWidget
):
widget
.
setEnabled
(
True
)
thread
=
None
for
table
in
(
self
.
table
,
self
.
untable
):
table
.
refresh_distribution
(
self
.
distribution
)
def
report_issue
(
self
):
issue_template
=
f"""
\
Python distribution:
{
python_distribution_infos
()
}
Control panel version:
{
__version__
}
Python Version:
{
platform
.
python_version
()
}
Qt Version:
{
winpython
.
_vendor
.
qtpy
.
QtCore
.
__version__
}
,
{
winpython
.
qt
.
API_NAME
}
{
winpython
.
_vendor
.
qtpy
.
__version__
}
What steps will reproduce the problem?
1.
2.
3.
What is the expected output? What do you see instead?
Please provide any additional information below.
"""
url
=
QUrl
(
f"
{
__project_url__
}
/issues/entry"
)
url
.
addQueryItem
(
"comment"
,
issue_template
)
QDesktopServices
.
openUrl
(
url
)
def
about
(
self
):
"""About this program"""
QMessageBox
.
about
(
self
,
f"About
{
self
.
NAME
}
"
,
f"""<b>
{
self
.
NAME
}
{
__version__
}
</b>
<br>Package Manager and Advanced Tasks
<p>Copyright © 2012 Pierre Raybaut
<br>Licensed under the terms of the MIT License
<p>Created, developed and maintained by Pierre Raybaut
<p><a href="
{
__project_url__
}
">WinPython at Github.io</a>: downloads, bug reports,
discussions, etc.</p>
<p>This program is executed by:<br>
<b>
{
python_distribution_infos
()
}
</b><br>
Python
{
platform
.
python_version
()
}
, Qt
{
winpython
.
_vendor
.
qtpy
.
QtCore
.
__version__
}
,
{
winpython
.
_vendor
.
qtpy
.
API_NAME
}
qtpy
{
winpython
.
_vendor
.
qtpy
.
__version__
}
"""
,
)
def
main
(
test
=
False
):
app
=
QApplication
([])
win
=
PMWindow
()
win
.
show
()
if
test
:
return
app
,
win
else
:
app
.
exec_
()
def
test
():
app
,
win
=
main
(
test
=
True
)
print
(
sys
.
modules
)
app
.
exec_
()
if
__name__
==
"__main__"
:
main
()
Back
|
FazBrowse Home
|
New Git URL