Use separate root objects to gather the sample visualization and the
[blender-addons-contrib.git] / text_editor_pasteall.py
index 0d5923466dee7be4aef5513392a7183bd08fa0d4..fa5f8effea6d568c179ce11ee41581cf90608e71 100644 (file)
 bl_info = {
     "name": "PasteAll",
     "author": "Dalai Felinto (dfelinto)",
-    "version": (0,6),
-    "blender": (2, 5, 7),
-    "api": 36007,
+    "version": (0, 7),
+    "blender": (2, 60, 0),
     "location": "Text editor > Properties panel",
     "description": "Send your selection or text to www.pasteall.org",
-    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\
+    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
         "Scripts/Text_Editor/PasteAll",
-    "tracker_url": "https://projects.blender.org/tracker/index.php?"\
-        "func=detail&aid=23493",
+    "tracker_url": "https://developer.blender.org/T23493",
     "category": "Text Editor"}
 
 # ########################################################
@@ -59,12 +57,12 @@ class TEXT_PT_pasteall(bpy.types.Panel):
     bl_label = "PasteAll.org"
 
     def draw(self, context):
-        layout = self.layout        
+        layout = self.layout
         layout.operator("text.pasteall", icon='URL')
         layout.prop(context.scene, "use_webbrowser")
 
 class TEXT_OT_pasteall(bpy.types.Operator):
-    ''''''
+    """"""
     bl_idname = "text.pasteall"
     bl_label = "PasteAll.org"
     bl_description = "Send the current text or selection to www.pasteall.org"
@@ -92,32 +90,31 @@ class TEXT_OT_pasteall(bpy.types.Operator):
         html = self.send_text(text, format)
 
         if html is None:
-            self.report('ERROR', "Error in sending the text to the server.")
+            self.report({'ERROR'}, "Error in sending the text to the server.")
             return {'CANCELLED'}
 
         # get the link of the posted page
         page = self.get_page(str(html))
-        
+
         if page is None or page == "":
-            self.report('ERROR', "Error in retrieving the page.")
+            self.report({'ERROR'}, "Error in retrieving the page.")
             return {'CANCELLED'}
         else:
-            self.report('INFO', page)
+            self.report({'INFO'}, page)
 
         # store the link in the clipboard
         bpy.context.window_manager.clipboard = page
 
         if context.scene.use_webbrowser:
             try:
-                _webbrowser_bug_fix()
                 webbrowser.open_new_tab(page)
             except:
-                self.report('WARNING', "Error in opening the page %s." % (page))
+                self.report({'WARNING'}, "Error in opening the page %s." % (page))
 
         return {'FINISHED'}
-            
+
     def send_text(self, text, format):
-        ''''''
+        """"""
         import urllib
         url = "http://www.pasteall.org/index.php"
         values = {  'action' : 'savepaste',
@@ -136,7 +133,7 @@ class TEXT_OT_pasteall(bpy.types.Operator):
             return page_source
 
     def get_page(self, html):
-        ''''''
+        """"""
         id = html.find('directlink')
         id_begin = id + 12 # hardcoded: directlink">
         id_end = html[id_begin:].find("</a>")
@@ -147,13 +144,13 @@ class TEXT_OT_pasteall(bpy.types.Operator):
             return None
 
     def get_selected_text(self, text):
-        ''''''
+        """"""
         current_line = text.current_line
         select_end_line = text.select_end_line
-        
+
         current_character = text.current_character
         select_end_character = text.select_end_character
-        
+
         # if there is no selected text return None
         if current_line == select_end_line:
             if current_character == select_end_character:
@@ -193,9 +190,9 @@ class TEXT_OT_pasteall(bpy.types.Operator):
                         continue
 
         return text_return
-    
+
     def get_file_format(self, text):
-        '''Try to guess what is the format based on the file extension'''
+        """Try to guess what is the format based on the file extension"""
         extensions =   {'diff':'24',
                         'patch':'24',
                         'py':'62',
@@ -220,65 +217,4 @@ def unregister():
 if __name__ == "__main__":
     register()
 
-def _webbrowser_bug_fix():
-    """hack copied from wm.py"""
-    # test for X11
-    import os
-
-    if os.environ.get("DISPLAY"):
-
-        # BSD licenced code copied from python, temp fix for bug
-        # http://bugs.python.org/issue11432, XXX == added code
-        def _invoke(self, args, remote, autoraise):
-            # XXX, added imports
-            import io
-            import subprocess
-            import time
-
-            raise_opt = []
-            if remote and self.raise_opts:
-                # use autoraise argument only for remote invocation
-                autoraise = int(autoraise)
-                opt = self.raise_opts[autoraise]
-                if opt:
-                    raise_opt = [opt]
-
-            cmdline = [self.name] + raise_opt + args
-
-            if remote or self.background:
-                inout = io.open(os.devnull, "r+")
-            else:
-                # for TTY browsers, we need stdin/out
-                inout = None
-            # if possible, put browser in separate process group, so
-            # keyboard interrupts don't affect browser as well as Python
-            setsid = getattr(os, 'setsid', None)
-            if not setsid:
-                setsid = getattr(os, 'setpgrp', None)
-
-            p = subprocess.Popen(cmdline, close_fds=True,  # XXX, stdin=inout,
-                                 stdout=(self.redirect_stdout and inout or None),
-                                 stderr=inout, preexec_fn=setsid)
-            if remote:
-                # wait five secons. If the subprocess is not finished, the
-                # remote invocation has (hopefully) started a new instance.
-                time.sleep(1)
-                rc = p.poll()
-                if rc is None:
-                    time.sleep(4)
-                    rc = p.poll()
-                    if rc is None:
-                        return True
-                # if remote call failed, open() will try direct invocation
-                return not rc
-            elif self.background:
-                if p.poll() is None:
-                    return True
-                else:
-                    return False
-            else:
-                return not p.wait()
-
-        import webbrowser
-        webbrowser.UnixBrowser._invoke = _invoke