widgetexceptionerror i am trying to build a simple app using python kivy and this is the error which i am getting - kivy

I am trying to build a app using kivy and I am getting a widget expression error
raise WidgetException('Cannot add %r, it already has a parent %r'
kivy.uix.widget.WidgetException: Cannot add <kivy.uix.button.Button object at 0x0000026C4F999E40>, it already has a parent <main.SpartanGrid object at 0x0000026C4F1480B0>
this is my code
import turtle
import kivy
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
wn = turtle.Screen()
wn.setup(height=1.0,width=1.0)
wn.bgcolor('black')
turtle.hideturtle()
usr = turtle.textinput("what user wish to", "please tell weather you want to access or
write to the file")
usr.lower()
if usr == 'access':
with open("C:\\Users\\Badri\\Documents\\New folder\\pyproject.txt", 'r') as pr:
cont = pr.read()
turtle.color('red')
turtle.write(cont, align='center', font=('caliber', 25, 'normal'))
elif usr == 'write':
class SpartanGrid(GridLayout):
def __init__(self,**kwargs):
super(SpartanGrid,self).__init__()
self.cols=3
self.add_widget(Label(text="person Name:"))
self.s_name=TextInput()
self.add_widget(self.s_name)
self.add_widget(Label(text="person ph.no"))
self.s_no = TextInput()
self.add_widget(self.s_no)
self.press = Button(text="submit")
self.add_widget(self.press)
self.press.bind(on_press=self.submit)
self.add_widget(self.press)
def submit(self,instance):
print("successful")
class SpartanApp(App):
def build(self):
return SpartanGrid()
if __name__ == "__main__":
SpartanApp().run()
else:
turtle.write("the input is not valid",align='center',font=('caliber',25,'normal'))
turtle.bye()
turtle.done()

Related

REST endpoint works as in line script and doesn't work when mentioned as file-Cannot open URL: bundle://200.0:1/rest_CreateMultipleSubtasks.groovy

I am using this REST endpoint for a fragment and it works perfectly as an inline script. 
Here is my code below and here is a screenshot of the page where I am redirected after clicking on the button. 
import groovy.transform.BaseScript
import com.atlassian.jira.issue.Issue;
import javax.ws.rs.core.Response
import org.apache.log4j.Logger
import groovy.transform.BaseScript
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import javax.ws.rs.core.MultivaluedMap
import com.atlassian.jira.component.ComponentAccessor
import javax.ws.rs.core.Response
import CreateMultipleSubtasks.Configuration_CreateMultipleSubtasks
import com.atlassian.jira.project.Project
#BaseScript CustomEndpointDelegate delegate
callSubTaskCreator(httpMethod: "GET", groups: ["jira-users"]) {MultivaluedMap queryParams, String body ->
def log1 = Logger.getLogger("atlassian-jira.log")
log1.warn("MOUNA CAMELIA223");
Configuration_CreateMultipleSubtasks conf =new Configuration_CreateMultipleSubtasks()
def MultipleSubtasksHashMap= conf.getSubTaskCreatorHashMap()
String itracCreatemultiplesubtasksProjectCategoriesURL = MultipleSubtasksHashMap["itracCreatemultiplesubtasksProjectCategoriesURL"] as String;
log1.warn("MOUNA CAMELIA223 "+itracCreatemultiplesubtasksProjectCategoriesURL);
 def user = ComponentAccessor.jiraAuthenticationContext?.loggedInUser
  def issueId = queryParams.getFirst("issueId") as Long
  Issue myissue = ComponentAccessor.getIssueManager().getIssueObject(issueId)
  def issueKey = myissue.getKey()
  def itracCreatemultiplesubtasksProjectCategoriesURL2 = itracCreatemultiplesubtasksProjectCategoriesURL.replaceAll(":1:", issueKey)
  def itracCreatemultiplesubtasksProjectCategoriesURL3 = itracCreatemultiplesubtasksProjectCategoriesURL2.replaceAll(":2:", user.getUsername())
  log1.warn("The rest endpoint has been executed by the user " +user)
  Response.temporaryRedirect(URI.create(itracCreatemultiplesubtasksProjectCategoriesURL3)).build()
 
}
When I specify a file for the code that I refer to in my script editor. Everything fails when I click on the button and I am redirected to an error page as you can see below. 
anyone knows what the problem is?
We need a package declatation at the top of the code so we need package BulkSplitter at the top of the code. We need to go to REST endpoint and execute an update. Otherwise, Jira doesn't recognize our changes.
package BulkSplitter
import groovy.transform.BaseScript
import com.atlassian.jira.issue.Issue;
import javax.ws.rs.core.Response
import org.apache.log4j.Logger
import groovy.transform.BaseScript
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import javax.ws.rs.core.MultivaluedMap
import com.atlassian.jira.component.ComponentAccessor
import javax.ws.rs.core.Response
import CreateMultipleSubtasks.Configuration_CreateMultipleSubtasks
import com.atlassian.jira.project.Project
#BaseScript CustomEndpointDelegate delegate
callSubTaskCreator(httpMethod: "GET", groups: ["jira-users"]) {MultivaluedMap queryParams, String body ->
def log1 = Logger.getLogger("atlassian-jira.log")
log1.warn("MOUNA CAMELIA223");
Configuration_CreateMultipleSubtasks conf =new Configuration_CreateMultipleSubtasks()
def MultipleSubtasksHashMap= conf.getSubTaskCreatorHashMap()
String itracCreatemultiplesubtasksProjectCategoriesURL = MultipleSubtasksHashMap["itracCreatemultiplesubtasksProjectCategoriesURL"] as String;
log1.warn("MOUNA CAMELIA223 "+itracCreatemultiplesubtasksProjectCategoriesURL);
def user = ComponentAccessor.jiraAuthenticationContext?.loggedInUser
def issueId = queryParams.getFirst("issueId") as Long
Issue myissue = ComponentAccessor.getIssueManager().getIssueObject(issueId)
def issueKey = myissue.getKey()
def itracCreatemultiplesubtasksProjectCategoriesURL2 = itracCreatemultiplesubtasksProjectCategoriesURL.replaceAll(":1:", issueKey)
def itracCreatemultiplesubtasksProjectCategoriesURL3 = itracCreatemultiplesubtasksProjectCategoriesURL2.replaceAll(":2:", user.getUsername())
log1.warn("The rest endpoint has been executed by the user " +user)
Response.temporaryRedirect(URI.create(itracCreatemultiplesubtasksProjectCategoriesURL3)).build()
}

Jira REST endpoint redirected to error page

I am using a REST endpoint and here is my code: and here are some screenshots. The first screenshot shows the declaration of the condition and the denclaration of the Link: /rest/scriptrunner/latest/custom/callSubTaskCreator?issueId=${issue.id}. The second screenshot shows the declaration of the REST endpoint. I am specifying the link of a file in the script editor. Finally, the last screenshot shows the error page where I am redirected after clicking on the link.
as you can see I am redirected to an error page after I click on the button. Anyone knows what is wrong?
package CreateMultipleSubtasks
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import com.atlassian.jira.issue.Issue;
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.atlassian.sal.api.ApplicationProperties
import com.atlassian.sal.api.UrlMode
import org.apache.log4j.Logger
import com.atlassian.jira.project.Project
import com.atlassian.jira.bc.project.component.ProjectComponent
import com.atlassian.jira.project.ProjectManager
#BaseScript CustomEndpointDelegate delegate
callSubTaskCreator(httpMethod: "GET", groups: ["jira-users"]) {
MultivaluedMap queryParams, String body ->
def log = Logger.getLogger("atlassian-jira.log")
log.warn("I AM HERE MOUNA 1");
ConfigurationCreateMultipleSubtasks conf = new ConfigurationCreateMultipleSubtasks()
def subTaskCreatorHashMap= conf.getSubTaskCreatorHashMap()
String itracCreatemultiplesubtasksProjectCategoriesURL = subTaskCreatorHashMap["itracCreatemultiplesubtasksProjectCategoriesURL"];
def user = ComponentAccessor.jiraAuthenticationContext?.loggedInUser
Issue issue = ComponentAccessor.getIssueManager().getIssueObject(queryParams.getFirst("issueId") as Long)
def itracCreatemultiplesubtasksProjectCategoriesURL2 = itracCreatemultiplesubtasksProjectCategoriesURL.replaceAll(":1:", issue.getKey())
def itracCreatemultiplesubtasksProjectCategoriesURL3 = itracCreatemultiplesubtasksProjectCategoriesURL2.replaceAll(":2:", user.getUsername())
Response.temporaryRedirect(URI.create(itracCreatemultiplesubtasksProjectCategoriesURL3)).build()
 
}

Static type checking The variable jiraHelper/issue is undeclared

I am using a condition in my script in the REST endpoint and I am receiving the following errors:
Anyone knows what the problem is and what needs to be fixed?
Here is the code:
package CreateMultipleSubtasks
import org.apache.log4j.Logger
import com.atlassian.jira.plugin.webfragment.model.JiraHelper
import com.atlassian.jira.component.ComponentAccessor
def log1 = Logger.getLogger("atlassian-jira.log")
log1.warn("MOUNA BEFORE")
Configuration_CreateMultipleSubtasks conf = new Configuration_CreateMultipleSubtasks()
def subTaskCreatorHashMap= conf.getSubTaskCreatorHashMap()
String projectKey = subTaskCreatorHashMap["projectKey"];
String issueTypeName = subTaskCreatorHashMap["issueTypeName"];
log.warn("MOUNA PROJECT KEY "+ projectKey+" issuetypename "+issueTypeName)
def val=jiraHelper.project?.key==projectKey && issue.issueType.name==issueTypeName
return val

ROS/OpenCV/Flask - How to stream?

I'm trying to create a web stream interface of a camera that is connected to ROS.
A node publishes photo of the camera every 2 seconds to this topic: webcam/image_raw
image_message = bridge.cv2_to_imgmsg(frame_empty, encoding="bgr8")
pub_image_raw.publish(image_message)
And the other node subscribes to it and renders it on a web page via Flask.
#!/usr/bin/env python
import rospy
import threading
import cv2
from sensor_msgs.msg import Image
from cv_bridge import CvBridge, CvBridgeError
from flask import Flask, render_template, redirect, Response
app = Flask(__name__)
bridge = CvBridge()
cv_image = 0
def callback(data):
global cv_image
try:
cv_image = bridge.imgmsg_to_cv2(data, "bgr8")
#cv2.imshow("Image window", cv_image)
except CvBridgeError as e:
print(e)
threading.Thread(target=lambda: rospy.init_node('test_node5', disable_signals=True)).start()
image_sub = rospy.Subscriber("webcam/image_raw", Image, callback)
def gen():
global cv_image
while True:
#success, image = video.read()
ret, jpeg = cv2.imencode('.jpg', cv_image)
frame = jpeg.tobytes()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')
#app.route('/')
def video_feed():
return Response(gen(),
mimetype='multipart/x-mixed-replace; boundary=frame')
if __name__ == '__main__':
# from og server
app.run(host='0.0.0.0', port=5000, debug=True)
Until now it's kinda working but there is a lot of random errors.
Is there a way to improve this code?
Thank!

adding context QMenu to left click on a button in PySide

I want to add context menu to left click of mouse button pressed over emailbtn
from PySide import QtCore,QtGui
import sys
class ToolBarUI(QtGui.QWidget):
def __init__(self,*args,**kwargs):
super(ToolBarUI,self).__init__(*args,**kwargs)
self.createActions()
self.floatingToolBar()
pass
def sizeHint(self):
return QtCore.QSize(65,45)
def buttons(self):
x,y=15,35
self.btnVLay=QtGui.QVBoxLayout(self)
self.setLayout(self.btnVLay)
self.btnVLay.setContentsMargins(0,0,0,0)
self.incSavbtn=QtGui.QPushButton("Save")
self.incSavbtn.setMinimumSize(QtCore.QSize(x,y))
self.emailbtn=QtGui.QPushButton("Email")
self.emailbtn.setMinimumSize(QtCore.QSize(x,y))
self.upldbtn=QtGui.QPushButton("Upload")
self.upldbtn.setMinimumSize(QtCore.QSize(x,y))
self.setPrjbtn=QtGui.QPushButton("Set Project")
self.setPrjbtn.setMinimumSize(QtCore.QSize(x,y))
self.setThumb=QtGui.QPushButton("Set thumb")
self.setThumb.setMinimumSize(QtCore.QSize(x,y))
self.shwMatbtn=QtGui.QPushButton("Show Material")
self.shwMatbtn.setMinimumSize(QtCore.QSize(x,y))
self.fixtexbtn=QtGui.QPushButton("Fix Texture Paths")
self.fixtexbtn.setMinimumSize(QtCore.QSize(x,y))
btns = [self.incSavbtn,self.emailbtn,self.upldbtn,self.setPrjbtn,self.setPrjbtn,self.setThumb,self.shwMatbtn,self.fixtexbtn]
[self.btnVLay.addWidget(each) for each in btns]
def contextMenuEvent(self, event):
menu = QtGui.QMenu(self)
menu.addAction(self.emlSel)
menu.addAction(self.emlScn)
menu.addAction(self.emlBufr)
#menu.exec_(self.emailbtn.mapToGlobal(QtCore.QPoint(0,0)))
#menu.exec_(event.globalPos())
def createActions(self):
self.emlSel = QtGui.QAction("Email Selected", self)
self.emlScn = QtGui.QAction("Email this Scene", self)
self.emlBufr = QtGui.QAction("Email Current Frame Buffer", self)
def floatingToolBar(self):
self.buttons()
self.setLayout(self.btnVLay)
self.show()
pass
if __name__ =='__main__':
app = QtGui.QApplication(sys.argv)
win = ToolBarUI()
win.show()
sys.exit(app.exec_())
I have tried in contextMenuEvent method but that gives me on right click :/
What am i missing ? Any help will be appreciated.
It works in Linux but not in windows.
Below is code I used for systemtrayicon with left click support in windows. This might work for you as well.
QtCore.QObject.connect(self, QtCore.SIGNAL("activated(QSystemTrayIcon::ActivationReason)"), self.iconActivated)
def iconActivated(self, reason):
if reason == QtGui.QSystemTrayIcon.Trigger: // left click, right click is Context
self.contextMenu().activateWindow() // menu will disappear on clicking any where other than menu
self.contextMenu().popup(QtGui.QCursor.pos()) // display menu at cursor location
Looks like you could use the setMenu method:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from PyQt4 import QtCore, QtGui
class myWindow(QtGui.QWidget):
def __init__(self, parent=None):
super(myWindow, self).__init__(parent)
self.actionHello = QtGui.QAction(self)
self.actionHello.setText("Hello")
self.menu = QtGui.QMenu(self)
self.menu.addAction(self.actionHello)
self.buttonShow = QtGui.QPushButton(self)
self.buttonShow.setText("Button with menu")
self.buttonShow.setMenu(self.menu)
self.layout = QtGui.QVBoxLayout(self)
self.layout.addWidget(self.buttonShow)
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
app.setApplicationName('myWindow')
main = myWindow()
main.show()
sys.exit(app.exec_())

Resources