omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Setting button size using frame as parameter has no effect

    Pythonista
    4
    6
    4304
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • PetervdKamp
      PetervdKamp last edited by

      I have a scrollview to which I add textfields and a button dynamically. For the button I use the following code:

      insert_button = ui.Button(frame = (x, y, 120, 40), name = 'insertrecord', title = 'Add record')

      Running the code, the button has the wrong size. Changing the width and height values of the frame has no effect, even if I change them into unrealistic values like 600, 200.

      However, when I change my code into:

      insert_button = ui.Button(name = 'insertrecord', title = 'Add record')
      insert_button.frame = (x, y, 120, 40)

      then everything works fine.

      Is this a bug or do I miss something?

      Peter

      1 Reply Last reply Reply Quote 0
      • omz
        omz last edited by

        Is this a bug or do I miss something?

        No, it's a feature. ;) When you pass a title or image to the Button constructor, it determines the size automatically, which is often convenient, though obviously not what you want in this case. You'll have to set the frame afterwards (like you did) if you don't want this behavior.

        1 Reply Last reply Reply Quote 0
        • PetervdKamp
          PetervdKamp last edited by

          Ok, that's clear. Are there more widgets to which this apply? As they all inherits from ui.View I thought that I could use frame the way I did first.

          Peter

          1 Reply Last reply Reply Quote 0
          • dgelessus
            dgelessus last edited by

            I think the ability to pass frame as a constructor argument is only available on the base ui.View class. It's hard to tell which arguments are supported though - almost none of the View subclasses have their constructor arguments noted in the documentation, and since most of the ui module's functions and classes are written in (Objective-)C there is no way to find out how they work internally.

            1 Reply Last reply Reply Quote 0
            • omz
              omz last edited by

              With the exceptions of TableView, TableViewCell, and NavigationView, all ui.View subclasses should support the following keyword parameters: frame, flex, background_color (alternatively bg_color), and name. As I said, ui.Button ignores the size of the frame if either title or image are also passed.

              1 Reply Last reply Reply Quote 0
              • wradcliffe
                wradcliffe last edited by

                @dgelessus - the recent addition of ctypes may allow us to inspect the ui classes now. I have been trying to write an object dumper/lister but it is slow going for me. Here is an example code of what is possible - dumping info about the core bluetooth classes and a few others.

                
                from cocoapy.runtime import *
                
                def list_methods(cls, type):
                    count = c_uint()
                    method_array = objc.class_copyMethodList(cls, byref(count))
                    print '---', count.value, type, 'methods','---'
                    names = []
                    for i in range(count.value):
                        method = c_void_p(method_array[i])
                        sel = c_void_p(objc.method_getName(method))
                        name = objc.sel_getName(sel)
                        encoding = objc.method_getTypeEncoding(method)
                        return_type = objc.method_copyReturnType(method)
                        names.append((name, encoding, return_type))
                
                    names.sort()
                    for x, y, z in names: 
                        print x, y
                
                def list_variables(cls, type):
                    count = c_uint()
                    ivar_array = objc.class_copyIvarList(cls, byref(count))
                    print '---', count.value, type, 'variables','---'
                    names = []
                    for i in range(count.value):
                        ivar = c_void_p(ivar_array[i])
                        name = objc.ivar_getName(ivar)
                        encoding = objc.ivar_getTypeEncoding(ivar)
                        names.append((name, encoding))
                
                    names.sort()
                    for x, y in names: 
                        print x, y
                
                CB_Classes = [
                'CBATTRequest',
                'CBAttribute',
                'CBCentral',
                'CBCentralManager',
                'CBCharacteristic',
                'CBDescriptor',
                'CBMutableCharacteristic',
                'CBMutableDescriptor',
                'CBMutableService',
                'CBPairingAgent',
                'CBPeer',
                'CBPeripheral',
                'CBPeripheralManager',
                'CBScalablePipe',
                'CBScalablePipeManager',
                'CBService',
                'CBUUID',
                'CBXpcConnection',
                'AVAudioSession',
                'AVAudioRecorder',
                'NSMutableDictionary'
                ]
                
                if __name__ == '__main__':
                    for class_name in CB_Classes:
                        cls = get_class(class_name)
                        print '--------------------------'
                        print 'class:', class_name
                        list_methods(cls, 'instance')
                        list_methods(get_object_class(cls), 'class')
                        list_variables(cls, 'instance')
                        print '--------------------------'
                
                

                Uses a set of wrapper classes from cocoapy which is buried in pyglet, but the ByBee wrappers should also work.

                I have not yet figured out how to look at any of the Pythonista App classes, only various frameworks that are linked in.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                Powered by NodeBB Forums | Contributors