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.


    CaptureMedia

    Pythonista
    6
    22
    19618
    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.
    • ?
      A Former User last edited by

      Here is our work for capturing media (@techteej and @tony) from 2 other threads and @techteej's Speech project, tidied up, wrapped in a class, closing the server and presented in a popover sized to fit the iOS pop up.

      The code uses a chunk from @omz's File Transfer script.

      Only tested on an iPad mini (original) and the latest iOS 7 (see below), can't vouch for others.

      # see version 2.1
      

      Edit 2.1:

      New version posted

      Edit 2.0:

      New public interface attributes of: version, source, message and file name

      New compatibility testing in preparation for release of IOS 8

      New close button in base class to prompt user action after cancel

      New sub class example: MyCaptureMedia

      Update: better fix for programmatic close of popover

      Edit 1.0:

      Notes for GitHub users regarding the items removed there:

      1. The _make_xxx methods are according to @ccc's comments on best practices.... "Each ui element that gets added as a subview to your ui.View should have its own make_xxx() method." http://omz-forums.appspot.com/pythonista/post/5826032204513280

      2. The methods did load and layout are supplied as a provision for subclasses of CaptureMedia. Did load... gives the subclass the opportunity to add to or modify the ui of the class before it's presented, perhaps to make the WebView visible or leave it hidden but add extra buttons, etc. Layout gives the subclass the opportunity to change the size of the popover or adjust it for orientation changes etc.

      3. The function of the def log_message is to suppress the default log messages to the console.

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

        Please put this on github. Much easier to download and also collaborate.

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

          Also, I don't know why this crashes Pythonista on iOS 8.

          1 Reply Last reply Reply Quote 0
          • ?
            A Former User last edited by

            @techteej Please feel free to, I haven't used github. Oh iOS 8, was that the factor. Good to know, thanks.

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

              I posted it here on GitHub for you.

              1 Reply Last reply Reply Quote 0
              • ?
                A Former User last edited by

                Thanks

                1 Reply Last reply Reply Quote 0
                • ?
                  A Former User last edited by

                  @ccc I've added some notes above regarding the purpose of the items removed in the Github edit.

                  1 Reply Last reply Reply Quote 0
                  • ?
                    A Former User last edited by

                    Here's an example of how to make a custom CaptureMedia with the version posted here (this wouldn't work with the GitHub edit)...

                    class MyCaptureMedia (CaptureMedia):
                    	def did_load(self):
                    		self.name = 'My Capture Media'
                    		self.background_color = 'Lime'
                    		self.left_button_items = [ui.ButtonItem(image = ui.Image.named('ionicons-close-24'), action = lambda sender: self.close())]
                    		self.lHelp = ui.Label()
                    		self.lHelp.text = 'Please choose media...'
                    		self.add_subview(self.lHelp)
                    		super(MyCaptureMedia, self).did_load()
                    		
                    	def layout(self):
                    		self.width = 320
                    		self.height = 200
                    		self.lHelp.x = 30
                    		self.lHelp.y = 10
                    		self.lHelp.width = 180
                    		self.lHelp.height = 30
                    
                    1 Reply Last reply Reply Quote 0
                    • ccc
                      ccc last edited by

                      @Tony, Thanks for the explanations on the desire for extension points and log_message(). Makes sense to me. I posted a pull request to re-add log_message() and will try to put the extension points back into the GitHub source in the next 24 hours (if someone does not do so before I can).

                      Can we come up with a different name for did_load()? Ole had reserved the did_load() name for views that load ui resources from a .pyui file. A did_load() in a script that does not use .pyui might confuse the casual reader. Given that all ui elements are created at runtime without .pyui, we should use a similar yet different name.

                      1 Reply Last reply Reply Quote 0
                      • ?
                        A Former User last edited by

                        @ccc Good. Maybe... consider though... should the consumer of a class need to know or bother whether behind the scenes it's ui was implemented with the ui editor or with handwritten code?? The use of did_load here was deliberate to create consistency and transparency.

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

                          I submitted a pull request which I hope solves the issues that you mentioned above.

                          I also opened a new issue on cancel and close.

                          1 Reply Last reply Reply Quote 0
                          • ?
                            A Former User last edited by

                            @ccc Well done. Yes, it's a good point about detecting the cancel. The evaluate JavaScript returns immediately so that doesn't help. There's no POST when the user cancels... so again that doesn't help. It's hard to wait for an absence of the file when there's no knowing how long a video record might last.

                            In the base class... after cancel, tap outside the popover to close it and then the server closes because of the will close.

                            The sub class close button is the same scenario as the close from the POST I think... it seems to be a quirk of a programmatic close of a view presented in a popover that will_close doesn't automatically get called on the view in that case. Hence the second line at the end of POST to fix that. (present in a panel doesn't have that quirk I think, nor probably the other presents though I haven't tested.)

                            The sub class was a quick knock up to show the idea, but more properly I think the button item action would need to invoke both will close and close because of the quirk.

                            1 Reply Last reply Reply Quote 0
                            • ?
                              A Former User last edited by

                              @ccc It's a bit of a fudge, but this addition to the base class seems to fix the quirk of present in a popover programmatic close for both the POST and the sub class button item action (and the fix line from POST can be removed)...

                              def close(self):
                              		self.will_close()
                              		super(CaptureMedia, self).close()
                              
                              1 Reply Last reply Reply Quote 0
                              • ?
                                A Former User last edited by

                                Updated source to version 2.0

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

                                  @tony Just updated.

                                  1 Reply Last reply Reply Quote 0
                                  • ?
                                    A Former User last edited by

                                    @techteej Thanks.

                                    p.s. I'm working on adding in a settings button and my SettingsSheet class for a switch to turn warnings on/off.

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

                                      @tony I have to test this on an iOS 7 iPad, which I don't see very often (it's a relatives) so good luck! Hopefully @ccc will help you. I can do what I can when I get the iOS 7 iPad.

                                      1 Reply Last reply Reply Quote 0
                                      • ?
                                        A Former User last edited by

                                        @techteej Thanks :) Likewise when iOS 8 is out I'll have a way to try to get it working on that.

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

                                          capture_media generates an error on line 115 on my ipad air ios7.... any fix?

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

                                            Looks like you should replace self._f with os.path.split(__file__)[1].
                                            You might also want to try one of the older versions (github history) since it seems like people checked in work without testing.

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