-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Add Focus To Name feature and CommandPalette
- Loading branch information
1 parent
486576b
commit b54c95b
Showing
7 changed files
with
172 additions
and
15 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from __future__ import absolute_import | ||
|
||
import six | ||
from Qt.QtCore import QPoint, Qt | ||
from Qt.QtWidgets import QFrame, QHBoxLayout, QLineEdit, QShortcut | ||
|
||
from .workbox_completer import WorkboxCompleter | ||
|
||
|
||
class CommandPalette(QFrame): | ||
def __init__(self, model, parent=None, **kwargs): | ||
super(CommandPalette, self).__init__(parent=parent, **kwargs) | ||
self.y_offset = 100 | ||
lyt = QHBoxLayout(self) | ||
self.uiLineEDIT = QLineEdit(parent=self) | ||
lyt.addWidget(self.uiLineEDIT) | ||
self.setMinimumSize(400, self.sizeHint().height()) | ||
self.uiCloseSCT = QShortcut( | ||
Qt.Key_Escape, self, context=Qt.WidgetWithChildrenShortcut | ||
) | ||
self.uiCloseSCT.activated.connect(self.hide) | ||
self.uiLineCOMPL = WorkboxCompleter() | ||
self.uiLineCOMPL.setCaseSensitivity(False) | ||
self.uiLineCOMPL.setModel(model) | ||
self.uiLineEDIT.setCompleter(self.uiLineCOMPL) | ||
self.uiLineCOMPL.activated.connect(self.completed) | ||
self.uiLineCOMPL.highlighted.connect(self.completer_selected) | ||
# self.uiLineCOMPL.popup().clicked.connect(self.completed) | ||
self.current_name = parent.name_for_workbox(parent.current_workbox()) | ||
|
||
def completed(self, name): | ||
if isinstance(name, six.string_types): | ||
self.current_name = name | ||
else: | ||
self.current_name = self.uiLineCOMPL.pathFromIndex(name) | ||
self.hide() | ||
|
||
def completer_selected(self, name): | ||
self.parent().workbox_for_name(name.rstrip("/"), visible=True) | ||
|
||
def hide(self): | ||
# Close the popup if its open | ||
self.uiLineCOMPL.popup().hide() | ||
# Restore the original tab as the user didn't choose the new tab | ||
self.completer_selected(self.current_name) | ||
super(CommandPalette, self).hide() | ||
|
||
def reposition(self): | ||
pgeo = self.parent().geometry() | ||
geo = self.geometry() | ||
center = QPoint(pgeo.width() // 2, self.y_offset) | ||
geo.moveCenter(center) | ||
self.setGeometry(geo) | ||
|
||
def popup(self): | ||
self.reposition() | ||
self.uiLineEDIT.setFocus(Qt.PopupFocusReason) | ||
self.show() | ||
self.uiLineCOMPL.complete() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from __future__ import absolute_import | ||
|
||
from Qt.QtWidgets import QCompleter | ||
|
||
|
||
class WorkboxCompleter(QCompleter): | ||
def splitPath(self, path): | ||
return path.split("/") | ||
|
||
def pathFromIndex(self, index): | ||
return self.model().pathFromIndex(index) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from __future__ import absolute_import | ||
|
||
from Qt.QtCore import Qt | ||
from Qt.QtGui import QStandardItem, QStandardItemModel | ||
|
||
|
||
class WorkboxItemModel(QStandardItemModel): | ||
def __init__(self, manager, *args, **kwargs): | ||
super(WorkboxItemModel, self).__init__(*args, **kwargs) | ||
self.manager = manager | ||
|
||
def pathFromIndex(self, index): | ||
parts = [""] | ||
while index.isValid(): | ||
parts.append(self.data(index, Qt.DisplayRole)) | ||
index = index.parent() | ||
if len(parts) == 1: | ||
return "" | ||
return "/".join([x for x in parts[::-1] if x]) | ||
|
||
|
||
class WorkboxTreeItemModel(WorkboxItemModel): | ||
def process(self): | ||
root = self.invisibleRootItem() | ||
prev_group = -1 | ||
for _, group_name, tab_name, group_index, _ in self.manager.all_widgets(): | ||
if prev_group != group_index: | ||
group_item = QStandardItem(group_name) | ||
root.appendRow(group_item) | ||
prev_group = group_index | ||
|
||
tab_item = QStandardItem(tab_name) | ||
group_item.appendRow(tab_item) | ||
|
||
|
||
class WorkboxListItemModel(WorkboxItemModel): | ||
def process(self): | ||
root = self.invisibleRootItem() | ||
for _, group_name, tab_name, _, _ in self.manager.all_widgets(): | ||
group_item = QStandardItem('/'.join((group_name, tab_name))) | ||
root.appendRow(group_item) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters