PyQt4: QFileDialog and QFontDialog localization - localization

Subj: is it possible? For example, can I translate QtGui.QFileDialog().getSaveFileName() button "Save" to "Conservare", and "Cancel" to "Ignorare"? Is it possible to create my class based on QFileDialog/QFontDialog without inventing a velocity?
Someone said that these functions will be always translated, depending os system locale. Don't believe, my Russian version of OpenSUSE says that it is a lie. :-) And Russian Windows 7 has a such behaviour. All strings which I see on my systems are English. I'm not a nationalist, but I want to use strings in other languages. :-) Thanks!

A standard Qt installation should include 20 or so translation files for the Qt library itself.
An explanantion of how to use them can be found in this section of the Qt i18n docs.
Here's a basic PyQt4 example:
from PyQt4 import QtGui, QtCore
class Window(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self.buttons = QtGui.QDialogButtonBox(self)
button = self.buttons.addButton(QtGui.QDialogButtonBox.Open)
button.clicked.connect(self.handleOpen)
button = self.buttons.addButton(QtGui.QDialogButtonBox.Close)
button.clicked.connect(self.close)
layout = QtGui.QVBoxLayout(self)
layout.addWidget(self.buttons)
def handleOpen(self):
dialog = QtGui.QFileDialog()
dialog.exec_()
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
translator = QtCore.QTranslator()
if len(sys.argv) > 1:
locale = sys.argv[1]
else:
locale = QtCore.QLocale.system().name()
translator.load('qt_%s' % locale,
QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.TranslationsPath))
app.installTranslator(translator)
window = Window()
window.show()
sys.exit(app.exec_())

I've already found a solution: qm files. You can get them from ts files, using lrelease.

Related

Is there a way to override org-mode default exporting behavior?

I write my Beamer presentations for class in org-mode which I then export via the built in exporter to a LaTeX beamer presentation.
I know the default org-mode markup characteristics:
*bold* = \alert{bold}
/italics/ = \emph{italics}
+strike+ = \sout{strike}
=code= = \texttt{code}
~code~ = \texttt{code}
(Yes I am aware that ~ and = do different things, but they export identically for LaTeX purposes.)
What I would like is some way to either override one of the ~ or = syntax to export to \textcolor{example}{an example} Or perhaps to have another character that I can use for quick inline word or phrase size examples. Blocks I am happy to do with the #+BEGIN_EXAMPLE or similar syntax.
Is there an easy way to have that expand from a nice simple org-mode markup syntax?
The variable org-latex-text-markup-alist defines what happens when org exports the emphasised text. You can change specific markers to do what you want. For instance, I have customized this variable to be
'(org-latex-text-markup-alist
'((bold . "\\textbf{%s}")
(code . protectedtexttt)
(italic . "\\emph{%s}")
(strike-through . "\\hl{%s}")
(underline . "\\uline{%s}")
(verbatim . protectedtexttt)))
where I have strike-through changed to highlight the text instead of striking it through.

TextMobject doesn't work on Jupyter-Manim

I am currently using jupyter-manim since it is the most efficient way for me to use manim. I'm running my code on Kaggle and every time I use TextMobject in manim, it outputs an error that says Latex error converting to dvi. See log output above or the log file: media/Tex/54dfbfee288272f0.log. I've tried TexMobject and Text function, but only the Text function works. The Text function is limited however, and I'm not sure how to change the font. Is there a way to fix this or is it something that comes with using jupyter-manim? It seems that all the other functions work such as drawing shapes, animating scenes, etc.
%%manim
class Text(Scene):
def construct(self):
first_line = TextMobject('Hi')
second_line = TexMobject('Hi')
#Only one that works
third_line = Text('Hi')
I tried your Manim program and it worked as expected for me. I would try making sure
include from manimlib.imports import * in your first line (importing Manim library)
include self.play(...) so you can see them
I think you already have these, but I'm putting them in case you don't.
You may also be getting the error because you do not have a LaTeX distribution installed on your system (i.e. MikTex or Texlive).
I think part of your problem may be the name of the class you chose. I had problems with your code until I changed the name from Text to TextTest. Here is a minimally working example that works fine in my Jupyter notebook (after running import jupyter_manim of course).
%%manim TextTest -p -ql
from manim import *
class TextTest(Scene):
def construct(self):
first_line = TextMobject('Hi 1')
second_line = TexMobject('Hi 2').shift(DOWN)
third_line = Text('Hi 3').shift(UP)
self.add(first_line)
self.add(second_line)
self.add(third_line)
self.wait(1)
Also, you should be aware that TextMobject and TexMobject have been deprecated.

Using python to parse twitter url

I am using the following code but I am not able to extract any information from the url.
from urllib.parse import urlparse
if __name__ == "__main__":
z = 5
url = 'https://twitter.com/isro/status/1170331318132957184'
df = urlparse(url)
print(df)
ParseResult(scheme='https', netloc='twitter.com', path='/isro/status/1170331318132957184', params='', query='', fragment='')
I was hoping to extract the tweet message, time of tweet and other information available from the link but the code above clearly doesn't achieve that. How do I go about it from here ?
print(df)
ParseResult(scheme='https', netloc='twitter.com', path='/isro/status/1170331318132957184', params='', query='', fragment='')
I think you may be misunderstanding the purpose of the urllib parseurl function. From the Python documentation:
urllib.parse.urlparse(urlstring, scheme='', allow_fragments=True)
Parse a URL into six components, returning a 6-item named tuple. This
corresponds to the general structure of a URL:
scheme://netloc/path;parameters?query#fragment
From the result you are seeing in ParseResult, your code is working perfectly - it is breaking your URL up into the component parts.
It sounds as though you actually want to fetch the web content at that URL. In that case, I might take a look at urllib.request.urlopen instead.

How can I insert a file into another file when using the Spyder IDE?

When editing a file using the Spyder IDE editor I want to add the contents of another file, similar to what Emacs ctrl-x i does. For example:
main.py
import sys
def main():
help_text = """ ### external file contents go here ###"""
print(help_text)
if __name__ == '__main__':
sys.exit(main())
insertme.txt
Help text someone else gave me.
My desired result is a main.py looking like below (after file insertion and a little clean up):
import sys
def main():
help_text = """Help text someone else gave me."""
print(help_text)
if __name__ == '__main__':
sys.exit(main())
Going through help, online searches, etc. I can't find any direct way to do this (obviously I can do it other ways, but they are more time consuming). Is something like this directly possible with Spyder? If so, how?
(Spyder maintainer here) This is not possible in our editor, sorry.

Sublime text build system - how to auto open pdfs

I followed instructions provided here(How to create a shortcut for user's build system in Sublime Text?) to compile latex documents in xelatex, and on top of that I would also like it to automatically open pdf after compiling just like with latexmk, how can I achieve that? The document is built just fine, but I have to open it each time manually.
Here's an extension to the CompileWithXelatexCommand implementation that successfully opens the PDF in my default PDF viewer.
import sublime, sublime_plugin
import os
import time
class CompileWithXelatexCommand(sublime_plugin.TextCommand):
def run(self, edit):
if '/usr/texbin' not in os.environ['PATH']:
os.environ['PATH'] += ':/usr/texbin'
base_fname = self.view.file_name()[:-4]
pdf_fname = base_fname + ".pdf"
self.view.window().run_command('exec',{'cmd': ['xelatex','-synctex=1','-interaction=nonstopmode',base_fname]})
tries = 5
seconds_to_wait = 1
while tries > 0:
if os.path.isfile(pdf_fname):
break
time.sleep(seconds_to_wait)
seconds_to_wait *= 2
tries -= 1
os.system("open " + pdf_fname)
The polling loop is required; otherwise, the open call may happen before the PDF has been generated. There may be a cleaner way to synchronously exec a sequence of commands via run_command.
I don't have access to Windows now, but from this post you'll probably just need to change "open " to "start ". The PATH initialization logic will either need to be eliminated or adjusted.

Resources