Skip to content

Commit

Permalink
fix #1 - preserve scroll position
Browse files Browse the repository at this point in the history
  • Loading branch information
suxiaojiang committed Mar 6, 2021
1 parent d632392 commit 1047e73
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 33 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Rez Managaer
![](https://img.shields.io/badge/python-3.7%2B-blue)

![GUI](https://raw.githubusercontent.com/cuckon/rez-manager/master/images/GUI.png)

Expand All @@ -9,6 +10,7 @@ A rez util package that can:
- [x] Support variants.
- [ ] Filter & Sort the results.
- [x] Open folder of selected package.
- [ ] Work with rez in separate thread.

Please note that the deploy scripts is not contained in this repository. I
suppose it varies from place to place. The simplest way to deploy it is just
Expand Down
78 changes: 45 additions & 33 deletions src/rez_manager/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,32 @@

def generate_item_tooltip(item):
"""Generate a proper tooltip for item"""
if item.empty_folder:
return '[Empty folder]'

latest = item.latest
if not latest:
return ''

tooltip = []
if item.empty_folder:
tooltip.append('[Empty folder]')
else:
if latest.description:
tooltip.append(latest.format('Description: {description}'))
if latest.variants:
variants_string = ['Variants: ']

# `latest.variants` Example:
# [
# [PackageRequest('python-2.7')],
# [PackageRequest('python-3.7')],
# ]
for variant in latest.variants:
variant_str = ' * '
variant_str += '-'.join(p.safe_str() for p in variant)
variants_string.append(variant_str)
tooltip.append('\n'.join(variants_string))
if latest.tools:
tooltip.append('Tools: ' + ', '.join(latest.tools))

if latest.description:
tooltip.append(latest.format('Description: {description}'))
if latest.variants:
variants_string = ['Variants: ']

# `latest.variants` Example:
# [
# [PackageRequest('python-2.7')],
# [PackageRequest('python-3.7')],
# ]
for variant in latest.variants:
variant_str = ' * '
variant_str += ' | '.join(p.safe_str() for p in variant)
variants_string.append(variant_str)
tooltip.append('\n'.join(variants_string))
if latest.tools:
tooltip.append('Tools: ' + ', '.join(latest.tools))

return '\n'.join(tooltip)

Expand Down Expand Up @@ -139,7 +140,7 @@ def _add_delete_packages_menu(
if empty_package_folders:
actions.append(menu.addAction(
'Delete Empty Package Folder',
partial(delete_empty_folder, empty_package_folders)
partial(self.delete_empty_folder, empty_package_folders)
))

return actions
Expand Down Expand Up @@ -167,7 +168,6 @@ def _add_localise_package_menu(

return actions


def _add_multiple_packages_menu(self, menu, indexes):
local_repo_table_index = get_local_repo_index() + 1
model = self.model()
Expand Down Expand Up @@ -213,6 +213,18 @@ def localise(self, packages):
self.packageLocalised.emit()


# class RezPackagesProxyModel(QtCore.QSortFilterProxyModel):
# def __init__(self, parent=None):
# super(RezPackagesProxyModel, self).__init__(parent)
# self.setFilterKeyColumn(0)

# def reload(self):
# return self.sourceModel().reload()

# def itemFromIndex(self, index):
# return self.sourceModel().itemFromIndex(index)


class RezPackagesModel(QtGui.QStandardItemModel):

def __init__(self, parent=None):
Expand All @@ -221,18 +233,17 @@ def __init__(self, parent=None):
self.setHorizontalHeaderLabels(['Package'] + self.repos)

def reload(self):
# TODO: #1 - keep scrolling position.

package_repository_manager.clear_caches()
self.setRowCount(0)
families = list(packages.iter_package_families())
self.setRowCount(len(families))

for fam in packages.iter_package_families():
row = [QtGui.QStandardItem(fam.name)]
for row, fam in enumerate(families):
self.setItem(row, 0, QtGui.QStandardItem(fam.name))
versions = [None]
version_max = None

# Fill the spreadsheet
for repo in self.repos:
for irepo, repo in enumerate(self.repos):
latest = packages.get_latest_package(fam.name, paths=[repo])
package_folder = os.path.join(repo, fam.name)

Expand All @@ -252,19 +263,17 @@ def reload(self):
versions.append(latest.version or None)

item.setText(generate_item_text(item))
item.setToolTip(generate_item_tooltip(item))
row.append(item)

item.setToolTip(generate_item_tooltip(item))
self.setItem(row, irepo + 1, item)

# Find the winner
winner_found = False
for i in range(len(self.repos)):
if not winner_found and versions[i + 1] and versions[i + 1] == version_max:
winner_found = True
else:
row[i + 1].setForeground(QtGui.QColor('gray'))

self.appendRow(row)
self.item(row, i + 1).setForeground(QtGui.QColor('gray'))


class ManagerWin(QtWidgets.QMainWindow):
Expand Down Expand Up @@ -318,5 +327,8 @@ def show_status_message(self, message):
def setup_spreadsheet(self):
view = SpreadsheetView()
model = RezPackagesModel()
# proxy_model = RezPackagesProxyModel()
# proxy_model.setSourceModel(model)
# view.setModel(proxy_model)
view.setModel(model)
return view

0 comments on commit 1047e73

Please sign in to comment.