小编Fel*_*lix的帖子

QGraphicsView:如何使橡皮筋选择仅出现在鼠标左键上?

我想制作一个QGraphicsScene并在 中显示它QGraphicsView。我想通过鼠标中键滚动场景并通过左键进行橡皮筋选择。但我不知道如何使橡皮筋选择仅通过鼠标左键出现。

这是我的代码:

# -*- coding: utf-8 -*-

import os, sys

from PyQt5 import QtWidgets, QtCore, QtGui, QtSvg

class MegaSceneView(QtWidgets.QGraphicsView):
    def __init__(self, parent=None):
        super(MegaSceneView, self).__init__(parent)
        self._scale_factor = 1.0

        self._scale_by = 1.2
        self.setAcceptDrops(True)

        self.setRenderHint(QtGui.QPainter.Antialiasing)
        self.setMouseTracking(True)
        self.setRubberBandSelectionMode(QtCore.Qt.IntersectsItemShape)
        self.setDragMode(QtWidgets.QGraphicsView.RubberBandDrag)

        self._prev_mouse_scene_pos = None


    def mousePressEvent(self, event):
        if (event.buttons() & QtCore.Qt.MidButton) != QtCore.Qt.NoButton:
            self._prev_mouse_scene_pos = (event.pos())
        super(MegaSceneView, self).mousePressEvent(event)

    def mouseReleaseEvent(self, event):
        super(MegaSceneView, self).mouseReleaseEvent(event)
        self._prev_mouse_scene_pos = None

    def mouseMoveEvent(self, event):
        super(MegaSceneView, self).mouseMoveEvent(event)

        if (event.buttons() & QtCore.Qt.MidButton) != QtCore.Qt.NoButton:
            cur_mouse_pos = (event.pos())
            if …
Run Code Online (Sandbox Code Playgroud)

qt pyqt qgraphicsview qgraphicsscene qt5

5
推荐指数
2
解决办法
2201
查看次数

PyInstaller:如何在一个文件夹中创建多个程序?

我正在开发一个 Python 包,并且有大约 10 个演示 Python 脚本来展示其功能。

我想用 PyInstaller 分发演示脚本:创建 10 个 exe 文件并将它们放在一个文件夹中,其中包含它们依赖的所有库。

你不能告诉我,怎么做?

python pyinstaller

5
推荐指数
1
解决办法
2544
查看次数

是否可以将 C++ 小部件嵌入 PyQt 应用程序?

我有一个 PyQt5 应用程序和大多数用 Python 编写的小部件。我想用 C++ Qt 编写一些小部件以使其更快,然后将其嵌入到我的 PyQt QMainWindow 中。

是否可以?

c++ python pyqt pyqt5

5
推荐指数
1
解决办法
3139
查看次数

Python:枚举的片段

我想在一个列表中迭代.另外,我想知道迭代下元素的索引.

我想做点什么

for i, elm in enumerate(test_list)[7:40]:
    print i, elm
    #i must start with 7
Run Code Online (Sandbox Code Playgroud)

唉,它说,那 'enumerate' object has no attribute '__getitem__'

我怎样才能以大多数pythonic的方式获得它?

python list slice

4
推荐指数
2
解决办法
2298
查看次数

支持JS的Python浏览器模拟器

我想从网站上获取一些数据.通常我会用mechanize这些东西,但现在网站用JS提供数据.唉,mechanize不支持它.

我可以用什么呢?

python mechanize

3
推荐指数
1
解决办法
2万
查看次数

GitLab 在本地主机上使用 Docker 运行程序:如何将主机暴露给容器?

我正在学习使用 GitLab CI。

刚才我在 localhost ( external_url "http://localhost") 上使用 GitLab。我已经使用普通ubuntu:20.04映像注册了一个 Docker 运行程序,并尝试在其上运行一些测试作业。

唉,它尝试从容器中的本地主机存储库克隆我的存储库,但无法做到这一点,因为我的本地主机的端口 80 在容器中不可见。

Running with gitlab-runner 13.5.0 (ece86343)
  on docker0 x8pHJPn7
Preparing the "docker" executor
Using Docker executor with image ubuntu:20.04 ...
Pulling docker image ubuntu:20.04 ...
Using docker image sha256:d70eaf7277eada08fca944de400e7e4dd97b1262c06ed2b1011500caa4decaf1 for ubuntu:20.04 with digest ubuntu@sha256:fff16eea1a8ae92867721d90c59a75652ea66d29c05294e6e2f898704bdb8cf1 ...
Preparing environment
Running on runner-x8phjpn7-project-6-concurrent-0 via gigant...
Getting source from Git repository
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /builds/root/ci_fuss/.git/
fatal: unable …
Run Code Online (Sandbox Code Playgroud)

continuous-integration gitlab docker

3
推荐指数
1
解决办法
5789
查看次数

诗歌:如何从 git 子目录安装?

我想安装feastpython 包poetry

\n

pip3 install git+https://github.com/feast-dev/feast#subdirectory=sdk/python工作正常,

\n

poetry add git+https://github.com/feast-dev/feast#subdirectory=sdk/python给出了一个错误:

\n
  CalledProcessError\n\n  Command '['git', '--git-dir', '/tmp/pypoetry-git-feas51ct2_me/.git', '--work-tree', '/tmp/pypoetry-git-feas51ct2_me', 'checkout', 'subdirectory=sdk/python']' returned non-zero exit status 1.\n\n  at /usr/lib/python3.8/subprocess.py:516 in run\n       512\xe2\x94\x82             # We don't call process.wait() as .__exit__ does that for us.\n       513\xe2\x94\x82             raise\n       514\xe2\x94\x82         retcode = process.poll()\n       515\xe2\x94\x82         if check and retcode:\n    \xe2\x86\x92  516\xe2\x94\x82             raise CalledProcessError(retcode, process.args,\n       517\xe2\x94\x82                                      output=stdout, stderr=stderr)\n       518\xe2\x94\x82     return CompletedProcess(process.args, retcode, stdout, stderr)\n       519\xe2\x94\x82 \n       520\xe2\x94\x82 \n
Run Code Online (Sandbox Code Playgroud)\n

我该如何修复它?

\n

python pip python-poetry

3
推荐指数
1
解决办法
6541
查看次数

如何调试基于PyQt4的应用程序?

我有一个简单PyQt4的应用程序.我想用PyCharm调试它.

唉,我崩溃了一个错误:

Process finished with exit code -1073740771 (0xC000041D)

这是代码:

from PyQt4 import QtGui, QtCore

app = QtGui.QApplication([])
win = QtGui.QMainWindow() # Breakpoint is here
win.show()
QtGui.QApplication.instance().exec_()
Run Code Online (Sandbox Code Playgroud)

你不能告诉我,我该怎么做才能应付它?

python debugging pyqt pycharm

2
推荐指数
1
解决办法
3709
查看次数

多个矢量对的Numpy和dot产品:怎么做?

我想得到dot productN个向量对(a_vec [i,:],b_vec [i,:]).

a_vec具有形状[N, 3],bvec具有相同的形状(N个3D矢量).

我知道它可以通过numpy.dot功能在循环中轻松完成.但不能以某种方式更简单,更快地完成吗?

python numpy matrix scipy

2
推荐指数
1
解决办法
86
查看次数

需要Python中的循环FFT卷积

我需要更快的模拟

scipy.signal.convolve2d(data, filter, boundary="wrap", mode="same")
Run Code Online (Sandbox Code Playgroud)

你不能建议我如何更换它吗?

PSscipy.signal.fftconvolve足够快,但它没有boundary选项,我无法使其在循环卷积模式下工作。

python convolution scipy

2
推荐指数
1
解决办法
1996
查看次数

Kubernetes:如何获取我正在运行的 Pod 名称?

我想在 Pod 内运行 Python 代码。该吊舱是由我无法控制的气流创建的。

我想以某种方式获取我正在运行的 Pod 的名称。

如何做呢?

kubernetes

2
推荐指数
1
解决办法
2560
查看次数

Python,PEP-8和多行字典格式

我必须dict在Python中声明一些.我写了这样一段代码:

class MegaClass(object):
    _activation_grad_classes = \
    {
        activation.ForwardStrictRELU: activation.BackwardStrictRELU,
        activation.ForwardLog: activation.BackwardLog,
        activation.ForwardSinCos: activation.BackwardSinCos
    }
Run Code Online (Sandbox Code Playgroud)

得到PEP-8错误:E122 continuation line missing indentation or outdented.

我该如何解决?

python pep8

1
推荐指数
1
解决办法
4273
查看次数