AcceptPanel的行为修正

This commit is contained in:
玉宇清音 2023-12-30 17:43:16 +08:00
parent 351b446a15
commit 1bd5fd9a29
5 changed files with 46 additions and 18 deletions

View File

@ -5,7 +5,9 @@
</component>
<component name="ChangeListManager">
<list default="true" id="55c45e43-6fd9-4244-902d-86f83a348f5b" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.idea/codeStyles/codeStyleConfig.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Manager.py" beforeDir="false" afterPath="$PROJECT_DIR$/Manager.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/test.py" beforeDir="false" afterPath="$PROJECT_DIR$/test.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -25,9 +27,9 @@
<component name="HierarchyBrowserManager">
<option name="IS_AUTOSCROLL_TO_SOURCE" value="true" />
</component>
<component name="ProjectColorInfo"><![CDATA[{
"associatedIndex": 2
}]]></component>
<component name="ProjectColorInfo">{
&quot;associatedIndex&quot;: 2
}</component>
<component name="ProjectId" id="2aDBCkoR2x9AbgMgSJixv1KIMSj" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true">
<ConfirmationsSetting value="2" id="Add" />
@ -46,11 +48,11 @@
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"git-widget-placeholder": "master",
"git-widget-placeholder": "main",
"settings.editor.selected.configurable": "preferences.sourceCode"
}
}]]></component>
<component name="RunManager" selected="Python.Manager">
<component name="RunManager" selected="Python.SplitPanel">
<configuration name="DockPanel" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="SimpleIDE" />
<option name="ENV_FILES" value="" />
@ -141,10 +143,10 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="Python.Manager" />
<item itemvalue="Python.SplitPanel" />
<item itemvalue="Python.DockPanel" />
<item itemvalue="Python.test" />
<item itemvalue="Python.Manager" />
<item itemvalue="Python.DockPanel" />
</list>
</recent_temporary>
</component>

View File

@ -1,13 +1,13 @@
from PyQt5.QtWidgets import QWidget, QApplication
from PyQt5.QtCore import QObject, QEvent, QRect, QMargins, Qt
from PyQt5.QtGui import QPainter, QColor
from enum import Enum
from PyQt5.QtCore import QObject, QEvent, QRect, QMargins, Qt, QMimeData
from PyQt5.QtGui import QPainter, QColor, QDragEnterEvent, QDropEvent
import re
class AcceptPanel(QWidget):
def __init__(self, parent):
super(AcceptPanel, self).__init__(parent)
def __init__(self, mgr):
super(AcceptPanel, self).__init__(None)
self.left_rect = QRect()
self.right_rect = QRect()
self.top_rect = QRect()
@ -17,6 +17,8 @@ class AcceptPanel(QWidget):
self.setMouseTracking(True)
self.setAcceptDrops(True)
self.mgr_inst = mgr
def resizeEvent(self, a0):
total_rect = self.rect()
total_rect = total_rect - QMargins(5, 5, 5, 5)
@ -35,7 +37,6 @@ class AcceptPanel(QWidget):
super(AcceptPanel, self).paintEvent(a0)
painter = QPainter(self)
painter.fillRect(self.rect(), Qt.lightGray)
painter.fillRect(self.hover_rect, Qt.gray)
painter.fillRect(self.top_rect, Qt.green)
@ -65,6 +66,21 @@ class AcceptPanel(QWidget):
self.update()
def dragEnterEvent(self, a0: QDragEnterEvent):
if a0.mimeData().hasFormat("text/plain"):
content = a0.mimeData().text()
regex = re.compile("view-drags\\(([^\\(\\)]+)\\)")
if regex.match(content):
a0.acceptProposedAction()
def dropEvent(self, a0: QDropEvent):
regex = re.compile("view-drags\\(([^\\(\\)]+)\\)")
result = regex.match(a0.mimeData().text())
if result:
view_id = result.group(1)
adjust_view = self.mgr_inst.get_dockpanel(view_id)
self.setVisible(False)
print(adjust_view)
class DragManager(QObject):
__unique_inst: 'DragManager' = None
@ -72,6 +88,8 @@ class DragManager(QObject):
def __init__(self):
super(DragManager, self).__init__()
self.__dock_map = {}
self.__accept_panel = AcceptPanel(self)
self.__accept_panel.setVisible(False)
@classmethod
def instance(cls):
@ -101,8 +119,12 @@ class DragManager(QObject):
gpos = sender.mapToGlobal(event.pos())
point = view_inst.mapFromGlobal(gpos)
if (view_inst.rect().contains(point)) and (self.__peak_window(view_inst).isActiveWindow()):
print(view_inst.rect())
self.__accept_panel.setParent(view_inst)
self.__accept_panel.raise_()
self.__accept_panel.async_with(view_inst)
self.__accept_panel.setVisible(True)
pass
pass
pass
return super(DragManager, self).eventFilter(sender, event)

Binary file not shown.

View File

@ -1,2 +1,6 @@
dict = {}
print(dict.__class__.__name__)
import re
regex = re.compile("somevalue\\(([^\\(\\)]+)\\)")
rst = regex.match("somevalue(adfadsfdf)")
if rst:
print(rst.group(1))