vtk: code work only correctly in debug with breakpoint - vtk

I have a code:
do not work correctly in release
do not work correctly in debug without breakpoint
work correctly in debug with a breakpoint
import vtkmodules.all as vtk
render = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(render)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
cubeAnnotation = vtk.vtkAnnotatedCubeActor()
actors = vtk.vtkPropCollection()
cubeAnnotation.GetActors(actors)
cubeActor = list(actors)[0]
colors = vtk.vtkNamedColors()
face_colors = vtk.vtkUnsignedCharArray()
face_colors.SetNumberOfComponents(3)
face_x_plus = colors.GetColor3ub('Red')
face_x_minus = colors.GetColor3ub('Green')
face_y_plus = colors.GetColor3ub('Blue')
face_y_minus = colors.GetColor3ub('Yellow')
face_z_plus = colors.GetColor3ub('Cyan')
face_z_minus = colors.GetColor3ub('Magenta')
face_colors.InsertNextTypedTuple(face_x_minus)
face_colors.InsertNextTypedTuple(face_x_plus)
face_colors.InsertNextTypedTuple(face_y_plus)
face_colors.InsertNextTypedTuple(face_y_minus)
face_colors.InsertNextTypedTuple(face_z_plus)
face_colors.InsertNextTypedTuple(face_z_minus)
cubeActor.GetMapper().GetInput().GetCellData().SetScalars(face_colors)
cubeActor.GetMapper().Update()
cubeActor.Modified()
render.AddActor(cubeActor)
render.ResetCamera()
renWin.Render()
iren.Initialize()
iren.Start()
The breakpoint should be added at cubeActor.GetMapper().GetInput().GetCellData().SetScalars(face_colors), and the cube will be visualizated as:
Otherwise, it do show only gray color.
The environment has been tested:
win10 & ubuntu18
vtk 9.1.0
pycharm
It really make me confuzed. Any suggestion is appreciated~~~

Related

How to fix unidentified character problem while passing data from TKinter to Photoshop via Python script?

I made a GUI Application which looks like this:
The ones marked red are Tkinter Text widgets and the ones marked yellow are Tkinter Entry widgets
After taking user input, the data is to be added to a PSD file and then rendered as an image. But Lets say, after taking the following data as input:
It renders the following Photoshop file:
How do I fix this issue that it does not recognize "\n" properly and hence the rendered document is rendered useless.
Here is the code which deals with converting of the accepted user data into strings and then adding it to Photoshop template and then rendering it:
def DataAdder2CSV():
global edate, eSNO, eage, egender, ename, ePID, econtact, ecomp, eallergy, ehistory, eR
e=edate.get()
a=eSNO.get()
d=eage.get()
f=egender.get()
b=ename.get()
c=ePID.get()
g=econtact.get()
h=ecomp.get(1.0,END)
i=eallergy.get(1.0,END)
j=ehistory.get(1.0,END)
k=eR.get(1.0,END)
data=[a,b,c,d,e,f,g,h,i,j,k]
file=open("Patient_Data.csv","a", newline="")
writer=csv.writer(file, delimiter=",")
writer.writerow(data)
file.close()
messagebox.showinfo("Prescription Generator", "Data has been saved to the database successfully!")
import win32com.client, os
objShell = win32com.client.Dispatch("WScript.Shell")
UserDocs = objShell.SpecialFolders("MyDocuments")
from tkinter import filedialog
ExpDir=filedialog.askdirectory(initialdir=UserDocs, title="Choose Destination Folder")
psApp = win32com.client.Dispatch("Photoshop.Application")
psApp.Open("D:\Coding\Python Scripts\Dr Nikhil Prescription App\Prescription Generator\Presc_Template.psd")
doc = psApp.Application.ActiveDocument
lf1 = doc.ArtLayers["name"]
tol1 = lf1.TextItem
tol1.contents = b
lf2 = doc.ArtLayers["age"]
tol2 = lf2.TextItem
tol2.contents = d
lf3 = doc.ArtLayers["gender"]
tol3 = lf3.TextItem
tol3.contents = f
lf4 = doc.ArtLayers["pid"]
tol4 = lf4.TextItem
tol4.contents = c
lf4 = doc.ArtLayers["date"]
tol4 = lf4.TextItem
tol4.contents = e
lf5 = doc.ArtLayers["contact"]
tol5 = lf5.TextItem
tol5.contents = g
lf6 = doc.ArtLayers["complaint"]
tol6 = lf6.TextItem
varH=" "+h.rstrip("\n")
tol6.contents =varH
lf7 = doc.ArtLayers["allergy"]
tol7 = lf7.TextItem
tol7.contents = i.rstrip("\n")
lf8 = doc.ArtLayers["history"]
tol8 = lf8.TextItem
varJ=" "+j.rstrip("\n")
tol8.contents =varJ
lf9 = doc.ArtLayers["R"]
tol9 = lf9.TextItem
tol9.contents = k.rstrip("\n")
options = win32com.client.Dispatch('Photoshop.ExportOptionsSaveForWeb')
options.Format = 13
options.PNG8 = False
pngfile =ExpDir+f"/{c}-{b}_({e}).png"
doc.Export(ExportIn=pngfile, ExportAs=2, Options=options)
messagebox.showinfo("Prescription Generator", "Prescription has been saved in the desired location successfully!")
There are 3 ways of expressing new line characters:
MacOS uses \r
Linux uses \n
Windows uses \r\n
Python and tkinter use \n but it looks like psApp.Application uses \r instead. That is why the document isn't rendered properly. For more info read the answers to this question.

How to disable anti-aliasing in QGIS export (pyqgis)

I'm trying to save a print layout as BMP in QGIS through python code, but want to turn of antialiasing and can't seem to figure out how to do it
def saveImage(self, layout, filename="defaultexport", extension=".bmp"):
"""Saves given layout as an image"""
filefolder = get_save_location()
filepath = os.path.join(filefolder, filename + extension)
if not os.path.isdir(filefolder):
os.makedirs(filefolder)
exporter = QgsLayoutExporter(layout)
context = QgsLayoutRenderContext(layout)
context.setFlag(context.FlagAntialiasing, False)
export_settings = exporter.ImageExportSettings()
export_settings.generateWorldFile = False
export_settings.dpi = 25
export_settings.flags = context.FlagAntialiasing
result = exporter.exportToImage(filepath, export_settings)
Is what I have. I have no idea what I'm doing with the QgsLayoutRenderContext, but it's about the only thing that seemed like it might do it. Saving manually and turning of the AA setting in save dialog works fine, but I need to do it through pyqgis
Revisting this project knowing some more Python and PyQt5 stuff this was an easy one
exporter = QgsLayoutExporter(layout)
context = QgsLayoutRenderContext(layout)
context.setFlag(context.FlagAntialiasing, False)
export_settings = exporter.ImageExportSettings()
export_settings.generateWorldFile = False
export_settings.dpi = 25
export_settings.flags = context.flags()
result = exporter.exportToImage(self.filepath, export_settings)
Needed to use context.flags()

I am facing End of file reached error

I am newbie to python and was trying following code
class Arm(object):
def __init__(self, SNo, ActivityDate, RequesterTeam, RequesterSignumId, RequesterEmailId,Circle,Customer,Technology,WOType,ProblemTitle,ActivityTypeorEqType,SiteID,BSCFACID,EngineerName,EngineerSignum,DetailDescriptionOfActivityToBePerformed,TimelineforActivityCompletion,WOIDbyWFM ):
self.SNo= SNo
self.ActivityDate=ActivityDate
self.RequesterTeam=RequesterTeam
self.RequesterSignumId=RequesterSignumId
self.RequesterEmailId=RequesterEmailId
self.Circle=Circle
self.Customer=Customer
self.Technology=Technology
self.WOType=WOType
self.ProblemTitle=ProblemTitle
self.ActivityTypeorEqType=ActivityTypeorEqType
self.SiteID=SiteID
self.BSCFACID=BSCFACID
self.EngineerName=EngineerName
self.EngineerSignum=EngineerSignum
self.DetailDescriptionOfActivityToBePerformed=DetailDescriptionOfActivityToBePerformed
self.TimelineforActivityCompletion=TimelineforActivityCompletion
self.WOIDbyWFM=WOIDbyWFM
def __str__(self):
return("Arm object:\n"
"SNo = {0}\n"
"ActivityDate = {1}\n"
"RequesterTeam = {2}\n"
"RequesterSignumId = {3}\n"
"RequesterEmailId = {4}\n"
"Circle = {5}\n"
"Customer = {6}\n"
"Technology = {7}\n"
"WOType = {8}\n"
"ProblemTitle = {9}\n"
"ActivityTypeorEqType = {10}\n"
"SiteID = {11}\n"
"BSCFACID = {12}\n"
"EngineerName = {13}\n"
"EngineerSignum = {14}\n"
"DetailDescriptionOfActivityToBePerformed = {15}\n"
"TimelineforActivityCompletion= {16}\n"
"WOIDbyWFM = {17}\n"
.format(self.SNo,
self.ActivityDate,
self.RequesterTeam,
self.RequesterSignumId,
self.RequesterEmailId,
self.Circle,
self.Customer,
self.Technology,
self.WOType,
self.ProblemTitle,
self.ActivityTypeorEqType,
self.SiteID,
self.BSCFACID,
self.EngineerName,
self.EngineerSignum,
self.DetailDescriptionOfActivityToBePerformed,
self.TimelineforActivityCompletion,
self.WOIDbyWFM)
I am getting
File
"C:\Users\OpenSource\eclipse-workspace\PythonWorkSpace\DataHiding\src\Hiding.py", line 26 ^ SyntaxError:unexpected EOF while parsing error
while running the code. please suggest me where i am making errors.
You should have "WOIDbyWFM = {17}\n"..format(self.SNo, .......
You are missing a closing right parentheses at the end of your return statement.
Please use the PyCharm editor and it will show you all errors like eclipse does and then you can correctly indent your code to make it bug free.

Print to the IDLE Shell when a tkinter button is pressed

I am trying to create a small window that shows up in the corner of your screen. The window will have a keyboard on it. I want to be able to make the computer think that you pressed a button on your keyboard when a button in the window is pressed. This is the code I have so far:
from tkinter import *
top = Tk()
frame1 = Frame(top)
btn = Button(frame1,text="q",command= 'print("q",end="")')
btn2 = Button(frame1,text="w",command= 'print("w",end="")')
btn3 = Button(frame1,text="e",command= 'print("e",end="")')
btn4 = Button(frame1,text="r",command= 'print("r",end="")')
btn5 = Button(frame1,text="t",command= 'print("t",end="")')
btn6 = Button(frame1,text="y",command= 'print("y",end="")')
btn7 = Button(frame1,text="u",command= 'print("u",end="")')
btn8 = Button(frame1,text="i",command= 'print("i",end="")')
btn9 = Button(frame1,text="o",command= 'print("o",end="")')
btn10 = Button(frame1,text="p",command='print("p",end="")')
frame2 = Frame(top)
btn11 = Button(frame2,text="a",command='print("a",end="")')
btn12 = Button(frame2,text="s",command='print("s",end="")')
btn13 = Button(frame2,text="d",command='print("d",end="")')
btn14 = Button(frame2,text="f",command='print("f",end="")')
btn15 = Button(frame2,text="g",command='print("g",end="")')
btn16 = Button(frame2,text="h",command='print("h",end="")')
btn17 = Button(frame2,text="j",command='print("j",end="")')
btn18 = Button(frame2,text="k",command='print("k",end="")')
btn19 = Button(frame2,text="l",command='print("l",end="")')
frame3 = Frame(top)
btn20 = Button(frame3,text="z",command='print("z",end="")')
btn21 = Button(frame3,text="x",command='print("x",end="")')
btn22 = Button(frame3,text="c",command='print("c",end="")')
btn23 = Button(frame3,text="v",command='print("v",end="")')
btn24 = Button(frame3,text="b",command='print("b",end="")')
btn25 = Button(frame3,text="n",command='print("n",end="")')
btn26 = Button(frame3,text="m",command='print("m",end="")')
btnArr1 = [btn,btn2,btn3,btn4,btn5,btn6,btn7,btn8,btn9,btn10]
btnArr2 = [btn11,btn12,btn13,btn14,btn15,btn16,btn17,btn18,btn19]
btnArr3 = [btn20,btn21,btn22,btn23,btn24,btn25,btn26]
for x in range(0,len(btnArr1),1):
btnArr1[x].pack(side=LEFT)
frame1.pack()
for x in range(len(btnArr2)-1,-1,-1):
btnArr2[x].pack(side=RIGHT)
frame2.pack()
for x in range(len(btnArr3)-1,-1,-1):
btnArr3[x].pack(side=RIGHT)
frame3.pack()
top.mainloop()
When I run it, it does nothing. I tried using the plain code without the single quotes, and I tried using an exec() statement in the command parameter. Both tries failed.
I am using python 3.6.2
If anyone has any idea why this is, I would love to hear what you have to say. Thank you for your time!
The command= option requires a function or other callable object - a string does not qualify. You could try command=lambda: print("q",end="") to create such a function for each button.

How to get rid of lmer warning message?

I have made some changes to the lmer. It works as it should but I could not get rid of the warning message that pops when I run the program. I have added the following options which allows the program run without stopping but with the warning message. I believe it is the check.nobs.vs.rankZ = "warningSmall" part. How could I get rid of this, any suggestions? Thank you.
lmerControl(check.nobs.vs.nlev = "ignore",check.nobs.vs.rankZ =
"warningSmall",check.nlev.gtreq.5 = "ignore",check.nobs.vs.nRE="ignore",
check.rankX = c("ignore"),check.scaleX = "ignore",check.formula.LHS="ignore",
## convergence checking options
check.conv.grad = .makeCC("warning", tol = 1e-3, relTol = NULL),
check.conv.singular = .makeCC(action = "ignore", tol = 1e-4),
check.conv.hess = .makeCC(action = "warning", tol = 1e-6)
Warning Message from R:
Warning message:
In checkZrank(reTrms$Zt, n = n, control, nonSmall = 1e+06) :
number of observations (=300) <= rank(Z) (=300); the random-effects parameters and the
residual variance (or scale parameter) are probably unidentifiable
You should try check.nobs.vs.rankZ="ignore".
lmerControl doesn't need to specify anything other than the non-default options: at a quick glance, these are your non-default values:
lmerControl(check.nobs.vs.nlev = "ignore",check.nobs.vs.rankZ =
"ignore",check.nlev.gtreq.5 = "ignore",check.nobs.vs.nRE="ignore",
check.rankX = c("ignore"),
check.scaleX = "ignore",
check.formula.LHS="ignore",
check.conv.grad = .makeCC("warning", tol = 1e-3, relTol = NULL))
In general I would suggest it's wise to turn off only the specific warnings and errors you know you want to override -- the settings above look like they could get you in trouble.
I haven't checked this since you didn't give a reproducible example ...

Resources