I am creating a text box using vba in powerpoint. For that I am using the following code:
Set survey = cSlide.Shapes.AddTextbox(msoTextOrientationHorizontal, 20, 40, 400, 20)
survey.TextFrame.TextRange.text = Me.QuestionBox.text
survey.TextFrame.TextRange.font.SIZE = sh.GroupItems(1).TextFrame.TextRange.font.SIZE
survey.TextFrame.TextRange.font.name = sh.GroupItems(1).TextFrame.TextRange.font.name
survey.width = sh.GroupItems(1).width
survey.height = sh.GroupItems(1).height
survey.top = sh.GroupItems(1).top
survey.left = sh.GroupItems(1).left
As you can notice I am using the size of another shape to make it the same size as it. This is how the shape that I am using (above) and I created (below) looks:
I want it to appear in 2 lines instead of one. You can see that the width and height is correct but instead of going to the second line when it reach to the border of the shape it continues. If you just modify manually the shape below and give a bit more or less width it automatically put the second word in the second line but I cannot make it happen when I do it with vba. Is there something I can use to make it happen automatically?
When you add new shape to the slide, your shape default settings may be preventing wordwrap.
Please try:
survey.TextFrame.WordWrap = msoTrue
Related
I am trying to do rotation on multiple images in a folder but I am having this error when I put values of fx, fy greater than 0.2 in the resize function
(cv2.error: OpenCV(4.1.2) ... error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize')
Although, when I try to rotate a single image and put values of fx and fy equal to 0.5, it works perfectly fine.
Is there a way to fix this issue because it is very hectic to augment images one by one? Plus the multiple images which are rotated by the code attached here, with fx and fy values equal to 0.2, have undesirable dimensions i.e the photos are very small and their quality is also reduced.
the part of code for rotation of multiple images is given below:
for imag in os.listdir(source_folder):
img = cv2.imread(os.path.join(source_folder,imag))
img = cv2.resize(img, (0,0), fx=0.5, fy=0.5)
width = img.shape[1]
height = img.shape[0]
M = cv2.getRotationMatrix2D((width/2,height/2),5,1.0)
rotated_img = cv2.warpAffine(img,M,(img.shape[1],img.shape[0]))
cv2.imwrite(os.path.join(destination_right_folder, "v4rl" + str(a) + '.jpg') , rotated_img)
#cv2.imshow("rotated_right",rotated_img)
#cv2.waitKey(0)
a += 1
Add a check after you read the image to see if it is None:
img = cv2.imread(os.path.join(source_folder,imag))
if img is None: continue
The error is happening when you call the cv2.resize() function. Maybe files are being read that are not images.
I am attempting to open one file, see if cells have color fills, and copy the coordinate and fill information to a dictionary. Then, I want to iterate over the dictionary to copy the formatting into the same coordinates in a different document. (This may not be the best way to accomplish this)
def color_collect(wb): # This collects colors from cell coordinates
color_data = OrderedDict()
for sheetcount, wksht in enumerate(wb.worksheets):
color_data[sheetcount] = {}
for row in wksht:
for cell in row:
coord = cell.coordinate
coordcolor = cell.fill.start_color.index
if coordcolor != '00000000':
color_data[sheetcount][coord] = coordcolor
return color_data
def color_write(wb, color_data): # This adds color to cell coordinates
print color_data
for idx, sheet in enumerate(wb):
print idx
for cell in color_data[idx]:
print cell
coloridx = color_data[idx][cell]
print coloridx
sheet[cell].fill.start_color.index = color_data[idx][cell]
Running this gives this result:
sheet[cell].fill.start_color.index = color_data[idx][cell]
AttributeError: can't set attribute
Some notes: the index color is crucial because I use the index color to import the color-coded data into PowerPoint. If the index isn't properly applied, the data is not recognized later, so solutions that use plain RGB fills aren't super useful.
Any assistance would be helpful
This is best done by copying styles
Something like sheet[c1].fill = copy(c2.fill)
Below code is not centralizing text no error in code, but i want to centralize text.
import os
unicode_text = u"\u0627\u0628\u067E"
list_of_letters = list (unicode_text)
char = u''.join(word)
t1 = arabic_reshaper.reshape(char)
W,H= (32, 32)
img= PIL.Image.new('RGBA', (W, H), (255, 255, 255),)
draw = PIL.ImageDraw.Draw(img)
font = PIL.ImageFont.truetype( r"C:\Downloads\arabic.ttf", 15)
t2 = get_display(t1)
w, h = draw.textsize(t2.encode('utf-8'))
draw.text(((W-w)/2,(H-h)/2), t2, fill="#000000", font=font)
Your code does not center correctly because it does not retrieve the actual character width and height. You can see that if you print out the character sizes that textsize returns and then change the font size. You still get the same character sizes!
Why does it not change? Because you load a font but then don't use it for measuring. If you set it inside the draw object, or add font=font to both draw.textsize and draw.text, it works as expected.
(Just doing that gives an error on the original textsize line; possibly you attempted to fix the issue in an unrelated way by adding .encode('utf8). But that is not necessary.)
draw = PIL.ImageDraw.Draw(img)
draw.font = PIL.ImageFont.truetype( "times.ttf", 48)
t2 = get_display(t1)
w, h = draw.textsize(t2)
draw.text(((W-w)/2,(H-h)/2), t2, fill="#000000")
print ("char: %04X w %d h %d" % (ord(char),w,h))
This results in correctly centered characters throughout, the same for both Latin and Arabic letters.
I want to resize my text in plot_net but none of the options are working for me. I am trying
p <- plot_net(physeqP, maxdist = 0.4, point_label = "ID", color = "Cond", shape = "Timeperiod") p + geom_text(size=15)
This gives me error
"Error: geom_text requires the following missing aesthetics: x, y,
label".
Can anyone please tell me how can I fix the issue?
I dont want to resize legends or the axis, but the nodes text.
this image is drawn using phyloseq but since the font size is very small, i want to make it prominent.
Without an example it's hard to reproduce.
p <- plot_net(physeqP, maxdist = 0.4, point_label = "ID"
, color = "Cond", shape = "Timeperiod", cex_val = 2)
I believe this is with the NeuralNetTools package.
Try using: cex_val numeric value indicating size of text labels, default 1
https://www.rdocumentation.org/packages/NeuralNetTools/versions/1.5.0/topics/plotnet
How do you fade out/in a button in VB.NET properly? I can fadeout/in labels using:
Controls(i).ForeColor = Color.FromArgb(255, alpha, alpha, alpha)
(where Controls(i) is a label from a For Next loop through all controls in Me.Controls; alpha is the value of the RGB, also from a For Next loop).
This did not work for me with buttons because changing the ForeColor leaves the rest of the buttons' UIs visible!
So, the way I'm trying uses a saved Resource image of the button (from a screenshot) and creates a faded in/out version to be displayed as the image in a PictureBox:
Public Function SetImageOpacity(ByVal imgPic As Image, ByVal imgOpac As Double) As Image
Dim bmpPic As New Bitmap(imgPic.Width, imgPic.Height)
Dim grPic As Graphics = Graphics.FromImage(bmpPic)
Dim imgAtt As New ImageAttributes()
Dim cmxPic As New ColorMatrix()
cmxPic.Matrix33 = imgOpac
imgAtt.SetColorMatrix(cmxPic, ColorMatrixFlag.[Default], ColorAdjustType.Bitmap)
grPic.DrawImage(imgPic, New Rectangle(178, 144, bmpPic.Width, bmpPic.Height), imgPic.Width, imgPic.Height, imgPic.Width, imgPic.Height, GraphicsUnit.Pixel, imgAtt)
grPic.Dispose()
imgAtt.Dispose()
Return bmpPic
End Function
(where imgPic is the Resource image of the button, and imgOpac is the opacity on a scale of 1 to 0, where 0 is transparent).
I then use this image to set my PictureBox's image:
picbox.Image = SetImageOpacity(My.Resources.Nextbutton, 1)
However, I get a glitch where, even though the PictureBox is located at coordinates 178, 144, the image it is showing is displayed at the left edge of the form (i.e. wrong X coordinate), with the Y coordinate correct!
I have a feeling it may lie with my call of .DrawImage(...) (at line 8 of the function) - but the MSDN docs on this subject are very unclear to me.
Please link if this has been asked before!
The coordinates in the Graphics grPic are client coords relative to the image itself, not the Form. So (0, 0) is the top left of the image regardless of where that image ends up being displayed in some kind of control.
Try changing it to (0, 0):
grPic.DrawImage(imgPic, New Rectangle(0, 0, bmpPic.Width, bmpPic.Height), imgPic.Width, imgPic.Height, imgPic.Width, imgPic.Height, GraphicsUnit.Pixel, imgAtt)
why not just use a for loop to change the opacity of the button control from 1 to 0 in increments of say .01 ?