Use separate root objects to gather the sample visualization and the
[blender-addons-contrib.git] / text_editor_pasteall.py
index 6f74e777099c6903766b136aba3095d90bb58c2e..fa5f8effea6d568c179ce11ee41581cf90608e71 100644 (file)
 bl_info = {
     "name": "PasteAll",
     "author": "Dalai Felinto (dfelinto)",
-    "version": (0,5),
-    "blender": (2, 5, 4),
-    "api": 31999,
+    "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,13 +57,13 @@ class TEXT_PT_pasteall(bpy.types.Panel):
     bl_label = "PasteAll.org"
 
     def draw(self, context):
-        layout = self.layout        
-        layout.operator("text.PasteAll", icon='URL')
+        layout = self.layout
+        layout.operator("text.pasteall", icon='URL')
         layout.prop(context.scene, "use_webbrowser")
 
-class PasteAllOperator(bpy.types.Operator):
-    ''''''
-    bl_idname = "text.PasteAll"
+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,17 +90,17 @@ class PasteAllOperator(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
@@ -111,12 +109,12 @@ class PasteAllOperator(bpy.types.Operator):
             try:
                 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',
@@ -125,7 +123,7 @@ class PasteAllOperator(bpy.types.Operator):
                     'code' : text }
 
         try:
-            data = urllib.parse.urlencode(values)
+            data = urllib.parse.urlencode(values).encode()
             req = urllib.request.Request(url, data)
             response = urllib.request.urlopen(req)
             page_source = response.read()
@@ -135,7 +133,7 @@ class PasteAllOperator(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>")
@@ -146,13 +144,13 @@ class PasteAllOperator(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:
@@ -192,9 +190,9 @@ class PasteAllOperator(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',
@@ -210,9 +208,13 @@ def register():
         description='Opens the page with the submitted text.',
         default=True)
 
+    bpy.utils.register_module(__name__)
+
 def unregister():
     del bpy.types.Scene.use_webbrowser
+    bpy.utils.unregister_module(__name__)
 
 if __name__ == "__main__":
     register()
 
+