I thought that in the 21st century this is not a problem, but:
import sys
from PySide import QtGui
print('\u2122')
app = QtGui.QApplication(sys.argv)
widget = QtGui.QWidget()
widget.setWindowTitle('\u2122')
widget.show()
sys.exit(app.exec_())
on Ubuntu displays the trademark symbol in both the window and the terminal, on Windows (10) it displays \u2122 both places. I am using python 3.4 on both systems, on windows it's an Canopy install, if that helps anything, but probably totally unrelated to that. How can I get unicode characters to display on Windows as well?
EDIT
Okay, so it turned out that having print() doesn't make it python 3, my bad. Although the Windows python 2.7.9 gives an interesting error when I fix the strings to u'\u2122:
File "C:\Program Files\Enthought\Canopy32\App\appdata\canopy-1.5.5.3123.win-x86\lib\encodings\cp852.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\u2122' in position 0: character maps to <undefined>
Anyway, installing a 3.x will solve the issue.
Ensure that you have Python 3.x on your Windows box. The results are consistent with using Python 2.x.
To make your code with 2.x, change the strings into Unicode strings by appending a u to each one. E.g.
widget.setWindowTitle('\u2122')
On Windows, don't try to print Unicode to the console - it's totally broken. If you must, see the following module which allows it: https://github.com/Drekin/win-unicode-console
Related
How do I set an application's taskbar icon in PyQt4?
I have tried setWindowIcon, and it successfully sets the icon in the top-left of the main window, but it does not affect the icon shown in the Windows 7 taskbar -- the taskbar icon remains the default Python pyw icon. Here is my code:
from PyQt4 import QtGui
app = QtGui.QApplication([])
mainwindow = QtGui.QMainWindow()
mainwindow.show()
app.setWindowIcon(QtGui.QIcon('chalk.ico'))
mainwindow.setWindowIcon(QtGui.QIcon('chalk.ico'))
app.exec_()
[update] I've tried placing the setWindowIcon() before the show(). I've tried it with other images, ico and png. Nothing helps.
I've found the answer, after some digging.
In Windows 7, the taskbar is not for "Application Windows" per se, it's for "Application User Models". For example, if you have several different instances of your application running, and each instance has its own icon, then they will all be grouped under a single taskbar icon. Windows uses various heuristics to decide whether different instances should be grouped or not, and in this case it decided that everything hosted by Pythonw.exe should be grouped under the icon for Pythonw.exe.
The correct solution is for Pythonw.exe to tell Windows that it is merely hosting other applications. Perhaps a future release of Python will do this. Alternatively, you can add a registry key to tell Windows that Pythonw.exe is just a host rather than an application in its own right. See MSDN documentation for AppUserModelIDs.
Alternatively, you can use a Windows call from Python, to explicitly tell Windows what the correct AppUserModelID is for this process:
import ctypes
myappid = 'mycompany.myproduct.subproduct.version' # arbitrary string
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
EDIT: Please see Ronan's answer: the myappid string should be unicode.
#DamonJW's answer will work, but there is a minor catch: myappid should be unicode (argument type is PCWSTR).
import ctypes
myappid = u'mycompany.myproduct.subproduct.version' # arbitrary string
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
Otherwise getting the AppUserModelID will get wrong unicode characters (祭潣灭湡祭牰摯捵畳灢潲畤瑣瘮牥楳湯):
import ctypes
from ctypes import wintypes
lpBuffer = wintypes.LPWSTR()
AppUserModelID = ctypes.windll.shell32.GetCurrentProcessExplicitAppUserModelID
AppUserModelID(ctypes.cast(ctypes.byref(lpBuffer), wintypes.LPWSTR))
appid = lpBuffer.value
ctypes.windll.kernel32.LocalFree(lpBuffer)
if appid is not None:
print(appid)
That said, it is a minor thing, since Windows will still recognize the unicode string as "another process" and switch the icon accordingly.
You must set the AppUserModelID before your app shows any GUI. If you need to access other Windows 7 features you can have a look at Q7Goodies which is a Qt add-on for Windows 7 with a PyQt bindings.
Lately, whenever I launch RStudio, the XQuartz app also automatically launches. How can I stop this from happening? (It's annoying!)
The only thing I could find related to this issue was this stackoverflow question: loading ggplot2 (colorspace, actually) opens up x11. (I do have the colorspace package installed [v. 1.3-2] but for me XQuartz starts up immediately upon starting RStudio, not after a particular library is loaded.)
This behavior started very recently, possibly corresponding to the installation of the package sqldf, which does appear to force-open the XQuartz app when it's loaded, although I don't know how it could be causing XQuartz to open before the library is even loaded into the current session. I also tried deleting the .RData and .Rhistory files in my working directory and restarting RStudio, but it didn't help.
Version and system information:
RStudio Version 1.1.453
> sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.5
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.5.0 tools_3.5.0
OP here. Seems like the issue I was having stopped on its own. Updating to RStudio version 1.1.456 and/or R version 3.5.1 may have helped.
This is still happening to me on OS X with RStudio 1.4.1103, R 4.0.2, sqldf v0.4-11 and gsubfn v0.7. It happens immediately upon loading sqldf (which has gsubfn as a dependency).
Based on a hint from this Twitter thread, I figured out that if I run this line before loading sqldf, I can bypass loading the loading of XQuartz:
options(gsubfn.engine = "R") # This stops the loading of XQuartz on Mac
Including options(rgl.useNULL = TRUE) in my .Rprofile solved the problem for me. The quote below from the rgl vignette explains why it suggests this:
Default display
There are two ways in which rgl scenes are normally displayed within R. The older one is in a dedicated window. In Unix-alikes this is an X11 window; it is a native window in Microsoft Windows. On macOS, the XQuartz system (see https://www.xquartz.org) needs to be installed to support this.
To suppress this display, set options(rgl.useNULL = TRUE) before opening a new rgl window. See the help page for the rgl.useNULL function for how to set this before starting R.
The newer way to display a scene is by using WebGL in a browser window or in the Viewer pane in RStudio. To select this, set options(rgl.printRglwidget = TRUE). Each operation that would change the scene will return a value which triggers a new WebGL display when printed.
When I open python documentation, i see strange words :
'16.3. time � Time access and conversions','What뭩 New in Python'
like this.
(뭩 is korean word that means nothing. I'm korean student.)
enter image description here
Why are these happening?
Help me to fix this error.
Assuming you are using Windows:
I have seen this happen with my Chinese Windows set up. This would resolve if you change your Windows set up to English. This seems to be some sort of font error. Once you set your primary language to English, this should resolve. If not, reinstall python after setting language to English.
I maintain a PowerBuilder Classic 12.5 application which has functionality to print checks on a Source Technologies MICR printer. The application has been running fine in a Windows XP environment. We are trying to move to a Windows-7 operating system and the check printing no longer works.
Here is the issue. PowerBuilder issues a PrintOpen followed by several Print commands to send command strings to the printer to unlock MICR mode and various secure fonts:
il_job = PrintOpen( )
Print(il_job,'&%STF[password]$')
Print(il_job,'&%SMCPFFFF$')
Print(il_job,'&%STP10003$')
Print(il_job,'&%STP10002$')
Print(il_job,'&%STP10001$')
Print(il_job,'&%1B$&u600D')
Print(il_job,'&%1B$*t600R')
This works fine on XP, and if you redirect the printer to "print to file", you can see the command strings right there in the file.
In Windows-7, the printer does not recognize the command strings, and in fact, just prints the commands on the check stock. If you do the same "print to file", you can see the commands in there, but each character in the command string is separated by other characters.
The following is a sample taken from the "print to" file, and you can see the string '&%SMCPFFFF$' by looking at each character that precedes an asterisk (*).
*p171Y&*p50X%*p100XS*p150XM*p200XC*p250XP*p300XF*p350XF*p400XF*p450XF*p500X$
This would seem to be a print driver issue, and in fact, Source Technologies now provides a "Universal Print Driver" which we have been told to use. Our PC support person was able to get the check printing working temporarily by re-installing the old print driver that we used on Windows XP, but as soon as the printer is turned off and on again, it resets to the new universal driver.
I tried using PrintDefineFont and PrintSetFont, to set the font to Courier Regular 8pt (which is what the Tech Support guy at Source Technologies told us we needed), but that didn't help:
PrintDefineFont(il_job, 1, "Courier", -8, 400, Fixed!, AnyFont!, FALSE, FALSE)
PrintSetFont(il_job, 1)
Can anyone help me with this issue? Or suggest where I might get help.
Thanks.
Try this: Add a new printer. Select the port your printer is connected to. Select Manufacturer: Generic, Printer: Generic/Text only. When you print to this printer it should send exactly what's in your Print statements to the printer.
Thanks Hugh, I tried your suggestion which sounded good, but unfortunately it had no effect.
As it happens, as of yesterday I did resolve the last of the printing issues. I had to address each of the special fonts (micr line, signature, check amount etc.) individually, and used a combination of using PrintDefineFont/PrintSetFont, embedded printer command strings to reset the font, and changing a Column control in the datawindow to a Text control (a printer command string is moved into this field as well as the data, and the one worked, the other didn't).
Appreciate your help.
Les
Please right click on your software and go to compatibility mode and select "Windows XP with SP3" in it, click APPLY and OK.
Confirm if the software now send print commands perfectly?
This is really weird. I generate pdf using mpdf. I had no problem with printing pdfs. But suddenly this problem appeared. Not sure it is something to do with change of my code or updating my operating system or wireless printer printer.
System-------------Application-------Result
OS X 10.8.2---------Preview----------can't print
OS X 10.8.2---------Acrobat----------can print
OS X 10.7.x----------Reader----------can't print
Windows XP-----Reader/Dont know----can print
OS X 10.X.X---------Preview---------can't print
Some information:
We was able to print pdf before. There wasn't any complain from any OS/person.
I was working on some sql query changes. But I undo my things. still not working.
So what it says when someone try to print using "Preview"
-On my macbook pro it says (Printing - Connected to printing. and stays like this)
-Probably on other mac it also shows like happening something...but nothing happens.
FYI we don't get any confirmation like....printing completed....it is like printing..and printing.
There was a application PDFRepair. And after repairing with this application. I can print my pdf. But problem is its not freeware and quality is not good.
Maybe it is broken/damaged content issue.
Goal: Goal is print our pdf files with "Preview"
Any kinds of help or suggestions will be highly appreciated.
Finally solved. That was something to do with mPDF CMap resource stuffs. But it happens with only mPDF older version. In my case it was mPDF 5.0 Beta.
Using mPDF latest version will solve this problem. Now I can print my exported pdf from any OS and any application. Cheers