• ryubai

    @cvp thank you very much.
    i prefer to use uitableviewcontroller,it connect data source and delegate automatically.
    your code works but when I transfer to UITableViewController,it crashs.

    posted in Pythonista read more
  • ryubai

    @cvp i don’t understand how to .. i want to subclass a UITableViewcontroller and add a action when i left swipe a cell.
    could you show me the right way in the code i provided?
    sorry for my poor understanding.

    posted in Pythonista read more
  • ryubai

    @cvp i try the code below,but still crash,what’s the problem?

    from objc_util import *
    import ui
    
    @on_main_thread
    def main_tableview():
        def tableView_numberOfRowsInSection_(_self, _cmd,_tv,_section):
            return 3
        
        def numberOfSectionsInTableView_(_self, _cmd,_tv):
            return 1
        
        def tableView_cellForRowAtIndexPath_(_self, _cmd,_tv,_indexpath):
            cell=ObjCInstance(_tv).dequeueReusableCellWithIdentifier("cell1") 
            if cell==None:
                cell=ObjCClass('UITableViewCell').alloc().initWithStyle_reuseIdentifier_(3,"cell2")
            
            cell.textLabel().text = 'test'
            return cell.ptr
        
        def tableView_trailingSwipeActionsConfigurationForRowAtIndexPath_(_self,_cmd,_tv,_indexPath): 
            return None
            
        tvc1 = create_objc_class('UITableViewController',ObjCClass('UITableViewController'),methods=[tableView_numberOfRowsInSection_,numberOfSectionsInTableView_,tableView_cellForRowAtIndexPath_,tableView_trailingSwipeActionsConfigurationForRowAtIndexPath_])
        
        return  tvc1.alloc().init().autorelease()   
        
    @on_main_thread
    def main():
    
        root_vc = UIApplication.sharedApplication().keyWindow().rootViewController()
        tbc=main_tableview()
        root_vc.presentViewController_animated_completion_(tbc, True, None)
        
    if __name__=='__main__':
        main()
    

    posted in Pythonista read more
  • ryubai

    @cvp when i comment # return none,i got it.
    thanks very much.

    posted in Pythonista read more
  • ryubai

    @cvp thanks

    i have checked _objc_exception.txt and saw nothing in this crash.
    try the example you provided,when i do a left swipe,it just show “delete” button.
    i have no idea how the code below work

        # set actions if swipe
        UIContextualAction = ObjCClass('UIContextualAction').alloc()
        UIContextualAction.setTitle_("Drizzel's action 😅")
        # block does not have parameter nor return, thus we can use a Python def
        UIContextualAction.setHandler_(handler)
        UIContextualAction.setBackgroundColor_(ObjCClass('UIColor').blueColor().colorWithAlphaComponent(0.5))
        
        UISwipeActionsConfiguration = ObjCClass('UISwipeActionsConfiguration').configurationWithActions_([UIContextualAction])

    posted in Pythonista read more
  • ryubai

    hey~i need to return none in a objc new class function,but it crash’s when i use return none.how can i solve it? thanks very much.

    def tableView_trailingSwipeActionsConfigurationForRowAtIndexPath_(_self,_cmd,_tv,_indexPath):       
            return None
    

    posted in Pythonista read more
  • ryubai

    @JonB

    thanks.
    it seems not convenient for debug, and i still use objc_util as OC bridge.

    posted in Pythonista read more
  • ryubai

    @JonB

    run more than once will raise such errs,then how to solve?

    ctypes_patch.make_callback_returnable(CGSize)
    File "/private/var/mobile/Containers/Shared/AppGroup/02422888-CC52-45FC-BB53-72013D3F4AFA/Pythonista3/Documents/site-packages/ctypes_patch.py", line 128, in make_callback_returnable
    raise ValueError("The ctype {} already has a getfunc")
    ValueError: The ctype {} already has a getfunc

    posted in Pythonista read more
  • ryubai

    latest when i try rubicon_objc.
    the code below, run once is normal. run anther time will raise a err.
    how can i solve it? thanks in advance

    RuntimeError: An Objective-C class named b'Handler' already exists

    code:

    from rubicon.objc import NSObject, objc_method

    class Handler(NSObject):
    @objc_method
    def initWithValue_(self, v: int):
    self.value = v
    return self

    @objc_method
    def pokeWithValue_andName_(self, v: int, name) -> float:
        print("My name is", name)
        return v / 2.0
    

    my_handler = Handler.alloc().initWithValue(42)

    posted in Pythonista read more
  • ryubai

    @JonB @mikael @cvp and other dear friends

    Sincerely,many thanks to you all!
    i love to stay here.

    posted in Pythonista read more
  • ryubai

    anyone can help? please

    posted in Pythonista read more
  • ryubai

    @JonB

    thank you all

    when i overwrite a method requested a return type in a new class.
    number and string can be returned directly.
    cell object in tableview is returned in cell.ptr
    but how to return a CGSize structure?
    objc's CGSize does't work

    posted in Pythonista read more
  • ryubai

    @mcriley821

    it still can’t work.

    superclass=NSObject is default when new class is created.

    posted in Pythonista read more
  • ryubai

    i created a new class and add a function to methods.
    but it showed such error.
    how can i return cgsize correctly?
    thanks in advcance.

    TypeError: invalid result type for callback function

    def collectionView_layout_sizeForItemAtIndexPath_(_self, _cmd, _cv, _la, _ip):
    return CGSize(340,300)

    methods = [collectionView_layout_sizeForItemAtIndexPath_]

    DataSource = create_objc_class('DataSource', methods=methods, protocols=['UICollectionViewDelegateFlowLayout', 'UICollectionViewDataSource', 'UICollectionViewDelegate'])

    posted in Pythonista read more
  • ryubai

    @JonB

    thank you very much for detailed reply.
    i will have more tests and try to understand it indepth.
    maybe ask later when i meet new question,thank you again.

    posted in Pythonista read more
  • ryubai

    thanks to you all. sloved!
    and sorry for my wrong code format,i'll correct it in my next post.

    posted in Pythonista read more
  • ryubai

    how to understand thread clearly? see my comments
    I run these code and return such results.


    <NSThread: 0x2828f0780>{number = 7, name = (null)}
    <NSThread: 0x28285b100>{number = 1, name = main}
    <NSThread: 0x2828f0780>{number = 7, name = (null)}


    import threading
    from objc_util import  *
    import ui
    
    td=ObjCClass('NSThread')
    print(td.currentThread())
    #why isn't this in a mainthread? it shows in background thread.
    
    #it shows in background thread,it's okay
    @ui.in_background
    def test1():
        print(td.currentThread())
    
    #it shows in main thread,it's okay
    @on_main_thread
    def main():
        global td   
        print(td.currentThread())
        test1()
    
    if __name__=='__main__':
        main()
    

    posted in Pythonista read more
  • ryubai

    when I run these code, it shows a error name lib is not defineded?

    how to slove? thanks

    import ui
    from objc_util import *

    def change(sender):
    lb.text='new'

    @on_main_thread
    def main():
    v=ui.View()
    v.background_color='white'

    lb=ui.Label(text='old')
    btn=ui.Button(title='press',action=change)
    
    v.add_subview(lb)
    v.add_subview(btn)
    
    v.present()
    

    if name=='main':
    main()

    posted in Pythonista read more
  • ryubai

    @dgelessus

    great!it has worked under your kind guidance!
    thank you very very much!

    posted in Pythonista read more
  • ryubai

    @dgelessus

    sir,I read your latest replies in the forum and interested in rubicon.objc you mentioned.I have installed it by pip install rubicon.objc with stash but it doesn’t work.

    when I run
    from rubicon.objc import NSInteger, NSObject, ObjCProtocol, objc_method

    it showed a error, could you give me a help? thanks so much.

    Traceback (most recent call last):
    File "/private/var/mobile/Containers/Shared/AppGroup/02422888-CC52-45FC-BB53-72013D3F4AFA/Pythonista3/Documents/t_rubicon.py", line 1, in <module>
    from rubicon.objc import NSInteger, NSObject, ObjCProtocol, objc_method
    File "/private/var/mobile/Containers/Shared/AppGroup/02422888-CC52-45FC-BB53-72013D3F4AFA/Pythonista3/Documents/site-packages-3/rubicon/objc/init.py", line 15, in <module>
    from . import runtime # noqa: F401
    File "/private/var/mobile/Containers/Shared/AppGroup/02422888-CC52-45FC-BB53-72013D3F4AFA/Pythonista3/Documents/site-packages-3/rubicon/objc/runtime.py", line 2, in <module>
    from ctypes import (
    File "/var/containers/Bundle/Application/789BA705-9D92-409A-8DF3-9D0806F2BD5B/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/ctypes/util.py", line 72, in <module>
    from ctypes.macholib.dyld import dyld_find as _dyld_find
    ModuleNotFoundError: No module named 'ctypes.macholib'

    posted in Pythonista read more
Internal error.

Oops! Looks like something went wrong!