小编Ale*_*lex的帖子

如何使用pid从Python终止进程?

我正在尝试在python中编写一些简短的脚本,这将在子进程中启动另一个python代码,如果尚未启动,则终止终端和应用程序(Linux).

所以它看起来像:

#!/usr/bin/python
from subprocess import Popen

text_file = open(".proc", "rb")
dat = text_file.read()
text_file.close()

def do(dat):

    text_file = open(".proc", "w")
    p = None

    if dat == "x" :

        p = Popen('python StripCore.py', shell=True)
        text_file.write( str( p.pid ) )

    else :
        text_file.write( "x" )

        p = # Assign process by pid / pid from int( dat )
        p.terminate()

    text_file.close()

do( dat )
Run Code Online (Sandbox Code Playgroud)

应用程序从文件".proc"读取的pid命名过程缺乏知识的问题.另一个问题是解释器说名为dat的字符串不等于"x" ??? 我错过了什么?

python linux terminal process

38
推荐指数
1
解决办法
9万
查看次数

Python以及如何从Selenium元素WebElement对象中获取文本?

我试图通过使用Selenium方法获取html页面中的标记文本内容,但似乎someElement.getText()Python中没有方法.有什么帮助吗?

这是追溯:

AttributeError: 'WebElement' object has no attribute 'getText'
Run Code Online (Sandbox Code Playgroud)

python selenium selenium-webdriver

16
推荐指数
2
解决办法
6万
查看次数

SVG拖动组

我正在努力实现群组内部的群体和个人拖拽.在该组中有3个圆圈.蓝色和灰色圆圈必须单独拖动(通过onmousedown),橙色圆圈用于组移动(通过onclick).问题是拖动整个组后,你必须尝试http://www.atarado.com/stackOF/drag-with%20problems.svg并查看代码.

任何帮助将是欣赏.谢谢.

javascript svg dom

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

问:如何检查按下了哪个鼠标按钮

在尝试确定事件功能中按下了哪个鼠标按钮时,我在PySide中遇到了问题.我特别需要它来忽略鼠标移动事件,因为它在左右两个鼠标按钮上都有效.

如果按下场景上的右键,我想忽略鼠标移动事件.有帮助吗?

c++ qt pyqt pyside

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

在SVG中嵌入SVG

我找不到如何将两个SVG嵌入到SVG文档中的方法.我需要用能够用两个子SVG-s操作的代码的能力来做,并希望在这两个区域上都有独立的坐标.我不喜欢在HTML中这样做,因为我认为与SVG相比它太有限了.非常感谢!

javascript xml svg coordinates

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

试图旋转和转换SVG路径 - 我需要三角计算吗?

我试图用鼠标SVG路径操纵,它表示电子电阻的符号.此符号需要在"引线"结束时进行操作(如果可以拍摄实际电阻); 因此,我试图实现第一点arround(第二个仍然存在)以及在新坐标上拖动第一个点时按比例行为的所有路径点.

尝试分组,尝试使用三角函数...所以代码如下:

   `<g id="r" >    <!-- R - group for symbol of electronics resistor -->
    <path d="M 200 20 v80 h30 v150 h-60 v-150 h30 m 0 150 v80 "
    fill="none" stroke="blue" stroke-width="5" />
    <circle  cx="200" cy="20" r="10"
    fill="blue"   />
    <circle  cx="200" cy="330" r="10"
    fill="blue"/>
    </g>`
Run Code Online (Sandbox Code Playgroud)

请帮忙.

javascript svg coordinate-transformation

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

SVG小组翻译问题

我必须出于特定原因进行小组翻译(SVG).我不知道为什么我不能正确地做到这一点,因为在翻译完成后,在另一个单击组上它会重置开始位置的翻译并让我在SVG画布上乱跑.我在链接上写了准系统示例:http://www.atarado.com/en/stripboard-layout-software/group-translation-problem.svg,这里是代码:

<svg xmlns="http://www.w3.org/2000/svg"
 xmlns:xlink="http://www.w3.org/1999/xlink">
<script><![CDATA[
function startMove(evt){
 x1=evt.clientX;
 y1=evt.clientY;
 group=evt.target.parentNode;
 group.setAttribute("onmousemove","moveIt(evt)");
}
function moveIt(evt){
 dx=evt.clientX-x1;
 dy=evt.clientY-y1;
 group.setAttributeNS(null,"transform","translate("+ dx + ", " + dy +")");
}
function drop(){
 group.setAttributeNS(null, "onmousemove",null);
}
]]></script>
<rect x="0" y="0" width="100%" height="100%" fill="dodgerblue"/>

<g id="BC" transform="translate(0, 0)" onmousedown="startMove(evt)" onmouseup="drop()"><circle id="C" cx="60" cy="60" r="22" fill="lightgrey" stroke="black" stroke-width="8"/><circle id="B" cx="120" cy="60" r="22" fill="orange" stroke="black" stroke-width="8" /></g>
</svg>
Run Code Online (Sandbox Code Playgroud)

欢迎任何愿意提供帮助的人.

svg translation drag-and-drop coordinates coordinate-transformation

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

PySide如何将焦点设置到新窗口并在不存在的情况下打开它

我已经开始从 Zetcode 的示例中学习 PySide,并尝试编写具有两个窗口的应用程序:“原理图视图”,它是“布局视图”的父级,每个窗口都有菜单栏。启动时应该只是原理图窗口,布局 win 应该通过菜单栏根目录中的 switchtoLAYOUT 启动。

我的问题是:

  1. 如何使 root 中的“switchtoLAYOUT”不显示下拉菜单,并且仍然只对“布局视图”窗口的一个实例进行操作?
  2. 如何在两个窗口之间切换焦点(“switchtoLAYOUT”和“switchtoSCHEMATIC”)?
  3. 请检查我的代码并建议我一些聪明的东西(这应该不难)。

编码:

import sys
from PySide import QtCore, QtGui

class schematicWindow(QtGui.QMainWindow):

    def __init__(self):
        super(schematicWindow, self).__init__()
        self.defineSchWin()

    def defineSchWin(self):               
        exitAction = QtGui.QAction('&Exit', self)
        exitAction.setShortcut('Ctrl+Q')
        exitAction.setStatusTip('Exit application')
        exitAction.triggered.connect(self.close)

        self.statusBar()

        menubar = self.menuBar()
        fileMenu = menubar.addMenu('&File')
        fileMenu.addAction(exitAction)
        menubar.addMenu('&Edit')
        menubar.addMenu('&Passives')
        menubar.addMenu('&Descretes')
        menubar.addMenu('&IC\'s')
        swToLayMenu = menubar.addMenu('switchtoLAYOUT')
        swToLayAction = QtGui.QAction(self)
        swToLayAction.triggered.connect(self.layoutWindow)
        swToLayMenu.addAction(swToLayAction)    # open layoutWindow (if not exists) 
                                                # and set focus to layoutWindow 

        self.setGeometry(0, 300, 500, 300)
        self.setWindowTitle('Schematic View')    
        self.show() …
Run Code Online (Sandbox Code Playgroud)

qt pyqt pyside

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

如何使用python脚本启动/终止应用程序?

我使用Linux(LMDE),我想知道如何制作简单的.py脚本来启动和停止另一个python应用程序.例如 :

if pyApp is running :
   kill pyApp
   exit xterminal

else :
   start xterminal
   python pyApp.py
Run Code Online (Sandbox Code Playgroud)

它是否适合python或我应该使用bash?

python linux debian

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

如何删除或替换由起点和终点确定的 Python 中的子字符串?

有时我会删除或替换一个长字符串的子字符串。因此,我将确定一个开始模式和一个结束模式,这将确定子字符串的起点和终点:

long_string = "lorem ipsum..white chevy..blah,blah...lot of text..beer bottle....and so to the end"
removed_substr_start = "white chevy"
removed_substr_end = "beer bott"

# this is pseudo method down
STRresult = long_string.replace( [from]removed_substr_start [to]removed_substr_end, "")
Run Code Online (Sandbox Code Playgroud)

python regex string

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

为什么html2text模块会抛出UnicodeDecodeError?

我有html2text模块的问题...显示我UnicodeDecodeError:

UnicodeDecodeError: 'ascii' codec can't decode byte 
0xbe in position 6: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud)

示例:

#!/usr/bin/python
# -*- coding: utf-8 -*-
import html2text
import urllib

h = html2text.HTML2Text()
h.ignore_links = True

html = urllib.urlopen( "http://google.com" ).read()

print h.handle( html )
Run Code Online (Sandbox Code Playgroud)

...也尝试h.handle( unicode( html, "utf-8" ) 过没有成功.任何帮助.编辑:

Traceback (most recent call last):
  File "test.py", line 12, in <module>
    print h.handle(html)
  File "/home/alex/Desktop/html2text-master/html2text.py", line 254, in handle
    return self.optwrap(self.close())
  File "/home/alex/Desktop/html2text-master/html2text.py", line 266, in close
    self.outtext = self.outtext.join(self.outtextlist)
UnicodeDecodeError: 'ascii' …
Run Code Online (Sandbox Code Playgroud)

python unicode

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

Pyside QgraphicsScene无法捕获鼠标事件

我找不到将鼠标事件附加到场景的方法。如果没有 View,所有事件都会被捕获,但是当注释掉时,只有 mousePressEvent 起作用。请帮忙。

from PySide import QtGui, QtCore

class Window(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.Scene()
        self.View()

    def mousePressEvent(self, event):
        if event.button() == QtCore.Qt.LeftButton:
            print "Pressed!!!"

    def mouseMoveEvent(self, event):
        print "moving....."

    def mouseReleaseEvent(self, event):
        print "-------released"

    def Scene(self):
        self.s = QtGui.QGraphicsScene(self)

    def View(self):
        self.v = QtGui.QGraphicsView(self.s)
        self.setCentralWidget(self.v)

if __name__ == '__main__':
    import sys
    app = QtGui.QApplication(sys.argv)
    window = Window()
    window.resize(300, 200)
    window.show()
    sys.exit(app.exec_())
Run Code Online (Sandbox Code Playgroud)

qt pyqt pyside qt-events qt-signals

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

如何保存PySide树视图模型结构

这是其他SO问题QTreeView与自定义项目的链接,其中是QTreeView示例.

请在这个例子中解释一下,如何从树视图中保存树结构.

  1. 是QAbstractItemModel类,我可以从中提取标签名称,以及我可以再次加载的结构吗?

  2. 如果是这样,我怎么能访问节点?除索引以外的任何其他方式

编辑(来自链接):

import sys
from PySide import QtGui, QtCore


#-------------------------------------------------------------------------------
# my test data
class Icon():
    def __init__(self, icon, tooltip):
        self.pixmap = QtGui.QPixmap(icon)
        self.tooltip = tooltip

#-------------------------------------------------------------------------------
# my test data
class MyData():
    def __init__(self, txt, parent=None):
        self.txt = txt
        self.tooltip = None
        self.parent = parent
        self.child = []
        self.icon = []
        self.index = None
        self.widget = None

    #---------------------------------------------------------------------------
    def position(self):
        position = 0
        if self.parent is not None:
            count = 0
            children = self.parent.child …
Run Code Online (Sandbox Code Playgroud)

python qt pyqt qtreeview pyside

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