-
-
Notifications
You must be signed in to change notification settings - Fork 10
PR: Cleaning up code #94
base: master
Are you sure you want to change the base?
Changes from all commits
2929e1c
7a0053d
c62ebfe
bd5bf43
6f2bc48
acb4f8e
4d6f7d8
7699178
6597a9a
b884363
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,21 +73,21 @@ def _update_cell(self, row, column): | |
end = self.index(row, column) | ||
self.dataChanged.emit(start, end) | ||
|
||
def update_style_palette(self, palette={}): | ||
def update_style_palette(self, palette=None): | ||
"""Update style palette for conda-manager extension.""" | ||
if palette: | ||
self._palette.update(palette) | ||
|
||
def flags(self, index): | ||
@staticmethod | ||
def flags(index): | ||
"""Override Qt method""" | ||
column = index.column() | ||
|
||
if index.isValid(): | ||
if column in [C.COL_START, C.COL_END]: | ||
# return Qt.ItemFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) | ||
return Qt.ItemFlags(Qt.ItemIsEnabled) | ||
else: | ||
return Qt.ItemFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) | ||
# return Qt.ItemFlags(Qt.ItemIsEnabled) | ||
else: | ||
return Qt.ItemFlags(Qt.ItemIsEnabled) | ||
|
||
|
@@ -196,39 +196,33 @@ def data(self, index, role=Qt.DisplayRole): | |
return to_qvariant(P['icon.add.pressed']) | ||
else: | ||
return to_qvariant(P['icon.add.active']) | ||
elif (status == C.INSTALLED or | ||
status == C.UPGRADABLE or | ||
status == C.DOWNGRADABLE or | ||
status == C.MIXGRADABLE): | ||
elif status in [C.INSTALLED, C.UPGRADABLE, C.DOWNGRADABLE, | ||
C.MIXGRADABLE]: | ||
if r: | ||
return to_qvariant(P['icon.remove.pressed']) | ||
else: | ||
return to_qvariant(P['icon.remove.active']) | ||
else: | ||
return to_qvariant(P['icon.add.inactive']) | ||
elif column == C.COL_REMOVE: | ||
if (status == C.INSTALLED or | ||
status == C.UPGRADABLE or | ||
status == C.DOWNGRADABLE or | ||
status == C.MIXGRADABLE): | ||
if status in [C.INSTALLED, C.UPGRADABLE, C.DOWNGRADABLE, | ||
C.MIXGRADABLE]: | ||
if r: | ||
return to_qvariant(P['icon.remove.pressed']) | ||
else: | ||
return to_qvariant(P['icon.remove.active']) | ||
else: | ||
return to_qvariant(P['icon.remove.inactive']) | ||
elif column == C.COL_UPGRADE: | ||
if status == C.UPGRADABLE or \ | ||
status == C.MIXGRADABLE: | ||
if status in [C.UPGRADABLE, C.MIXGRADABLE]: | ||
if u: | ||
return to_qvariant(P['icon.upgrade.pressed']) | ||
else: | ||
return to_qvariant(P['icon.upgrade.active']) | ||
else: | ||
return to_qvariant(P['icon.upgrade.inactive']) | ||
elif column == C.COL_DOWNGRADE: | ||
if status == C.DOWNGRADABLE or \ | ||
status == C.MIXGRADABLE: | ||
if status in [C.DOWNGRADABLE, C.MIXGRADABLE]: | ||
if d: | ||
return to_qvariant(P['icon.downgrade.pressed']) | ||
else: | ||
|
@@ -243,26 +237,25 @@ def data(self, index, role=Qt.DisplayRole): | |
elif role == Qt.ToolTipRole: | ||
if column == C.COL_INSTALL and status == C.NOT_INSTALLED: | ||
return to_qvariant(_('Install package')) | ||
elif column == C.COL_INSTALL and (status == C.INSTALLED or | ||
status == C.UPGRADABLE or | ||
status == C.DOWNGRADABLE or | ||
status == C.MIXGRADABLE): | ||
elif column == C.COL_INSTALL and (status in [C.INSTALLED, | ||
C.UPGRADABLE, | ||
C.DOWNGRADABLE, | ||
C.MIXGRADABLE]): | ||
return to_qvariant(_('Remove package')) | ||
elif column == C.COL_UPGRADE and (status == C.INSTALLED or | ||
status == C.UPGRADABLE or | ||
status == C.MIXGRADABLE): | ||
elif column == C.COL_UPGRADE and (status in [C.INSTALLED, | ||
C.UPGRADABLE, | ||
C.MIXGRADABLE]): | ||
return to_qvariant(_('Upgrade package')) | ||
elif column == C.COL_DOWNGRADE and (status == C.INSTALLED or | ||
status == C.DOWNGRADABLE or | ||
status == C.MIXGRADABLE): | ||
elif column == C.COL_DOWNGRADE and (status in [C.INSTALLED, | ||
C.DOWNGRADABLE, | ||
C.MIXGRADABLE]): | ||
return to_qvariant(_('Downgrade package')) | ||
elif column == C.COL_PACKAGE_TYPE: | ||
if type_ == C.CONDA_PACKAGE: | ||
return to_qvariant(_('Conda package')) | ||
elif type_ == C.PIP_PACKAGE: | ||
return to_qvariant(_('Python package')) | ||
elif column == C.COL_VERSION: | ||
if is_upgradable: | ||
elif column == C.COL_VERSION and is_upgradable: | ||
return to_qvariant(_('Update available')) | ||
elif role == Qt.ForegroundRole: | ||
palette = QPalette() | ||
|
@@ -275,17 +268,17 @@ def data(self, index, role=Qt.DisplayRole): | |
color = palette.color(QPalette.Mid) | ||
color = P['foreground.not.installed'] | ||
return to_qvariant(color) | ||
elif column in [C.COL_VERSION]: | ||
if is_upgradable: | ||
elif column in [C.COL_VERSION] and is_upgradable: | ||
return to_qvariant(P['foreground.upgrade']) | ||
|
||
elif role == Qt.SizeHintRole: | ||
if column in [C.ACTION_COLUMNS] + [C.COL_PACKAGE_TYPE]: | ||
elif (role == Qt.SizeHintRole and column in | ||
C.ACTION_COLUMNS + [C.COL_PACKAGE_TYPE]): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The semantic is changed for the addition here, is it normal ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah it was a mistae :-| |
||
return to_qvariant(QSize(24, 24)) | ||
|
||
return to_qvariant() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
|
||
def headerData(self, section, orientation, role=Qt.DisplayRole): | ||
@staticmethod | ||
def headerData(section, orientation, role=Qt.DisplayRole): | ||
"""Override Qt method""" | ||
if role == Qt.TextAlignmentRole: | ||
if orientation == Qt.Horizontal: | ||
|
@@ -310,7 +303,8 @@ def rowCount(self, index=QModelIndex()): | |
"""Override Qt method""" | ||
return len(self._rows) | ||
|
||
def columnCount(self, index=QModelIndex()): | ||
@staticmethod | ||
def columnCount(index=QModelIndex()): | ||
"""Override Qt method""" | ||
return len(C.COLUMNS) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,7 +129,7 @@ def toint(x): | |
# replace letters found by a negative number | ||
replace_dic = {} | ||
alpha = sorted(alpha, reverse=True) | ||
if len(alpha): | ||
if alpha: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The sort can be done inside the |
||
replace_dic = dict(zip(alpha, list(range(-1, -(len(alpha)+1), -1)))) | ||
|
||
# Complete with zeros based on longest item and replace alphas with number | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,19 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
def human_bytes(n): | ||
""" | ||
Return the number of bytes n in more human readable form. | ||
""" | ||
"""Return the number of bytes n in more human readable form.""" | ||
if n < 1024: | ||
return '%d B' % n | ||
return '{0} B'.format(n) | ||
k = n/1024 | ||
if k < 1024: | ||
return '%d KB' % round(k) | ||
return '{0} KB'.format(round(k)) | ||
m = k/1024 | ||
if m < 1024: | ||
return '%.1f MB' % m | ||
return '{0:1f} MB'.format(m) | ||
g = m/1024 | ||
return '%.2f GB' % g | ||
return '{0:1f} GB'.format(g) | ||
|
||
|
||
def split_canonical_name(cname): | ||
""" | ||
Split a canonical package name into (name, version, build) strings. | ||
""" | ||
"""Split a canonical package name into (name, version, build) strings.""" | ||
return tuple(cname.rsplit('-', 2)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,23 +116,28 @@ def set_environments(self, prefix): | |
""" """ | ||
self.packages.set_environment(prefix=prefix) | ||
|
||
def add_env(self): | ||
@staticmethod | ||
def add_env(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These shouldn't be removed since I guess that |
||
""" """ | ||
# TODO: | ||
|
||
def clone_env(self): | ||
@staticmethod | ||
def clone_env(): | ||
""" """ | ||
# TODO: | ||
|
||
def remove_env(self): | ||
@staticmethod | ||
def remove_env(): | ||
""" """ | ||
# TODO: | ||
|
||
def preferences(self): | ||
@staticmethod | ||
def preferences(): | ||
""" """ | ||
# TODO: | ||
|
||
def report_issue(self): | ||
@staticmethod | ||
def report_issue(): | ||
if PY3: | ||
from urllib.parse import quote | ||
else: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in
Bootstrap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍