Skip to content

adding proxy model that toggles the instances. #33

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
24 changes: 24 additions & 0 deletions pyblish_lite/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,28 @@ QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {
}

#Details #Docstring {
}

#RecordCb::indicator:checked {
background: #ff66e8;
}

#DebugCb::indicator:checked {
background: #ff66e8;
}

#InfoCb::indicator:checked {
background: #66abff;
}

#WarningCb::indicator:checked {
background: #ffba66;
}

#ErrorCb::indicator:checked {
background: #ff4d58;
}

#CriticalCb::indicator:checked {
background: #ff4f75;
}
44 changes: 26 additions & 18 deletions pyblish_lite/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
as the key of a dictionary, except they can only be integers.

"""

import re
from Qt import QtCore, __binding__


Expand Down Expand Up @@ -200,13 +200,13 @@ def data(self, index, role):

# Context specific actions
for action in actions:
if action.on == "failed" and not item.has_failed:
if action.on == "failed" and not item._has_failed:
actions.remove(action)
if action.on == "succeeded" and not item.has_succeeded:
if action.on == "succeeded" and not item._has_succeeded:
actions.remove(action)
if action.on == "processed" and not item.has_processed:
if action.on == "processed" and not item._has_processed:
actions.remove(action)
if action.on == "notProcessed" and item.has_processed:
if action.on == "notProcessed" and item._has_processed:
actions.remove(action)

# Discard empty groups
Expand Down Expand Up @@ -488,12 +488,14 @@ def __init__(self, source, parent=None):

self.excludes = dict()
self.includes = dict()
self.search = re.compile('.*')

def item(self, index):
index = self.index(index, 0, QtCore.QModelIndex())
index = self.mapToSource(index)
model = self.sourceModel()
return model.items[index.row()]
def setData(self, index, value, role):
return self.sourceModel().setData(self.mapToSource(index), value, role)

def set_search(self, value):
value = value.replace(" ", ".*")
self.search = re.compile(".*{0}.*".format(value))

def add_exclusion(self, role, value):
"""Exclude item if `role` equals `value`
Expand Down Expand Up @@ -596,20 +598,18 @@ def filterAcceptsRow(self, source_row, source_parent):
model = self.sourceModel()
item = model.items[source_row]

key = getattr(item, "filter", None)
if key is not None:
regex = self.filterRegExp()
if regex.pattern():
match = regex.indexIn(key)
return False if match == -1 else True
if self.search:
data = item.get("label", None)
if not self.search.match(data):
return False

for role, values in self.includes.items():
data = getattr(item, role, None)
data = item.get(role, None)
if data not in values:
return False

for role, values in self.excludes.items():
data = getattr(item, role, None)
data = item.get(role, None)
if data in values:
return False

Expand All @@ -618,3 +618,11 @@ def filterAcceptsRow(self, source_row, source_parent):

def rowCount(self, parent=QtCore.QModelIndex()):
return super(ProxyModel, self).rowCount(parent)

def __iter__(self):
"""Yield each row of model"""
model = self.sourceModel()
for i in range(len(model.items)):
index = self.index(i, 0, QtCore.QModelIndex())
if self.mapToSource(index).isValid():
yield index
66 changes: 49 additions & 17 deletions pyblish_lite/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,21 +171,25 @@ def __init__(self, controller, parent=None):
terminal_footer = QtWidgets.QWidget()

search_box = QtWidgets.QLineEdit()
instance_combo = QtWidgets.QComboBox()
plugin_combo = QtWidgets.QComboBox()
show_errors = QtWidgets.QCheckBox()
# instance_combo = QtWidgets.QComboBox()
# plugin_combo = QtWidgets.QComboBox()
show_records = QtWidgets.QCheckBox()
show_records.setToolTip("Records")
show_debug = QtWidgets.QCheckBox()
show_debug.setToolTip("Debug")
show_info = QtWidgets.QCheckBox()
show_info.setToolTip("Info")
show_warning = QtWidgets.QCheckBox()
show_warning.setToolTip("Warning")
show_error = QtWidgets.QCheckBox()
show_error.setToolTip("Error")
show_critical = QtWidgets.QCheckBox()
show_critical.setToolTip("Critical")

layout = QtWidgets.QHBoxLayout(terminal_footer)
for w in (search_box,
instance_combo,
plugin_combo,
show_errors,
# instance_combo,
# plugin_combo,
show_records,
show_debug,
show_info,
Expand All @@ -200,7 +204,7 @@ def __init__(self, controller, parent=None):
terminal_page = QtWidgets.QWidget()
layout = QtWidgets.QVBoxLayout(terminal_page)
layout.addWidget(terminal_container)
# layout.addWidget(terminal_footer) # TODO
layout.addWidget(terminal_footer) # TODO
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(0)

Expand Down Expand Up @@ -353,14 +357,15 @@ def __init__(self, controller, parent=None):
instance_model = model.Instance()
plugin_model = model.Plugin()
terminal_model = model.Terminal()
terminal_proxy_model = model.ProxyModel(terminal_model)

artist_view.setModel(instance_model)
left_view.setModel(instance_model)
right_view.setModel(plugin_model)
terminal_view.setModel(terminal_model)
terminal_view.setModel(terminal_proxy_model)

instance_combo.setModel(instance_model)
plugin_combo.setModel(plugin_model)
# instance_combo.setModel(instance_model)
# plugin_combo.setModel(plugin_model)

names = {
# Main
Expand Down Expand Up @@ -388,6 +393,14 @@ def __init__(self, controller, parent=None):
"Reset": reset,
"Stop": stop,

# Check Boxes
"RecordCb": show_records,
"DebugCb": show_debug,
"InfoCb": show_info,
"WarningCb": show_warning,
"ErrorCb": show_error,
"CriticalCb": show_critical,

# Misc
"CommentBox": comment_box,
"CommentPlaceholder": comment_placeholder,
Expand Down Expand Up @@ -427,6 +440,15 @@ def __init__(self, controller, parent=None):
"instances": instance_model,
"plugins": plugin_model,
"terminal": terminal_model,
"terminal_proxy": terminal_proxy_model
},
"terminal_toggles": {
"record": show_records,
"debug": show_debug,
"info": show_info,
"warning": show_warning,
"error": show_error,
"critical": show_critical
},
"tabs": {
"artist": artist_tab,
Expand Down Expand Up @@ -509,14 +531,14 @@ def __init__(self, controller, parent=None):
right_view.customContextMenuRequested.connect(
self.on_plugin_action_menu_requested)

for box in (show_errors,
show_records,
show_debug,
show_info,
show_warning,
show_error,
show_critical):
for box, value in ((show_records, 'record'),
(show_debug, 'debug'),
(show_info, 'info'),
(show_warning, 'warning'),
(show_error, 'error'),
(show_critical, 'critical')):
box.setChecked(True)
box.toggled.connect(lambda toggle, v=value: self.on_item_filter(toggle, v))

artist_tab.setChecked(True)

Expand All @@ -526,6 +548,16 @@ def __init__(self, controller, parent=None):
#
# -------------------------------------------------------------------------

def on_item_search_filter(self, value):
model = self.data["models"]["terminal_proxy"]
model.set_search(value)

def on_item_filter(self, value, level):
model = self.data["models"]["terminal_proxy"]
f = model.remove_exclusion if value else model.add_exclusion
f(role="type", value=level)
f(role="levelname", value=level.upper())

def on_item_expanded(self, index, state):
if not index.data(model.IsExpandable):
return
Expand Down