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

Subprocess indicator #125

Merged
merged 2 commits into from
Nov 10, 2020
Merged
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
9 changes: 8 additions & 1 deletion allzpark/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ class Controller(QtCore.QObject):

patch_changed = QtCore.Signal(str) # full patch string

running_cmd_updated = QtCore.Signal(int)

states = [
_State("booting", help="ALLZPARK is booting, hold on"),
_State("resolving", help="Rez is busy resolving a context"),
Expand Down Expand Up @@ -275,6 +277,10 @@ def __init__(self,
def models(self):
return self._models

@property
def timers(self):
return self._timers

@property
def state(self):
return self._state
Expand Down Expand Up @@ -356,7 +362,8 @@ def resolved_packages(self, app_request):
# ----------------

def on_tasks_polled(self):
self._models["commands"].poll()
running_count = self._models["commands"].poll()
self.running_cmd_updated.emit(running_count)

def on_state_changed(self):
state = self._name_to_state[self._state.state]
Expand Down
7 changes: 6 additions & 1 deletion allzpark/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,14 +531,19 @@ def append(self, command):
def poll(self):
self.layoutAboutToBeChanged.emit()

running_count = 0
for row in range(self.rowCount()):
command = self.items[row]["object"]
value = "running" if command.is_running() else "killed"
is_running = command.is_running()
running_count += is_running
value = "running" if is_running else "killed"
index = self.createIndex(row, 0, QtCore.QModelIndex())
self.setData(index, value, "running")

self.layoutChanged.emit()

return running_count


class JsonModel(qjsonmodel.QJsonModel):

Expand Down
3 changes: 3 additions & 0 deletions allzpark/resources/chat-square-dots-fill.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions allzpark/resources/check-circle-fill.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions allzpark/resources/exclamation-circle-fill.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions allzpark/resources/gear-fill.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions allzpark/resources/style-dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,14 @@ Window #body QLineEdit {
margin: 3px;
}

Window QStatusBar::item {
border-right: 1px solid %(dim)s;
}

Window QStatusBar #indicatorText {
font-family: "JetBrains Mono";
}

FullCommand QLineEdit {
color: rgba(0, 0, 0, 0.2);
}
Expand Down
8 changes: 8 additions & 0 deletions allzpark/resources/style-light.css
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,14 @@ Window #body QLineEdit {
margin: 3px;
}

Window QStatusBar::item {
border-right: 1px solid %(dim)s;
}

Window QStatusBar #indicatorText {
font-family: "JetBrains Mono";
}

FullCommand QLineEdit {
color: rgba(0, 0, 0, 0.2);
}
Expand Down
75 changes: 73 additions & 2 deletions allzpark/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def __init__(self, ctrl, parent=None):
"leftToggles": QtWidgets.QWidget(),
"dockToggles": QtWidgets.QWidget(),

"stateIndicator": QtWidgets.QLabel(),
"stateIndicator": StateIndicator(),
"commandIndicator": CommandIndicator(),
}

# The order is reflected in the UI
Expand Down Expand Up @@ -232,6 +233,7 @@ def on_visible(widget, toggle, state):
layout.addWidget(widgets["fullCommand"])

status_bar = self.statusBar()
status_bar.addPermanentWidget(widgets["commandIndicator"])
status_bar.addPermanentWidget(widgets["stateIndicator"])

# Setup
Expand Down Expand Up @@ -284,6 +286,7 @@ def on_visible(widget, toggle, state):
self.on_profileversion_reset)
ctrl.resetted.connect(self.on_reset)
ctrl.state_changed.connect(self.on_state_changed)
ctrl.running_cmd_updated.connect(self.on_running_cmd_updated)
ctrl.logged.connect(self.on_logged)
ctrl.profile_changed.connect(self.on_profile_changed)
ctrl.repository_changed.connect(self.on_repository_changed)
Expand Down Expand Up @@ -611,6 +614,9 @@ def tell(self, message, level=logging.INFO):
def on_logged(self, message, level):
self._docks["console"].append(message, level)

def on_running_cmd_updated(self, count):
self._widgets["commandIndicator"].set_count(count)

def on_state_changed(self, state):
self.tell("State: %s" % state, logging.DEBUG)

Expand Down Expand Up @@ -659,7 +665,7 @@ def on_state_changed(self, state):
launch_btn.setEnabled(False)
launch_btn.setText("Failed to resolve")

self._widgets["stateIndicator"].setText(str(state))
self._widgets["stateIndicator"].set_status(str(state))
self.update_advanced_controls()

def on_launch_clicked(self):
Expand Down Expand Up @@ -733,9 +739,74 @@ def showEvent(self, event):
def closeEvent(self, event):
self._ctrl.state.store("geometry", self.saveGeometry())
self._ctrl.state.store("windowState", self.saveState())
for timer in self._ctrl.timers.values():
timer.stop()
return super(Window, self).closeEvent(event)


class Indicator(QtWidgets.QWidget):
"""Status bar indicator base class"""

def __init__(self, parent=None):
super(Indicator, self).__init__(parent)
widgets = {
"icon": QtWidgets.QLabel(),
"text": QtWidgets.QLabel(),
}
widgets["icon"].setObjectName("indicatorIcon")
widgets["text"].setObjectName("indicatorText")

layout = QtWidgets.QHBoxLayout(self)
layout.setContentsMargins(4, 2, 4, 2)
layout.addWidget(widgets["icon"])
layout.addWidget(widgets["text"])

self._widgets = widgets
self._size = QtCore.QSize(px(12), px(12))

def setToolTip(self, tip):
for widget in self._widgets.values():
widget.setToolTip(tip)
super(Indicator, self).setToolTip(tip)


class StateIndicator(Indicator):

def __init__(self, parent=None):
super(StateIndicator, self).__init__(parent)

icons = {
"busy": res.icon("chat-square-dots-fill").pixmap(self._size),
"ready": res.icon("check-circle-fill").pixmap(self._size),
"error": res.icon("exclamation-circle-fill").pixmap(self._size),
}
self._icons = icons

def set_status(self, status):
if status in ["errored", "noapps", "noprofiles", "pkgnotfound"]:
key = "error"
elif status == "ready":
key = "ready"
else:
key = "busy"

self._widgets["icon"].setPixmap(self._icons[key])
self._widgets["text"].setText(status)
self.setToolTip("Current status: %s" % status)


class CommandIndicator(Indicator):

def __init__(self, parent=None):
super(CommandIndicator, self).__init__(parent)
icon = res.icon("gear-fill")
self._widgets["icon"].setPixmap(icon.pixmap(self._size))

def set_count(self, count):
self._widgets["text"].setText(str(count))
self.setToolTip("%d running commands" % count)


class FullCommand(QtWidgets.QWidget):
def __init__(self, ctrl, parent=None):
super(FullCommand, self).__init__(parent)
Expand Down