Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement #96 (app version changeable) #126

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion allzpark/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def __init__(self,
state = State(self, storage, parent_environ)

models = {
"apps": model.ApplicationModel(),
"apps": model.ApplicationModel(self),
"profileVersions": QtCore.QStringListModel(),

# Docks
Expand Down Expand Up @@ -1083,6 +1083,11 @@ def _list_apps(self, profile):
"patchWithFilter", False
)
)
# update context key `app_request` if patched
for pkg in context.resolved_packages or []:
if pkg.name == app_package.name:
app_request = "%s==%s" % (pkg.name, pkg.version)
break

contexts[app_request] = context

Expand Down
2 changes: 1 addition & 1 deletion allzpark/delegates.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def setEditorData(self, editor, index):

def setModelData(self, editor, model, index):
model = index.model()
package = model.data(index, "name")
package = model.data(index, "family")
options = model.data(index, "versions")
default = model.data(index, "default")
version = options[editor.currentIndex()]
Expand Down
33 changes: 31 additions & 2 deletions allzpark/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,33 +179,51 @@ class ApplicationModel(AbstractTableModel):
"version"
]

def __init__(self, *args, **kwargs):
def __init__(self, ctrl, *args, **kwargs):
super(ApplicationModel, self).__init__(*args, **kwargs)
self._broken_icon = res.icon("Action_Stop_1_32.png")
self._ctrl = ctrl

def reset(self, applications=None):
applications = applications or []

self.beginResetModel()
self.items[:] = []

# TODO: This isn't nice. The model should
# not have to reach into the controller.
paths = self._ctrl._package_paths()

for app in applications:
root = app.root

data = allzparkconfig.metadata_from_package(app)
tools = getattr(app, "tools", None) or [app.name]
app_request = "%s==%s" % (app.name, app.version)

version = str(app.version)

# Fetch all versions of package
# TODO: set range to profile request
versions = rez.find(app.name, paths=paths)
versions = sorted(
[str(v.version) for v in versions],
key=util.natural_keys
)

item = {
"name": app_request,
"label": data["label"],
"version": str(app.version),
"version": version,
"versions": versions,
"icon": parse_icon(root, template=data["icon"]),
"package": app,
"context": None,
"active": True,
"hidden": data["hidden"],
"broken": isinstance(app, BrokenPackage),
"family": app.name,
"default": version,

# Whether or not to open a separate console for this app
"detached": False,
Expand Down Expand Up @@ -253,6 +271,16 @@ def data(self, index, role):

return super(ApplicationModel, self).data(index, role)

def flags(self, index):
if index.column() == 1:
return (
QtCore.Qt.ItemIsEnabled |
QtCore.Qt.ItemIsSelectable |
QtCore.Qt.ItemIsEditable
)

return super(ApplicationModel, self).flags(index)


class BrokenContext(object):
def __init__(self, app_name, request):
Expand Down Expand Up @@ -401,6 +429,7 @@ def reset(self, packages=None):
"state": state,
"relocatable": relocatable,
"localizing": False, # in progress
"family": pkg.name,
}

self.items.append(item)
Expand Down
15 changes: 13 additions & 2 deletions allzpark/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@
from .vendor import qargparse
from .version import version
from . import resources as res, dock, model
from . import allzparkconfig
from . import allzparkconfig, delegates

px = res.px


class Applications(dock.SlimTableView):

def __init__(self, ctrl, parent=None):
super(Applications, self).__init__(parent)
self.setItemDelegate(delegates.Package(ctrl, self))
self.setEditTriggers(self.EditKeyPressed)


class Window(QtWidgets.QMainWindow):
title = "Allzpark %s" % version

Expand Down Expand Up @@ -60,7 +68,7 @@ def __init__(self, ctrl, parent=None):
"logo": QtWidgets.QToolButton(),
"appVersion": QtWidgets.QLabel(version),

"apps": dock.SlimTableView(),
"apps": Applications(ctrl),
"fullCommand": FullCommand(ctrl),

# Error page
Expand Down Expand Up @@ -696,6 +704,9 @@ def on_app_clicked(self, index):
app.show()
self.on_dock_toggled(app, visible=True)

if index.column() == 1:
self._widgets["apps"].edit(index)

def on_app_selection_changed(self, selected, deselected):
"""The current app was changed

Expand Down