Comments (13)
Original comment by vanquish-box (2011-05-02T01:38:18Z):
Sorry, I forgot to give version info.
Version 1.1.4
Problem occurs in both installer and portable version.
from rednotebook.
Original comment by vanquish-box (2011-05-02T01:56:54Z):
Bug #762942: Automatic input of time(Ctrl + D) is always 00:00
Just to add.... appened to see the above bug report. I am suffering from this as well.
from rednotebook.
Original comment by jendrikseipp (2011-05-03T12:09:10Z):
This code fragment should reproduce the problem:
def format_date(format_string, date=None):
if date is None:
date = datetime.datetime.now()
date_string = date.strftime(format_string)
# Turn date into unicode string
date_string = date_string.decode('utf-8', 'replace')
return date_string
import locale
locale.setlocale(locale.LC_ALL, '')
print format_date("%A %B", date=datetime.date(2011, 3, 1))
Does anyone have an idea about how to fix this unicode issue?
from rednotebook.
Original comment by jendrikseipp (2011-05-03T12:10:08Z):
For the above code to work you have to import "datetime" first.
from rednotebook.
Original comment by k-nielsen81 (2011-05-05T12:02:37Z):
This applies to a few Danish letters in weekend days as well (Lørdag, Søndag). The are not rendered correctly in the preferences dialog and in the automatically inserted weekdays in the exports, but they are rendered correctly in the preview and in the export content.
Since, as you know, I use Rednotenook as a log book at work, the obvious solution is off course for me to simply not work in the weekends ;)
I'll can reproduce the problem with the code above and will have a look at to see if I can figure it out.
PS: I'm assuming the export weekdays problem is related, else please inform me and I will make a separate report
from rednotebook.
Original comment by jendrikseipp (2011-05-05T12:30:18Z):
Am 05.05.2011 14:02, schrieb TLE:
I'll can reproduce the problem with the code above and will have a look
at to see if I can figure it out.
That would be great!
PS: I'm assuming the export weekdays problem is related, else please
inform me and I will make a separate report
Yes, this is the same issue, no separate report is needed.
from rednotebook.
Original comment by k-nielsen81 (2011-05-05T12:46:05Z):
Hmm, seems to be a windows only problem, at least the code works fine for me on Linux. The locales get set differently, but it think they ar esupposed to, so that is probably not the problem.
import locale
locale.setlocale(locale.LC_ALL, '')
locale.getlocale()
('Danish_Denmark', '1252')
on Linux:
import locale
locale.setlocale(locale.LC_ALL, '')
locale.getlocale()
('da_DK', 'UTF8')
from rednotebook.
Original comment by k-nielsen81 (2011-05-05T14:13:47Z):
I believe this solves it:
def format_date(format_string, date=None):
if date is None:
date = datetime.datetime.now()
date_string = date.strftime(format_string)
# Turn date into unicode object
date_string = date_string.decode(locale.getlocale()[1], 'replace')
return date_string
import locale
import datetime
locale.setlocale(locale.LC_ALL, '')
print format_date("%A %B", date=datetime.date(2011, 5, 1))
All right so I had a thought of what might be the problem, so I went to my local character set guru and talked with him about it: date.strftime returns a byte string object where the special characters are represented by several bytes according to the encoding set in locale, but it does not know anything about it. It is simply a byte string. So what decode does when called, is to return that byte string as a unicode object which is python internal unambigous string representation. Therefore, the argument that decode needs is not what you want out (that is always a unicode object), but the encoding of the byte string, which it does not know. And so the reason that it worked before in Linux is that here the byte string returned from strftime just happened to be in UTF8 since that is what is given in the locale (in most cases I gues, not sure about chinese).
In any case, if what you want returned from the function is a unicode object then the above will do the trick. If what you wanted was a UTF8 encoded byte string the you need to add .encode('UTF8') to the relevant line.
Regards Kenneth
PS: BTW i tested on both Linux and Windows, works great
PPS: I have not checked what the 'replace' argument does (but i can guess), so you have to make sure yourself that it is still right.
from rednotebook.
Original comment by askhl (2011-05-05T14:37:37Z):
What is the purpose of converting the date_string to unicode? strftime returns something locale-dependent, so that should be in the correct encoding already. By converting to unicode you are discarding that information, and when you print the unicode object, Python (or rather: the file object you are printing to) does not know anymore which encoding you want when it attempts to turn the unicode object back into bytes in order to print it. You either have to explicitly reconvert it back to the locale's encoding, or never convert to a unicode object in the first place.
Disclaimer: I think the above is true, but I didn't specifically test any of it. Some tinkering may be required.
from rednotebook.
Original comment by jendrikseipp (2011-05-05T15:33:39Z):
Awesome Kenneth, thank you very much for your help! I'll incorporate your fix as soon as time permits. This will make many WIndows people happy I guess :)
@ask: All internal text processing is done in unicode in RedNotebook. so the dates have to be in that format as well.
from rednotebook.
Original comment by askhl (2011-05-05T16:15:44Z):
Depending on what you do with the printed string, there can still be problems. Try running the example script when the output is piped into e.g. less or cat. It will complain, because stdout doesn't use the locale encoding unless you're printing to a tty (which can be very annoying).
For correct results, everything that you print should be explicitly encoded:
print some_unicode_object.encode(locale_encoding)
or you can use the codecs module to create a special file object to print to.
(I don't know whether you necessarily need to print to a tty, or if you are in reality passing the strings along to e.g. gtk; in the latter case it may not be necessary to do explicit encoding)
from rednotebook.
Original comment by k-nielsen81 (2011-05-06T07:54:19Z):
@jendrik: No problem
@ask: As far as I understand the strings are used by a webkit engine for the preview and the exports and for some module "save-simple-types-in-a-text-format kind of module (don't remember the name) for saving. So it probably isn't a problem.
from rednotebook.
Original comment by k-nielsen81 (2011-05-10T09:16:40Z):
Wuhu. I have helped with my fist ever free software bug.
from rednotebook.
Related Issues (20)
- Preview mode: Urls containing hashtags are broken and not styled properly HOT 1
- RedNotebook/KDE - keyboard freeze, sometimes KDE freeze HOT 1
- [feature request] Automatic/scheduled backups HOT 1
- Gdk-Errors on Preview, possibly also on Tag Cloud; KDE Plasma X11 HOT 1
- Debian Package Requires Incorrect Dependency; Warning report HOT 2
- Spellcheck doesn't handle apostrophes HOT 4
- lost all data after I asked it to remind me during my next session HOT 3
- Segmentation fault On Ubuntu 23.04 Wayland HOT 3
- Build option for the portable version? HOT 4
- Make rednotebook use the Installation different directory to save cfg, data and log files HOT 3
- Rednotebook crashes shortly after opening, HOT 2
- Fails to launch remotely with X11 forwarding HOT 2
- Preview and word cloud not show HOT 14
- After upgrade, can no longer copy in preview mode HOT 1
- Debians lintian nagging about build-backend. HOT 1
- Remove spellcheck.py and use distro supplied pygtkspellcheck. HOT 3
- Hashtags that happen to contain HEX characters (A - F) and are 6 characters or more are not captured as hashtags HOT 3
- hashtags not shown red in writing mode and bold not shown bold, if making a bullet point list HOT 1
- Change made in commit d2ffc80 - GPL-3.0+ HOT 1
- RNB buttons crash my Gnome session HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rednotebook.