omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular
    1. Home
    2. indoxan

    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.


    • Profile
    • Following 0
    • Followers 1
    • Topics 3
    • Posts 8
    • Best 0
    • Controversial 0
    • Groups 0

    indoxan

    @indoxan

    Japanese high school student. My English depends on machine translation.

    0
    Reputation
    3
    Profile views
    8
    Posts
    1
    Followers
    0
    Following
    Joined Last Online
    Location Japan

    indoxan Unfollow Follow

    Latest posts made by indoxan

    • RE: Commenting out code on an iPad

      Hi @emeraldmoss, you don't have to store the code in any particular folder, and you can choose any file name.

      To add editor shortcuts, tap the wrench button (🔧) in the top right.
      When the menu appears, tap "Edit", then tap the plus button that appears.
      When the "New Shortcut" view is displayed, select the file with the code written in "Run Script", decide the title and icon, and tap "Add".

      Select some code, tap the wrench button, run the shortcut you just added and commenting out should work.

      posted in Pythonista
      indoxan
      indoxan
    • RE: Return values of user-defined Objective-C classes

      Thanks for the reply, @cvp.

      I'm implementing the myButton method as a class method, so I don't think creating an instance is necessary.

      I wanted to define a class method that returns a customized instance, like UIButton's systemButtonWithImage:target:action: method.

      But this story should be put aside for now. As you say, similar things seem to be happen even when defining them as regular methods.

      posted in Pythonista
      indoxan
      indoxan
    • Return values of user-defined Objective-C classes

      Hi, I'm trying to define a class method in objc_util that returns my customized UI class as follows:

      from objc_util import *
      
      def myButton(_cls, _cmd):
          cls = ObjCInstance(_cls)
          button = cls.alloc().init().autorelease()
      
          # customize the button
          ...
      
          return button
      
      MyButton = create_objc_class(
          "MyButton",
          ObjCClass("UIButton"),
          classmethods=[myButton])
      
      if __name__ == "__main__":
          my_button = MyButton.myButton()
          ...
      

      But the return value is None.

      I tried to set the return value to button.ptr, but it had no effect.
      I also took into account the argtypes and restype issues, but they were a bit too technical for me.

      What is the correct way?

      posted in Pythonista
      indoxan
      indoxan
    • Cannot call UIButton.setMenu_() in Pythonista 3.4

      Using UIButton.setMenu_() crashes.
      I noticed this problem when I'm using @mikael ui3 menu.py.

      It looks like:

      objc_button = self.button.objc_instance.button()
      objc_button.setMenu_(objc_menu)
      

      I also tried something like this:

      button = ObjCClass("UIButton").alloc().init()
      menu = ObjCClass("UIMenu").alloc().init()
      ...
      button.setMenu_(menu)
      

      But crashed as well.

      I remember there was no problem in Pythonista3.3, is there any solution?

      posted in Pythonista
      indoxan
      indoxan
    • RE: KVO on WKWebView

      @vivek101 @cvp @JonB

      I was able to solve this problem by using ObjCDelegate of @mikael pythonista-achors for the time being. I will try other methods as well.

      Thank you for your kind reply!

      posted in Pythonista
      indoxan
      indoxan
    • RE: KVO on WKWebView

      I also tried programs like:

      class WebView(ui.View):
      
          def __init__(self):
              self.create_webview()
      
          @objc_util.on_main_thread
          def create_webview(self):
              self.webview = objc_util.ObjCClass("WKWebView").alloc().initWithFrame_(...)
              self.objc_instance.addSubview_(self.webview)
      
      class View(ui.View):
      
          def __init__(self):
      
              self.webview = WebView()
              self.add_subview(self.webview)
      
              observer_cls = objc_util.create_objc_class("observer_cls", methods=[self.observeValueForKeyPath_ofObject_change_context_])
              observer = objc_util.ObjCClass("observer_cls").alloc()
      
              self.webview.webview.addObserver_forKeyPath_options_context_(observer, "canGoBack", 0, None)
              self.webview.webview.addObserver_forKeyPath_options_context_(observer, "canGoForward", 0, None)
              ...
      
          def observeValueForKeyPath_ofObject_change_context_(_self, _cmd, _path, _obj, _change, _context):
                  ...
      

      observer is used as an instance of observer_cls.
      But in this case an error occurs. _objc_exception.py looks like this:

      Exception ignored on calling ctypes callback function: <bound method View.observeValueForKeyPath_ofObject_change_context_ of <__main__.View object at 0x116bbc180>>
      TypeError: View.observeValueForKeyPath_ofObject_change_context_() takes 6 positional arguments but 7 were given
      
      posted in Pythonista
      indoxan
      indoxan
    • RE: KVO on WKWebView

      @vivek101 Thank you for your welcome and for answering my question.

      I tried the solution you showed, but it still seems that observeValueForKeyPath_ofObject_change_context_ is not called.
      Also, when I specified a non-existent name in keyPath of addObserver, nothing happened as well.

      I'm not familiar with Objective-C and there are many things I don't understand, but I have the following questions:

      • I understand that in create_objc_class the superclass defaults to NSObject.
      • When using observeValueForKeyPath_ofObject_change_context_ as a class method, shouldn't I use the classmethod argument of create_objc_class?
      posted in Pythonista
      indoxan
      indoxan
    • KVO on WKWebView

      I'm trying out Key-Value-Observing with WKWebView in objc_util.

      class WebView(ui.View):
      
          def __init__(self):
              self.create_webview()
      
          @objc_util.on_main_thread
          def create_webview(self):
              self.webview = objc_util.ObjCClass("WKWebView").alloc().initWithFrame_(...)
              self.objc_instance.addSubview_(self.webview)
      
      class View(ui.View):
      
          def __init__(self):
      
              self.webview = WebView()
              self.add_subview(self.webview)
      
              observer = objc_util.create_objc_class("observer", methods=[self.observeValueForKeyPath_ofObject_change_context_])
      
              self.webview.webview.addObserver_forKeyPath_options_context_(observer, "canGoBack", 0, None)
              self.webview.webview.addObserver_forKeyPath_options_context_(observer, "canGoForward", 0, None)
              ...
      
          def observeValueForKeyPath_ofObject_change_context_(_self, _cmd, _path, _obj, _change, _context):
              ...
      

      I'm using something like this, but observeValueForKeyPath_ofObject_change_context_ doesn't seem to get called. Is there something wrong?

      posted in Pythonista
      indoxan
      indoxan