Sublime Text 3 auto-Indentation with comments - sublimetext3

I have been using ST3 to write python for a while, but the auto-indentation has confused me sometimes.
I am currently writing a python function and I noticed that if there is a comment at the end of a line of code, the auto-indentation by pressing enter at middle of the line won't work. For example, I have the following lines:
fig = plt.figure(num = 0, figsize = (10,10))
fig = plt.figure(num = 0, figsize = (10,10)) #This creates a figure
By pressing 'Enter' before 'figsize' in both lines, the first line would auto-indent while the second wouldn't:
Indent Issue Image
Does anyone has any solution to this? I can add the comment after using the indentation but it is always a fuss to do this.

Related

tkinter - Hebrew text changes order mid-text

So I got this weird issue where I simply want to display a Hebrew text (with special characters, accents, diacritics, etc.) on a Label.
lines = None
with open("hebrew.txt", encoding="utf-8") as f:
lines = f.read().split("\n")
window = Tk()
lbl = Label(window, text=lines[11], font=("Narkisim", 14))
lbl.grid(column=0, row=0)
window.geometry('850x200')
window.mainloop()
Hebrew is a RTL language. The thing is - up until a specific length of the line - it displays correctly. But once the line is longer than that length, the next words appear to the right of the text (in English, think of it as if words started appearing to the left of the text instead of each word being the right-most). This only happens with lines over a certain length... (e.g. if I do text=lines[11][:108] it's still good. The "good" length changes a bit from line to line.
This only happens with all nikkud/diacritics/accents. If I use regular Hebrew text without these special characters - it's all good. Any ideas what could be the issue? It's driving me crazy.

PIL Drawing text and breaking lines at \n

Hi im having some trouble getting sometimes longer texts which should be line breaked at specific lines onto an image it always just prints the \n with it without breaking the line and i cant find any info online if this is even possible or if it just sees the raw string to put on the img without checking for linebreaks. The Text is just some random stuff from a CSV
def place_text(self,text,x,y):
temp = self.csv_input[int(c)][count]
font = ImageFont.truetype('arial.ttf', 35) # font z.b.: arial.ttf
w_txt, h_txt = font.getsize(text)
print("Jetzt sind wie in der zweiten möglichkeit")
draw_text = ImageDraw.Draw(self.card[self.cardCount])
draw_text.text((x, y), temp, fill="black", font=font, align="left")
Yeah i know this Code is kinda all over the place but for putting the text on the image that shouldnt cause any issues does it?
Writing stuff on an Imgae with that results in just one line of continuous text with the \n's still in there and no line breaks.
Found the answer the String pulled fomr the CSV had to be decoded again before beeing placed
text = bytes(text, 'utf-8').decode("unicode_escape")
did the trick

How to begin highlighting words

I am writing an app of a Python editor of my own. I am using a Text widget and want to highlight words as the words are typed in like Python editor. As soon as the character # is typed in, I want to begin highlighting all characters followed from the character # with color of red.
Below is the partial code for the purpose. When the character # was identified as it was typed in to the Text widget, I added a tag of "CM" from the typed-in-character to the end of the line (I thought this would do the job for me).
import tkinter as tk
def onModification(event=None):
c=event.char
if not c: return
pos=hT0.index(tk.INSERT)
if c=='#':
hT0.tag_add('CM',pos,f'{int(pos.split(".")[0])}.end')
return
hW=tk.Tk()
hT0=tk.Text(hW,wrap='none',font=('Times New Roman'12))
hT0.insert('end','')
hT0.place(x=27, y=0, height=515,width=460)
hT0.bind('<Key>', onModification)
hT0.tag_config('CM', foreground='#DD0000')
But the output highlights only characters already existed even without the just-typed-in-character #.
An idea for the job I want?
Thank you so much in advance.
I obtained an idea from the Get position in tkinter Text widget
def onModification(event=None):
...
pos=hT0.index(tk.INSERT)
lineN, ColN=[int(c) for c in pos.split('.')]
if c=='#':
#hT0.tag_add('CM',pos,f'{int(pos.split(".")[0])}.end')
hT0.tag_add('CM',f'{lineN}.{ColN-1}',f'{lineN}.end')
return
...
#hT0.binds('<key>', onModification) needs to be changed to...
hT0.bindtags(('Text','post-class-bindings','.','all'))
hT0.bind_class('post-class-bindings', '<KeyPress>', onModification)

Why does Vim indent every line once more when I copy and paste text from my browser to a file?

Why do I get this when I copy some text from a browser window into a file I'm editing with Vim? How do I get the lines to line up properly?
from django.db import models
from django.contrib.gis.db import models
# Create your models here.
class WorldBorder(models.Model):
# Regular Django fields corresponding to the attributes in the
# world borders shapefile.
name = models.CharField(max_length=50)
area = models.IntegerField()
pop2005 = models.IntegerField('Population 2005')
fips = models.CharField('FIPS Code', max_length=2)
iso2 = models.CharField('2 Digit ISO', max_length=2)
iso3 = models.CharField('3 Digit ISO', max_length=3)
un = models.IntegerField('United Nations Code')
region = models.IntegerField('Region Code')
subregion = models.IntegerField('Sub-Region Code')
lon = models.FloatField()
lat = models.FloatField()
# GeoDjango-specific: a geometry field (MultiPolygonField)
mpoly = models.MultiPolygonField()
# Returns the string representation of the model.
def __str__(self): # __unicode__ on Python 2
return self.name
You probably have either autoindent or cindent on. When you have one of those options on, Vim doesn't know the difference between the newlines that get pasted into the terminal and those you enter yourself. Therefore, when you paste a newline, Vim indents the line, and then you also paste whitespace providing an additional indent, and so on with the next line, until you're much farther over on the screen than you want.
The solution is to use :set paste to set paste mode and then paste, then :set nopaste to turn paste mode off. While in paste mode, Vim doesn't autoindent lines, so pasting a large number of lines into the terminal doesn't cause ever-increasing indents.
If you have a Vim with clipboard support on your particular platform, you can also paste using the "* and "+ registers (e.g. with "*p to paste), which won't have that problem, either.

Integrating a LCD Display in a widget that shows the line number of the textEdit

I want to get the line number of a textEdit in pyqt when the mouse cursor is clicked on a particular line . Kindly suggest
Maybe this gives you an idea:
self.connect(self.ui.textEdit, QtCore.SIGNAL("cursorPositionChanged()"),self.lineNumber)
and later:
def lineNumber(self):
# we try to get the lineNumber on change of cursor position
theLineNumber = self.ui.textEdit.textCursor().blockNumber()
self.ui.label.setText('Ln : '+str(theLineNumber))

Resources