• Robert_Tompkins

    Thanks! Yea... I just recently started using that lol. This is why I try writing programs for a wide range of things. Otherwise I don’t learn about these things!

    Not trying to hijack.. but how can I simplify this? Goal of this was to just strip anything that is not always used in my use-case. Like punctuation. I’m detecting text on-screen via OCR and extract it and attempt to find a match. But I want to be lenient lol.

            textString = textString.replace('[', '')
            textString = textString.replace(']', '')
            textString = textString.replace('  ', ' ')
            textString = textString.replace("'", '')
            textString = textString.strip()
            textString = textString.lower() 

    posted in Pythonista read more
  • Robert_Tompkins

    So I went through like 20 of my programs for a good, simple example..
    But I realized that I don’t convert any user input in-line. I prefer to do it after storing the input to a variable.
    This allows me to do my own tests on it before falling through to a default error message.

    For example, in my game, prompting for a name to be used for profile loading/saving..

    def loadProfile(self, passedPlayerName=None, resetProfile=None):
            global profileLoaded
            listOfDebugNames = ["admin", "ADMIN", "Admin", "sudo", "SUDO", "Sudo"]
            if passedPlayerName != None:
                self.playerName = passedPlayerName
                self.playerName = console.input_alert(
                    f'Please enter your Profile Name',
                    'Case Sensitive, probably',
                if self.playerName == "":
                    self.playerName = "NOOB"
            if self.playerName in listOfDebugNames:
                # Debug handling is done here

    So with string being default, you can first check if it is equal to a debug string you specify.
    Or, you can check the type of it first and handle it case by case / type by type.
    Here’s a random example of me handling two cases where the item passed to a function can be a string, or can be a list of strings.

    def getPriceEsoItem(item):
        global dictOfItemFields
        global dictOfSearches
        device = zxtouch("")
        dictOfSearches = {}
        argumentType = type(item)
        if argumentType == list:
            for string in item:
                length = len(string)
                dictOfSearches[string] = length
            length = len(item)
            dictOfSearches[item] = length

    Maybe there’s a downside that I am missing.. But to me, it seems to always be better to store user input first. Then do your own handling for various input types depending on your use-case.

    posted in Pythonista read more
  • Robert_Tompkins

    @talns100 said:

    Hey, when I execute a script and enters a number as input it automatically behaves as a string.
    How to fix that? I can’t add inputs cuase of it.
    Will casting fix the problem?
    Why does it happen in the first place?

    Yes, user input is treated as a string by default but casting does fix the problem.
    Since user input can be of any type, handling it as a string is the safest way to store the value.

    You can easily cast it in-line

    userInput = int(input(“Enter an integer:\n”))

    Or later

    userInput = input(“Enter stuff:\n”)
    integerInput = int(userInput)
    floatInput = float(userInput)

    That’s my two cents!

    posted in Pythonista read more
  • Robert_Tompkins

    Unless somebody knows how to correct this.
    Let me know if you can/cannot replicate this on your device.

    Problem: Debugger window font color is black, background color is automatically set to match ‘Editor > Editor Background’ color. So text is unreadable if you use a dark editor background while using Light iPhone theme.

    Solution: Add debugger window attributes to the Custom Theme configuration options.
    This would allow us to specify the color of the text and background separately from wherever they are currently pulling their attributes from.
    Debugger Background
    Debugger Text

    Anyone else have this issue? Or found a workaround?

    posted in Pythonista read more
  • 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!

    ^^ 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

    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

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

    posted in Pythonista read more
  • Robert_Tompkins

    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

Internal error.

Oops! Looks like something went wrong!