-
-
SteppenwolfUA
@omz Hi, again! I did some reading of the Apple's docs and found there's a whole bunch of attributes with ..color.. component
NSString *const NSAttachmentAttributeName; NSString *const NSBackgroundColorAttributeName; NSString *const NSBaselineOffsetAttributeName; NSString *const NSExpansionAttributeName; NSString *const NSFontAttributeName; NSString *const NSForegroundColorAttributeName; NSString *const NSKernAttributeName; NSString *const NSLigatureAttributeName; NSString *const NSLinkAttributeName; NSString *const NSObliquenessAttributeName; NSString *const NSParagraphStyleAttributeName; NSString *const NSShadowAttributeName; NSString *const NSStrikethroughColorAttributeName; NSString *const NSStrikethroughStyleAttributeName; NSString *const NSStrokeColorAttributeName; NSString *const NSStrokeWidthAttributeName; NSString *const NSTextEffectAttributeName; NSString *const NSUnderlineColorAttributeName; NSString *const NSUnderlineStyleAttributeName; NSString *const NSVerticalGlyphFormAttributeName; NSString *const NSWritingDirectionAttributeName;
Setting the foreground color could be achieved by putting UIColor (which is basically NSColor via toll-free bridging if I'm not mistaken) as value for "NSColor" key in a Python dict. I wonder what would be the names for other predefined keys in the above list. Since you can't use "NSColor" as Python key for all color attributes, there obviously must be different key names for all keys with UIColor, NSNumber etc values.
Many thanks in advance
-
SteppenwolfUA
I'm just a bloody beginner and a Windows+iPad user to top it all ))) Still willing to learn and really happy to get support from gurus here! Thank you very much indeed!
-
SteppenwolfUA
Hi, @omz
As usual you saved my day!!!
The lesson learned here is I hit the compiled/interpreted language border and you can't always tranlate obj c apis to Python...
How did you figure out the correspondence of NSForegroundColorAttributeName and 'NSColor'? What have I missed here? Any tips?
Many thanks
-
SteppenwolfUA
Hi, all
I need a small example of how to use NSMutableAttributedString for attributed text property of UITextView. Can't set text attibutes, get crashes when playing with different options...
Thanx in advance
@on_main_thread def test_001(): red = UIColor.redColor() font = ObjCClass('UIFont').systemFontOfSize_(30.) mystring = ObjCClass('NSMutableAttributedString').alloc() teststring = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec tincidunt facilisis dapibus.' mystring.initWithString_(teststring) #d_red = NSDictionary.alloc().initWithObjectsAndKeys_([red, 'NSForegroundColorAttributeName', None]) # crash d_red = NSDictionary.alloc().initWithObjects_forKeys_((red,), ('NSForegroundColorAttributeName',)) mystring.setAttributes_range_(d_red, NSRange(10, 15)) tv = ui.TextView() tvc = ObjCInstance(tv) #tvc.setAttributedText_(mystring) # the following line works just fine (why?) tvc.attributedText = mystring tvc.setFont_(font) # ok tv.present()```
-
SteppenwolfUA
I've reproduced your generator example and it did indeed crash... So it's copy-paste with generators for now, until some solutions shows up. Thank you for the insights, anyway!
-
SteppenwolfUA
Thank you, Ole! It worked like charm, which again proves the point that reading the docs isn't enough. You need hands-on experience. I was too dumb to put 2 and 2 together despite having read about the
@on_main_thread
decorator.
Your remark about redundant _objc_ptr was an eye-opener. I'm upset 'cause I spent quite some time to dig it out )))) Thanks again.
-
SteppenwolfUA
Hello, everyone
I've started dabbling with objc_util module by trying out sample code provided with Pythonista and reading iOS docs. I find the whole idea of using Objective C from Python exciting. I've managed to set a property like backgroundColor on ui.View. What's struck me is the long time it takes. Almost 3x as long as for normal ui.View. Besides, first I get the default 'vanilla' view and then it gets colored. Any ideas what I am missing here?
from objc_util import * import ui import time # WORKS THE SAME WAY as in Myclass below #cl = UIColor.alloc() #cl = cl.init().initWithRed_green_blue_alpha_(.2, .3, .6, 1.).autorelease() class Myclass (ui.View): def __init__(self): #ui.View.__init__(self) #changes nothing ocv = ObjCInstance(self._objc_ptr) cl = UIColor.blueColor() ocv.backgroundColor = cl start = time.clock() v = Myclass() v.present('sheet') print time.clock()-start start = time.clock() v2 = ui.View() v2.background_color('blue') v2.present('sheet') print time.clock()-start
Thanx in advance.
-
SteppenwolfUA
I don't get this behaviour when typing the same in console. Copy pasting into editor works fine, but is awkward.
Thank you so much for your prompt response.
-
SteppenwolfUA
Hi!
I've got the following problem: every time I try to type os.walk(someroot) in editor and enter dot (to type next() for example) Pythonista crashes.
Is this just a peculiarity on my iPad or is this a general bug?
I would appreciate any hints. Thanks