• Robert_Tompkins

    Actually what you have right there is perfect!

    @JonB, I don’t need the little things! However, I will probably create a new version of this code and turn it into that for practice! I could definitely use it.
    Edit: On second thought, that sounds real complicated. I might quit Python attempting that at this point :)

    @cvp Again, those changes are exactly what I needed, thanks!
    (https://imgur.com/a/TiCqTRz)

    ^^ Dunno how to do inline images haha. I ran out of ideas, so that’s a link to what I have with your changes.

    posted in Pythonista read more
  • Robert_Tompkins

    Ooo awesome. Thanks! I have been playing around with it trying to figure out a way to o’offwet’ the starting point so that the center of the slice on each vertical and horizontal axes line up. (Like on a dartboard).

    Let me see if I can throw an image here to show you what I mean.

    posted in Pythonista read more
  • Robert_Tompkins

    @cvp
    Alright, I installed the version of stash mentioned in his repo.
    Then conveniently used pip to grab the gestures library to make sure I didn’t mess anything up.

    Now the dartboard works like a charm! Thanks again.

    I’ll play around with it and see if I can clean it up without breaking it!
    I really need to browse git for useful Pythonista modules.

    In a week or so I will be back onto the DatePicker program and understanding objC usage in what you gave me there haha. Slowly but surely..

    posted in Pythonista read more
  • Robert_Tompkins

    @cvp
    Oh, whatcha got in your gestures module? Haha. That is not included by default:p

    posted in Pythonista read more
  • Robert_Tompkins

    @cvp
    That’s perfect! Thank you a ton haha. I see that I was close on what I had..
    I will put what you have to good use, thank you!

    I just couldn’t understand why ‘18’ wouldn’t work and that ‘9’ was producing better looking results.
    But now that you gave me something that works, I can finally understand where I went wrong.
    Very much appreciated!

    posted in Pythonista read more
  • Robert_Tompkins

    Alright, I’ve been asking a lot of you guys (well, mainly @JonB and @cvp haha).
    However, I have one more question / request..

    I thought it would be something I could easily accomplish but I was wrong.
    Was hoping to write a simple program that does the following:

    — Draw a dartboard on screen (circle split into 20 equal segments is all I need)
    — This works out to be 20 segments that should be 18 degrees each (360/20)
    — Set up each segment as a clickable button
    — The button.Action will be to highlight the selected segment and place a number label on it
    — For example:
    — Tapping top center segment will highlight it and place number 1 in segment
    — Then, if I tap a 2nd segment, it highlights it (same color as first is fine) and places number 2
    — This continues for 3 total selections. However, more is fine.

    I keep running into issues doing this.. It could be my lack of Geometry skills, or that I haven’t used Path() before, or maybe I’m just not cut out for programming ;)

    What is the best way to go about doing this?
    I’ve looked for code and tried reusing a few, but I end up with a weird pie chart that doesn’t ‘slice’ where I expect it to. Or I end up with some pretty cool drawings, from an abstract point of view!

    posted in Pythonista read more
  • Robert_Tompkins

    @JonB
    Sweet, I actually have been browsing the Apple developer docs, specially UIKit stuff, because that is what I keep finding examples of and I believe that’s what OMZ based the UI elements on.

    I managed to find some stuff there, as well as created a method to help investigate objects, etc.

    def investigateItem(item):
        mysteriousItem = item
        mysteriousInfo = dir(mysteriousItem)
        for x in mysteriousInfo:
            print(f"{x}")
        
    #setScreenBrightness()
    UIScreen = ObjCClass('UIScreen')
    screen = UIScreen.mainScreen()
    investigateItem(screen) 
    

    However, I totally forgot about using the console... That is a game changer, thanks!
    I’ll check out the other info you mentioned after I play a bit via console. Is it weird that I’m excited right now? Haha. Using the console to interact/access/view attributes, etc. is going to be crazy useful.

    posted in Pythonista read more
  • Robert_Tompkins

    @cvp
    I need some help ;)

    Been struggling because I have not used objc previously. So syntax and how it’s being converted on the fly to be used to access objects, etc.. is brand new to me.

    I have been trying to play with it via adjusting my screen brightness using one of the built in objc examples:

    from objc_util import *
    from time import sleep
    def run_async(func):
        from threading import Thread
        from functools import wraps
        
        @wraps(func)
        def async_func(*args, **kwargs):
            func_hl = Thread(target = func, args = args, kwargs = kwargs)
            func_hl.start()
            return func_hl
        return async_func
    
    @on_main_thread
    def setScreenBrightness():
        UIScreen = ObjCClass('UIScreen')
        screen = UIScreen.mainScreen()
        #print(f"UIScreen.get_names(): {UIScreen.get_names()}")
        for x in range(1):
            brightnessVar = 1.0
            for x in range(995):
                screen.setBrightness(brightnessVar)
                brightnessVar -= 0.001
                sleep(0.0001)
                #print(f"screen.brightness(): {screen.brightness()}")
            for x in range(995):
                if screen.brightness() < 1.0:
                    screen.setBrightness(brightnessVar)
                    brightnessVar += 0.001
                    sleep(0.0001)
    setScreenBrightness()
    
    

    However, what would help is being able to see a list of ‘objects’ I can get/set attributes for.
    For example:

    UIScreen = ObjCClass('UIScreen')
        screen = UIScreen.mainScreen() 
    

    What is UIScreen? I assume we are letting objc create a class/do conversions/do its magic to allow us to access/modify properties of it. But what other strings/object classes are available? Is there something like ‘UIFlashlight’?

    Of course, my attempts to print out a list of ‘things’ to try and understand structure, etc.. have resulted in a HUGE list being returned.. But for me to be able to learn this stuff, I get the most out of playing around with things, tweaking, printing out what’s there, but I can’t seem to do this. But again, I don’t even know where to begin haha.

    Any resources, tips you have send them my way! But as far as the countdown code you gave me; that will work perfectly. Once I understand the basics I will be rolling through the rest.

    posted in Pythonista read more
  • Robert_Tompkins

    @cvp

    Sweet, looks like all the bits n pieces are there!
    I haven’t played around with objc_util much, so it will take some trial and error to get what I want.

    However, I see that module used all over the place, and likely for good reason.
    So I will play with it and once I get a feel for it, will see where else I can use it.

    Thanks!

    posted in Pythonista read more
  • Robert_Tompkins

    Hey guys,

    I was playing around with date picker so I could create a quick program to calculate the time until a future date for my 7 year old daughter. She always asks us “how long until my birthday??” So I made her a program that will tell her the Days, Hours, Minutes, Seconds until the date she selected in the ui.DatePicker.

    Currently, she selects a date and it outputs the delta into a textView(4 of them, one for each: D,H,M,S), which get updated in real-time (Spams the terminal if debug flag is true, but I’m cool with that).

    What I would like to do is replace the textViews with another DatePicker.
    Unfortunately, none of the modes available display all fields: D,H,M,S.

    Is there a way for me to do this?
    Ideally, I’d like a copy of the source code for DatePicker so I could resize the width of the segments to be smaller(so it all fits) and then create additional segments to display D,H,M,S and rotate each dial in real-time.

    Here is my working code as of right now:

    import ui
    import console
    import time
    import datetime
    from time import *
    from objc_util import *
    from datetime import timedelta#, datetime
    
    def run_async(func):
        from threading import Thread
        from functools import wraps
        
        @wraps(func)
        def async_func(*args, **kwargs):
            func_hl = Thread(target = func, args = args, kwargs = kwargs)
            func_hl.start()
            return func_hl
            
        return async_func
    
    birthday = [2021, 2, 21]
    
    # TODO: ##### MAIN VIEW #####
    birthdayView = ui.View()
    birthdayView.background_color = 'black'
    birthdayView.x = 0
    birthdayView.y = 0
    birthdayView.width = 100
    birthdayView.height = 100
    birthdayView.flex = "LRTB"
    #########################
    
    # TODO: ##### DATE PICKER #####
    dateSelector = ui.DatePicker()
    dateSelector.center = (birthdayView.width / 2, birthdayView.height / 2)
    dateSelector.x = birthdayView.center[0]
    dateSelector.y = birthdayView.center[1]
    dateSelector.background_color = "#AAA"
    dateSelector.mode = 1
    #########################
    
    # TODO: ##### DAYS OUTPUT FIELD #####
    daysOutputField = ui.TextView()
    daysOutputField.x = birthdayView.center[0] - 15
    daysOutputField.y = birthdayView.center[1] + 300
    daysOutputField.width = 350
    daysOutputField.height = 50
    daysOutputField.background_color = "#000"
    daysOutputField.text_color = "#F00"
    daysOutputField.font = "<system>", 18
    #########################
    
    # TODO: ##### HOURS OUTPUT FIELD #####
    hoursOutputField = ui.TextView()
    hoursOutputField.x = birthdayView.center[0] - 15
    hoursOutputField.y = birthdayView.center[1] + 355
    hoursOutputField.width = 350
    hoursOutputField.height = 50
    hoursOutputField.background_color = "#000"
    hoursOutputField.text_color = "#F00"
    hoursOutputField.font = "<system>", 22
    #########################
    
    # TODO: ##### MINUTES OUTPUT FIELD #####
    minutesOutputField = ui.TextView()
    minutesOutputField.x = birthdayView.center[0] - 15
    minutesOutputField.y = birthdayView.center[1] + 410
    minutesOutputField.width = 350
    minutesOutputField.height = 50
    minutesOutputField.background_color = "#000"
    minutesOutputField.text_color = "#F00"
    minutesOutputField.font = "<system>", 26
    #########################
    
    # TODO: ##### SECONDS OUTPUT FIELD #####
    secondsOutputField = ui.TextView()
    secondsOutputField.x = birthdayView.center[0] - 15
    secondsOutputField.y = birthdayView.center[1] + 465
    secondsOutputField.width = 350
    secondsOutputField.height = 50
    secondsOutputField.background_color = "#000"
    secondsOutputField.text_color = "#F00"
    secondsOutputField.font = "<system>", 30
    #########################
    
    #import datetime
    #from time import localtime, time, gmtime, mktime, struct_time
    
    # TODO: ##### DEBUG FLAG #####
    debugMode = 1
    #########################
    
    @run_async
    def calculateTimeUntilBirthday(sender):
        global birthday
        global dateSelector
        global countdownTimer
        global daysOutputField
        global hoursOutputField
        global minutesOutputField
        global secondsOutputField
        
        while birthdayView.on_screen:
            currentTime = datetime.datetime.now()
            birthdayTime = dateSelector.date.replace(hour = 0, minute = 0, second = 0)
            birthdayString = f"{birthdayTime.month}/{birthdayTime.day}/{birthdayTime.year}"
            timeUntilBirthday = (birthdayTime) - (currentTime)
            
            seconds = timeUntilBirthday.seconds
            hours = seconds / 3600
            
            minutesLeft = hours - int(hours)
            minutesLeftMinutes = minutesLeft * 60
            
            secondsLeft = minutesLeftMinutes - int(minutesLeftMinutes)
            secondsLeftSeconds = secondsLeft * 60
            secondsLeftSeconds = round(secondsLeftSeconds, 2)
                
            daysOutput = f"Days: {timeUntilBirthday.days}"
            daysOutputField.text = daysOutput
            
            hoursOutput = f"Hours: {int(hours)}"
            hoursOutputField.text = hoursOutput
            
            minutesOutput = f"Minutes: {int(minutesLeftMinutes)}"
            minutesOutputField.text = minutesOutput
            
            secondsOutput = f"Seconds: {int(secondsLeftSeconds)}"
            secondsOutputField.text = secondsOutput
            
            
            if debugMode:
                print(f"Current Time: {currentTime}")
                print(f"Birthday Time: {birthdayTime}")
                print(f"birthdayString: {birthdayString}")
                print(f"timeUntilBirthday: {timeUntilBirthday}")
                print(f"seconds: {seconds}")
                print(f"hours: {hours}")
                print(f"minutesLeft: {minutesLeft}")
                print(f"minutesLeftMinutes: {minutesLeftMinutes}")
                print(f"secondsLeft: {secondsLeft}")
                print(f"secondsLeftSeconds: {secondsLeftSeconds}")
                print(f"secondsLeftSeconds: {secondsLeftSeconds}")
                
                print(f"Time Until Birthday: {birthdayString}\n Days: {timeUntilBirthday.days}\n  Hours: {int(hours)}\n   Minutes: {int(minutesLeftMinutes)}\n    Seconds: {int(secondsLeftSeconds)}")
    
    
    #birthdayView.add_subview(countdownTimer)
    
    birthdayView.add_subview(dateSelector)
    birthdayView.add_subview(daysOutputField)
    birthdayView.add_subview(hoursOutputField)
    birthdayView.add_subview(minutesOutputField)
    birthdayView.add_subview(secondsOutputField)
    
    dateSelector.action = calculateTimeUntilBirthday
    birthdayView.present(hide_title_bar = True) 
    

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!