Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-03-2008, 06:03 PM   #1 (permalink)
New Member
 
Join Date: Aug 2008
Posts: 1
Crashed is on a distinguished road
Default iPhone/Python Inquiry

I lack experience in the iPhone SDK and Objective-C, but I was hoping you guys could help me understanda thing or two so I could develop applications in a language I'm more comfortable with (Python).

I wanted to give one of my controls a color, so I looked on this forum to see how it would be done and found:

Code:
	[label setText:@"Hello World"]; 
	[label setTextColor:[UIColor blueColor]];
Now, I was hoping it would be as simple as control.setTextColor_(UIColor.blueColor) but my application just crashes (still haven't figured out a way to print or log errors).

Does anyone know where I could find blueColor, or, alternatively how to build my own color?

Other than the HelloWorld app (which I used religiously) there's no resources or information I can find on the net on iphone/python. So because of that I'll post my demo program, in case it'll help any future developers who check forum following the same goal.

Code:
import sys
import objc
from _uicaboodle import UIApplicationMain
from objc import YES, NO, NULL

objc.loadBundle('UIKit', globals(), '/System/Library/Frameworks/UIKit.framework')

class Application(UIApplication):
    @objc.signature('v@:@')
    def applicationDidFinishLaunching_(self, unused):
        # Initialize the window and view.
        self.window = UIWindow.alloc().initWithFrame_(UIHardware.fullScreenApplicationContentRect())
        self.view = UIView.alloc().initWithFrame_(self.window.bounds())

        # Create the navigation bar
        self.navbar = UINavigationBar.alloc().initWithFrame_(((0, 0), UINavigationBar.defaultSize()))
        self.navbar.setBarStyle_(1)
        self.view.addSubview_(self.navbar)

        # Create and add the navigation bar
        self.navbar.pushNavigationItem_(UINavigationItem.alloc().initWithTitle_('iChatters'))

        navbar_height = self.navbar.bounds()[0][1] + self.navbar.bounds()[1][1]

        # Create a textview
        self.textview = UITextView.alloc().initWithFrame_(((4, navbar_height + 4), (100, 24)))
        #self.textview.setText_(UIColor.blueColor_)
        self.view.addSubview_(self.textview)

        # Create a button!
        self.button = UIThreePartButton.alloc().initWithFrame_(((4 + 50, navbar_height + 4 + 50), (100, 24)))
        self.button.setTitle_('CLICK ME')
        self.button.setShowPressFeedback_(YES)
        self.button.setEnabled_(YES)
        self.view.addSubview_(self.button)

        # Setup the window
        self.window.orderFront_(self)
        self.window.makeKey_(self)
        self.window._setHidden_(NO)
        self.window.setContentView_(self.view)

UIApplicationMain(sys.argv, Application)

Last edited by Crashed; 08-03-2008 at 06:03 PM. Reason: Fixed a new line.
Crashed is offline   Reply With Quote
Old 08-04-2008, 11:28 AM   #2 (permalink)
Registered Member
 
Join Date: Apr 2008
Location: Colorado
Posts: 312
jonc is an unknown quantity at this point
Send a message via AIM to jonc
Default

As far as I know you can only write python for a jailbroken phone.

I don't know python so your code was foreign to me, but you seem to be on the right track. I think we could offer you more help if it was in objective-c.
jonc is offline   Reply With Quote
Old 08-04-2008, 04:48 PM   #3 (permalink)
I live @ iDevKit.com
 
Join Date: Jul 2008
Posts: 142
mxweas is an unknown quantity at this point
Default

Look at saurik's documentation for the python version of UITextView, UITextView in python redirects to the renamed UITextView from old toolchain. setTextColor will take a CGColorRef and I believe sauriks python port will not include the new sdk class's for NDA reasons. Therefore UIColor/UIFont and other class's that are new since 1.1.4 will not be available.

Max
mxweas is offline   Reply With Quote
Old 04-15-2011, 09:42 AM   #4 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 8
Gik254 is on a distinguished road
Default How I did it.

Define a color
ex.
bgColorBLUE = UIColor.colorWithRed_green_blue_alpha_(0.7,0.74,1. 0,1.0)
fgColorDarkBlue = UIColor.colorWithRed_green_blue_alpha_(0.0,0.01,0. 38,1.0)
# values are of course (R, G, B, transparency) from 0 to 1

and then use as such:
field.setBackgroundColor_(bgColorBLUE)
field.setColor_(fgColorDarkBlue)

(where field is a UITextLabel, or any other object you want)

(I did this in an app (derived from HelloPython) and it works fine)

Last edited by Gik254; 04-15-2011 at 09:45 AM.
Gik254 is offline   Reply With Quote
Old 04-15-2011, 09:51 AM   #5 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 8
Gik254 is on a distinguished road
Default

Now can you tell me how to read the value of a UIDatePicker in a similar situation (PyObjC program)?

I define it as: self.datePicker = UIDatePicker.alloc().initWithFrame_(myframe)

I set the date I want with: self.datePicker.setDate_(mydate)
but when I try to access the value (dialed by the user) I cant find a way...

There is no self.datePicker.getDate_() or self.datePicker.date or any other I could guess... (and the documentation does not help...)
Gik254 is offline   Reply With Quote
Old 04-19-2011, 02:16 AM   #6 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 8
Gik254 is on a distinguished road
Default

OK, I found it (it was fairly stupid!)

the answer was:
self.datePicker.date() # GMT date
self.datePicker.hour() # Local Hour
and the rest as:
self.datePicker.minute() # Minutes, etc
Gik254 is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone, python, sdk

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 337
8 members and 329 guests
chiataytuday, givensur, ipodphone, jbro, mtl_tech_guy, Punkjumper, vilisei, yomo710
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,881
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:14 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0