Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dd446ce

Browse files
committed
Merge pull request #80 from stonebig/master
wppm bug fix + Qt5 compatibility move
2 parents 25b3f46 + a1b4c48 commit dd446ce

File tree

2 files changed

+45
-22
lines changed

2 files changed

+45
-22
lines changed

winpython/controlpanel.py

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
QAbstractItemView, QProgressDialog, QTableView,
2222
QPushButton, QLabel, QTabWidget, QToolTip,
2323
QDesktopServices)
24-
from winpython.qt.QtCore import (Qt, QAbstractTableModel, QModelIndex, SIGNAL,
24+
from winpython.qt.QtCore import (Qt, QAbstractTableModel, QModelIndex, Signal,
2525
QThread, QTimer, QUrl)
2626
from winpython.qt.compat import (to_qvariant, getopenfilenames,
2727
getexistingdirectory)
@@ -41,6 +41,9 @@
4141

4242

4343
class PackagesModel(QAbstractTableModel):
44+
# Signals after PyQt4 old SIGNAL removal
45+
dataChanged = Signal(QModelIndex, QModelIndex)
46+
4447
def __init__(self):
4548
QAbstractTableModel.__init__(self)
4649
self.packages = []
@@ -127,8 +130,9 @@ def setData(self, index, value, role=Qt.EditRole):
127130
self.checked.remove(package)
128131
else:
129132
self.checked.add(package)
130-
self.emit(SIGNAL("dataChanged(QModelIndex,QModelIndex)"),
131-
index, index)
133+
# PyQt4 old SIGNAL: self.emit(SIGNAL("dataChanged(QModelIndex,QModelIndex)"),
134+
# PyQt4 old SIGNAL: index, index)
135+
self.dataChanged.emit(index, index)
132136
return True
133137
return False
134138

@@ -141,6 +145,9 @@ def setData(self, index, value, role=Qt.EditRole):
141145

142146

143147
class PackagesTable(QTableView):
148+
# Signals after PyQt4 old SIGNAL removal, to be emitted after package_added event
149+
package_added = Signal()
150+
144151
def __init__(self, parent, process, winname):
145152
QTableView.__init__(self, parent)
146153
assert process in ('install', 'uninstall')
@@ -185,7 +192,8 @@ def add_packages(self, fnames):
185192
notcompatible.append(bname)
186193
except NotImplementedError:
187194
notsupported.append(bname)
188-
self.emit(SIGNAL('package_added()'))
195+
# PyQt4 old SIGNAL: self.emit(SIGNAL('package_added()'))
196+
self.package_added.emit()
189197
if notsupported:
190198
QMessageBox.warning(self, "Warning",
191199
"The following packages filenaming are <b>not "
@@ -272,6 +280,9 @@ class DistributionSelector(QWidget):
272280
"""Python distribution selector widget"""
273281
TITLE = 'Select a Python distribution path'
274282

283+
# Signals after PyQt4 old SIGNAL removal
284+
selected_distribution = Signal(str)
285+
275286
def __init__(self, parent):
276287
super(DistributionSelector, self).__init__(parent)
277288
self.browse_btn = None
@@ -292,8 +303,9 @@ def setup_widget(self):
292303
# self.line_edit.setDisabled(True)
293304
self.browse_btn = QPushButton(get_std_icon('DirOpenIcon'), "", self)
294305
self.browse_btn.setToolTip(self.TITLE)
295-
self.connect(self.browse_btn, SIGNAL("clicked()"),
296-
self.select_directory)
306+
# PyQt4 old SIGNAL:self.connect(self.browse_btn, SIGNAL("clicked()"),
307+
# PyQt4 old SIGNAL: self.select_directory)
308+
self.browse_btn.clicked.connect(self.select_directory)
297309
layout = QHBoxLayout()
298310
layout.addWidget(self.label)
299311
layout.addWidget(self.line_edit)
@@ -318,7 +330,8 @@ def select_directory(self):
318330
continue
319331
directory = osp.abspath(osp.normpath(directory))
320332
self.set_distribution(directory)
321-
self.emit(SIGNAL('selected_distribution(QString)'), directory)
333+
# PyQt4 old SIGNAL: self.emit(SIGNAL('selected_distribution(QString)'), directory)
334+
self.selected_distribution.emit(directory)
322335
break
323336

324337

@@ -338,7 +351,7 @@ def run(self):
338351
or locale.getpreferredencoding()
339352
try:
340353
error_str = error_str.decode(fs_encoding)
341-
except (UnicodeError, TypeError):
354+
except (UnicodeError, TypeError, AttributeError):
342355
pass
343356
self.error = error_str
344357

@@ -394,25 +407,32 @@ def setup_window(self):
394407
self.setWindowIcon(get_icon('winpython.svg'))
395408

396409
self.selector = DistributionSelector(self)
397-
self.connect(self.selector, SIGNAL('selected_distribution(QString)'),
398-
self.distribution_changed)
410+
# PyQt4 old SIGNAL: self.connect(self.selector, SIGNAL('selected_distribution(QString)'),
411+
# PyQt4 old SIGNAL: self.distribution_changed)
412+
self.selector.selected_distribution.connect(self.distribution_changed)
399413

400414
self.table = PackagesTable(self, 'install', self.NAME)
401-
self.connect(self.table, SIGNAL('package_added()'),
402-
self.refresh_install_button)
403-
self.connect(self.table, SIGNAL("clicked(QModelIndex)"),
404-
lambda index: self.refresh_install_button())
415+
# PyQt4 old SIGNAL:self.connect(self.table, SIGNAL('package_added()'),
416+
# PyQt4 old SIGNAL: self.refresh_install_button)
417+
self.table.package_added.connect(self.refresh_install_button)
418+
419+
# PyQt4 old SIGNAL: self.connect(self.table, SIGNAL("clicked(QModelIndex)"),
420+
# PyQt4 old SIGNAL: lambda index: self.refresh_install_button())
421+
self.table.clicked.connect(lambda index: self.refresh_install_button())
405422

406423
self.untable = PackagesTable(self, 'uninstall', self.NAME)
407-
self.connect(self.untable, SIGNAL("clicked(QModelIndex)"),
408-
lambda index: self.refresh_uninstall_button())
424+
# PyQt4 old SIGNAL:self.connect(self.untable, SIGNAL("clicked(QModelIndex)"),
425+
# PyQt4 old SIGNAL: lambda index: self.refresh_uninstall_button())
426+
self.untable.clicked.connect(lambda index: self.refresh_uninstall_button())
409427

410428
self.selector.set_distribution(sys.prefix)
411429
self.distribution_changed(sys.prefix)
412430

413431
self.tabwidget = QTabWidget()
414-
self.connect(self.tabwidget, SIGNAL('currentChanged(int)'),
415-
self.current_tab_changed)
432+
# PyQt4 old SIGNAL:self.connect(self.tabwidget, SIGNAL('currentChanged(int)'),
433+
# PyQt4 old SIGNAL: self.current_tab_changed)
434+
self.tabwidget.currentChanged.connect(self.current_tab_changed)
435+
416436
btn_layout = self._add_table(self.table, "Install/upgrade packages",
417437
get_std_icon("ArrowDown"))
418438
unbtn_layout = self._add_table(self.untable, "Uninstall packages",

winpython/wppm.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def load_log(self, logdir):
166166
try:
167167
data = open(self.logpath(logdir), 'U').readlines()
168168
except (IOError, OSError):
169-
raise
169+
data = [] # it can be now ()
170170
self.files = []
171171
for line in data:
172172
relpath = line.strip()
@@ -326,8 +326,9 @@ def get_installed_packages(self):
326326
wininst.append(pack)
327327
# Include package installed via pip (not via WPPM)
328328
try:
329-
if os.path.dirname(sys.executable) == self.target:
329+
if os.path.dirname(sys.executable) == self.target and 1==2:
330330
# direct way: we interrogate ourself
331+
# avoid as it work only once (bug): result is never updated
331332
import pip
332333
pip_list = [(i.key, i.version)
333334
for i in pip.get_installed_distributions()]
@@ -491,9 +492,11 @@ def uninstall(self, package):
491492
package.uninstall()
492493
package.remove_log(self.logdir)
493494
elif not package.name == 'pip':
494-
subprocess.call([os.path.dirname(sys.executable) + r'\python.exe',
495+
# trick to get true target (if not current)
496+
this_executable_path = os.path.dirname(self.logdir)
497+
subprocess.call([this_executable_path + r'\python.exe',
495498
'-m', 'pip', 'uninstall', package.name, '-y'],
496-
cwd=os.path.dirname(sys.executable))
499+
cwd=this_executable_path)
497500
# legacy, if some package installed by old non-pip means
498501
package.load_log(self.logdir)
499502
for fname in reversed(package.files):

0 commit comments

Comments
 (0)