Alignment of TextCtrl - python-3.x

I have newly set up Linux Mint in my computer and learning wxpython(just because I was bored of tkinter and needed some rest from the headaches i got from creating large applications on it). I learned about first command 'TextCtrl'. Every thing works except I have a bit problem. the code is simple.
panel = wx.Panel(self)
wx.TextCtrl(panel, position=(10, 10), size=(250,150)
the code works fine except when I run it the cursor and the text appears to be in the middle(like vertically middle). Searched the damn internet, never found a simple solution. any guesses how can i align in to top in a single line of code?
screenshot

I think wx.Python will automatically align the text to the center in the vertical direction. If you need a wx.TextCtrl that big, I guess you want a multiline wx.TextCtrl. This you can get with the style parameter:
wx.TextCtrl(panel, position=(10, 10), size=(250,150), style=wx.TE_MULTILINE)

Related

How Can I Fix Inconsistent Text Downscaling with a Rich Text Label In Godot?

I have a rich text label that works fine under a resolution of 1920x1080. However, when scaled down to the resolution on my laptop, which has a 1366x768 resolution, the text on said label becomes janky and malformed.
Some lines are cut off at the top or the bottom, and others are squished (as you can see in the image at lines 3, 6, and 13).
I'm using Godot v3.5.1 and the text font is Noto Sans Regular from here
I tried enabling mipmaps, using the filter, disabling anti aliasing, disabling font oversampling and enabling GPU pixel snap under Project Settings > Rendering > 2D > Snapping. And out of all of those, only the pixel snap setting worked. Completely fixes the issue and the text is rendered properly.
However, this completely breaks an animation of a spinning circle that plays at basically all times during the actual gameplay. It becomes stuttered and shakes instead of the normally smooth animation it has otherwise. I realize this may possibly be fixed by using SVG instead of PNG sprites, but I feel like that's not an ideal solution in case other sprites get added. Especially since my game will also allow community members to add their own sprites for their own game play.
So is there any way to fix the text without breaking the animations, or make it so that the animations don't break with pixel snap enabled?

Getting rid of border on tkinter label

In my most recent posting, the code does exactly what I need it do...is there a way to get rid of the border/lighter gray area around the label? I want to only see the text.
Splitting tkinter canvas and frame apart
I have tried changing the label code to
v = Label(s, bg='gray',fg='black',borderwidth=0,highlightthickness=0,highlightcolor='gray',relief='sunken',anchor='w')
This still leaves the side borders that can be plainly seen in the code at the above link. I just inserted relief cause I saw someone else's post using it and thought I would give it a try versus leaving the relief flat as set by default. Made no difference.
How do I get rid of the light gray sides that are appearing on the Label. I know this is about to really become important probably as soon as this evening or tomorrow morning.

Pygame Shooting Bullets

Recently ive been trying to create a small game using Pygame, Ive managed to display an image which can move side to side, the trouble ive been having is enabling it to fire bullets using the space bar.
Heres my code so far:
http://pastebin.com/24xDYwY7
Ive now got the bullet to display however it doesnt come out from the "turret.png", and just sits in the top left of the screen.
Is anyone able to help me with this? I am extremely new to python and would appreciate the help
It looks like you're using a technique I like employing in PyGame - using different sprite Groups for separating good guys, bad guys, bullets, blocks, etc… with a single unified 'all the things' Group.
What I don't see is the all_sprites.update() call that makes the whole thing work, though I do see player.update(). PyGame groups are designed to let you call group.update() in place of a for x in y call such as:
for sprite in my_sprites:
sprite.update()
EDIT: Not seeing your images in the right place? If they're being set to the upper-left corner, this is usually because nothing is setting the surface of the drawn image to appear where you want it to.
One thing I've found handy about PyGame's get_rect() call is that it allows you to pass arguments to set attributes of the rect you get back. For example, my sprite.draw(self) methods tend to look something like this:
def draw(self):
"""Sets the image's Rect to the middle of the sprite,
then blits to the screen.
"""
draw_rect = self.drawn_image.get_rect(center=self.rect.center)
SCREEN.blit(self.drawn_image, draw_rect)
This assumes that the sprite object's self.x and self.y are being updated correctly as well, but it's essentially the right thing to do; get the rect for the object you're drawing, set it to the right coordinates just as you do the actual sprite, then pass the image and the rect to SCREEN.blit().

NSAttributedString: wrapping + truncation

I have a view that draws multicolored text inside UITableViewCell. To draw multicolored text I'm using NSAttributedString However, I would like to make it so that if the text is too long to fit into the view, the last visible line is truncated to display an ellipsis at its end.
Obviously this is very easy to do when drawing only a single line, as you can just set
kCTLineBreakByTruncatingTail for the line break mode of the paragraph style. The problem is that I want my text to wrap to fill the rectangle, and then only have the last line truncated with an ellipsis - setting the line break mode confines the whole text to one line.
Does anybody have any ideas of how I would go about this?
Many thanks in advance for any suggestions,
JC.
Create your CTFrame from your CTFrameSetter with the rectangle of your UITableViewCell. Then, you can get all the CTLines of your CTFrame and determine when they will cut off. To swap out the ellipsis, you could keep that drawn with a separate CTFrame and draw it over the overflowing text on the last line.
You can find working code here: https://stackoverflow.com/a/14612598/473067
It's a similar approach to what Heath suggested. But then all wrapped up in a shiny package.
Well, to activate text truncating in UILabel, you should re-set lineBreakMode parameter to NSLineBreakByTruncatingTail after setting attributedText.
textLabel.attributedText = attributedText;
textLabel.lineBreakMode = NSLineBreakByTruncatingTail;

LaTeX: How to make a fullpage vertical rule on every page?

I'm using LaTeX and I would like to have vertical rule along left side of page, topmargin to bottommargin, 0.5in from the left edge of the page. I want this on every page, so I assume that means it must somehow be tied to the header or the footer?
I've made no progress at all, so I need help with (1) making the full-length rule itself and (2) making it happen automatically on every page of the document.
Can someone tell me how to do that?
I got a working answer to my question on the Latex Community forum: http://www.latex-community.org/forum/viewtopic.php?f=5&t=9072&p=34877#p34877
The answer I got uses the 'Background' package and this code:
\documentclass{article}
\usepackage{background}
\usepackage{lipsum}% just to generate filler text for the example
\SetBgScale{1}
\SetBgAngle{0}
\SetBgColor{black}
\SetBgContents{\rule{.4pt}{\paperheight}}
\SetBgHshift{-9cm}
\begin{document}
\lipsum[1-90]
\end{document}
Works great and was easy to adjust to put one vrule in left margin area and one in the right margin area.
There could be a LaTeX package to do this for you, but I'm more of a TeX person, so I tried to come up with a TeX solution (not always the best idea to mix plain TeX with LaTeX but I think I have it working).
Try this. Box 255 is the box register that TeX places the page contents into before the page is output. What I've done is taken the existing output routine, and changed it to insert into box 255: a 0-height, 0-width infinitely shrinkable-but-overflowing set of boxes containing a rule that is the height of the page, 0.4pt thick and with any luck, half an inch away into the left. The existing contents of box 255 is then added after this rule. Then I call the previous output routine which outputs the page (which now includes a rule), and also the headers and footers.
\newtoks\oldoutput
\oldoutput=\expandafter{\the\output}%
\output{%
\setbox255\vbox to 0pt{%
\hbox to 0pt{%
\vsize\ht255%
\vbox to \ht255{%
\vss
\hbox to -0.5in{%
\hss
\vrule height \ht255 width 0.4pt%
}%
}\hss
}\vss
\box255%
}%
\the\oldoutput
}%
Put it before your \begin{document} command. This might not solve your problem completely, but hopefully it should get you started. Here's a great page for learning about TeX primitives and built-in things.
Have a look at the eso-pic package. From memory, what you want would look like this:
\AddToShipoutPicture{%
\setlength\unitlength{1in}%
\AtPageUpperLeft{%
\put(0.5,\topmargin){\vrule width .5pt height \textheight}%
}%
}
It's not clear in your question if you want the line to span the text area or the whole paper height. Depending on the case, you have to replace \topmargin and \textheight by the correct values, either 0pt or whatever your top margin is, or by \paperheight. See the geometry package if you don't already use it for how to control those dimensions.

Resources