Setting button size using frame as parameter has no effect
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?
Is this a bug or do I miss something?
No, it's a feature. ;) When you pass a
Buttonconstructor, it determines the size automatically, which is often convenient, though obviously not what you want in this case. You'll have to set the
frameafterwards (like you did) if you don't want this behavior.
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.
I think the ability to pass
frameas a constructor argument is only available on the base
ui.Viewclass. It's hard to tell which arguments are supported though - almost none of the
Viewsubclasses have their constructor arguments noted in the documentation, and since most of the
uimodule's functions and classes are written in (Objective-)C there is no way to find out how they work internally.
With the exceptions of
ui.Viewsubclasses should support the following keyword parameters:
name. As I said,
ui.Buttonignores the size of the
imageare also passed.
@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.