• GaryGadget

    Just the kind of pointer I needed thanks. I now have two pyui’s of which one is a tableview. I had to use global to enable the selected_row value to be used outside the function, is this the norm? Anyway thanks very much for your help.
    Regards
    Gary

    posted in Pythonista read more
  • GaryGadget

    Hi,

    I am learning how to use Pythonista and am looking for advice on the best method to implement a simple idea for a script I have. I have a GUI created with the designer to set up up a crossword grid. A cell is tapped to turn it either black or white (these are buttons). However, I want another option available when tapped to produce another GUI in the form of a Tableview with a list of numbers to select (up to 26).

    My problem is that I do not understand how to load the tableview I created with the designer, into view. Is it a new view requiring a frame or should it be loaded as a subview into my existing frame? All the examples I have found seem to be adding buttons to existing frames. Whereas I think I am trying to add a view which seems different. It wont load using subview with error ‘expecting’ view.

    Basically I’m trying to add another GUI called NumberSelector.pyui into the process when a cell is tapped.

    Is this the right way to implement my idea or should it be a different approach. If not, what am I doing wrong please?

    Thanks.

    ## AlphaPuzzle Solver by G A ##
    
    import ui
    b = ui.Button()
    
    def button_tapped(sender):
        '@type sender: ui.Button'
        # Get the button's title for the following logic:
        t= sender.name
        b = sender
        #print(t)
        #b.background_color = 'black'
        if (str(b.background_color)) != '(1.0, 1.0, 1.0, 1.0)':
            b.background_color = 'white'
        else:
                b.background_color = 'black'
        #print(b.background_color)
    
    v = ui.load_view('AlphaGrid')
    
    if min(ui.get_screen_size()) >= 768:
        # iPad
        v.frame = (0, 0, 360, 400)
        v.present('sheet')
    else:
        # iPhone
        v.present(orientations=['portrait'])
    

    posted in Pythonista read more
  • GaryGadget

    Don’t know how I missed that. Thanks for your help.

    posted in Pythonista read more
  • GaryGadget

    Thanks for that, I did search the class library for something like this but couldn’t/can’t find it. Am I looking in the wring place?

    posted in Pythonista read more
  • GaryGadget

    Hi,
    Quick one I hope.

    Is it possible to change the background colour of a button from within code, i.e. I want to make the colour dynamic so I can make it all black or white like a crossword. Or should I utilise the image to match my needs?

    Thanks for your time.

    Regards
    Gary

    posted in Pythonista read more
  • GaryGadget

    Hi, I'm not used to coding with Python so using Pythonista to help learn the ways on my mobile device for convenience. I'm trying to rewrite a codeword solver I wrote in Visual Basic for Excel. I used the spreadsheet grid for the user interface but not sure of the best method to adopt in Pythonista. The idea is to draw a crossword type grid (codeword) which can be edited and updated for each time a letter Is substituted in the grid.
    Not sure whether to use layers, user interface or separate tiles etc.

    Still learning so any pointers or examples for crossword type interface coding help would be greatly appreciated.

    Basically my program allows the user to see the effect of a particular letter when it is substituted in the grid. Thus helping to see if other areas of the grid look feasible. If not happy the then the operation can be corrected. Much quicker than pencil and paper apart from the initial set up of the grid.

    Thanks for any help.

    Regards
    Gary

    posted in Pythonista read more
  • GaryGadget

    Thanks to you all for your help so far. I have made some progress after the last post, if only a small step. I have now managed to get to grips a bit with switching 'views' at the touch of a button based on ccc's idea thanks.

    The idea is still to switch between 3 different class types for my codeword, number grid and letter grid. This I have some idea of how I will tackle it but can somebody please explain the use of the 'frame' command in the context of switching between views. i.e. I don't know how to size or position my grids to fill the screen on iPhone/iPad. I have tried different ways from what I have seen but none of them seem to work. In this particular use my classes will be the grids made up of buttons that I want to fill the screen as best they fit.

    Oh and I now have a bluetooth keyboard connected to my iPhone so it is much better for typing the lines of code in.

    Thanks
    Gary

    
    import ui, console
    
    def button_tapped(sender):
        sender.superview.send_to_back()
        print sender.name
        
    class FirstClass(ui.View):
        def __init__(self):
            self.background_color = 'blue'
            button = ui.Button(frame = (0, 0, 1, 1), title = 'Class 1')
            button.name = button.title
            button.bg_color = 'white'
            button.flex  = 'WH'
            self.add_subview(button)
            button.action = button_tapped
            
    class SecondClass(ui.View):
        def __init__(self):
            self.background_color = 'red'
            button = ui.Button(frame = (0, 0, 1, 1), title = 'Class 2')
            button.name = button.title
            button.bg_color = 'white'
            button.flex = 'WH'
            self.add_subview(button)
            button.action = button_tapped
    
    parent_view = ui.View()
    grids = [FirstClass(), SecondClass()]
    for i, b in enumerate(grids):
        #b.frame = (0, 0, parent_view.width, parent_view.height)
        b.flex = 'WH'
        parent_view.add_subview(b)
        b.send_to_back()
        
    parent_view.present('full_screen')
    
    

    posted in Pythonista read more
  • GaryGadget

    Thanks guys,

    I'm just trying to understand how all of the parts will work for my codeword GUI. Once I grasp that I'll be able to put them all together in a neater version.

    Basically I wanted to swap between my 3 main views: Codeword grid, number selection grid , and letter selection grid. But keep coming up against beginner type problems with my code. In this latest problem it was getting the SecondClass object (a selection grid) to appear full screen and pass a value back.

    I'll look more closely later at your posts but just wanted to thank you all for you prompt and helpful responses. It always helps speed things up but believe me I have spent ages on each stage just trying to get what looks like only a few lines of code.

    As I said before 'Baby Steps' for me but learning is satisfying!

    Regards
    Gary

    posted in Pythonista read more
  • GaryGadget

    I'm trying to get the buttons to switch between views. How can I pass the size to child_view so it fills the screen like its parent?

    Thanks in advance
    Gary

    import ui
    
    # test of view interchanging
    
    def button1_tapped(sender):
        child_view = SecondClass()
        parent_view.add_subview(child_view)
            
    
    def button2_tapped(sender):
        print 'button2 tapped'
    
    class FirstClass(ui.View):
        
        def __init__(self):
            self.present()
            self.background_color = 'black'
            button1 = ui.Button(frame = (1, 1, self.width, self.height))
            print 'parent_view started at ', self.width
            button1.title = 'First Class'
            self.add_subview(button1)
            button1.action = button1_tapped
    
            
    class SecondClass (ui.View):
            
        def __init__(self):
            print 'parent_view now = ', parent_view.width
            self.background_color = 'white'
            button2 =ui.Button(frame = (1, 1, parent_view.width, parent_view.height))
            button2.title = 'Second Class'
            parent_view.add_subview(button2)
            button2.action = button2_tapped
        
    
    
    parent_view = FirstClass()
    

    posted in Pythonista read more
  • GaryGadget

    Well spotted. Yes it is a mistake. I was getting errors when trying to use 'white' in equality tests so I used the tuple values instead. I couldn't remember what the values for black were but didn't implement it in the end. I'll reuse your line when I rewrite, once I know how all the parts work. The main obstacles are my inexperience with GUI's & Classes but also trying to learn how to use these techniques on my iPhone in my spare time. I am really impressed with the shear power of Pythonista so far though. Bit fiddly editing on the phone at times though. Thanks for your help.

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!