Use separate root objects to gather the sample visualization and the
[blender-addons-contrib.git] / text_editor_pasteall.py
index 7f4826bc0e10e7900b652e9ab24afe843a7c7fc3..fa5f8effea6d568c179ce11ee41581cf90608e71 100644 (file)
 #
 # ##### END GPL LICENSE BLOCK #####
 
+bl_info = {
+    "name": "PasteAll",
+    "author": "Dalai Felinto (dfelinto)",
+    "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.6/Py/"
+        "Scripts/Text_Editor/PasteAll",
+    "tracker_url": "https://developer.blender.org/T23493",
+    "category": "Text Editor"}
+
 # ########################################################
 # PasteAll.org Text Sender Script
 #
 #
 # ########################################################
 
-bl_addon_info = {
-    "name": "PasteAll",
-    "author": "Dalai Felinto (dfelinto)",
-    "version": (0,5),
-    "blender": (2, 5, 4),
-    "api": 31865,
-    "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/"\
-        "Scripts/Text_Editor/PasteAll",
-    "tracker_url": "https://projects.blender.org/tracker/index.php?"\
-        "func=detail&aid=23493&group_id=153&atid=468",
-    "category": "Text Editor"}
 
 import bpy
 import urllib
@@ -58,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"
 
@@ -82,7 +81,7 @@ class PasteAllOperator(bpy.types.Operator):
         # get the selected text
         text = self.get_selected_text(st.text)
         # if no text is selected send the whole file
-        if text == None: text = st.text.as_string()
+        if text is None: text = st.text.as_string()
 
         # get the file type based on the extension
         format = self.get_file_format(st.text)
@@ -90,18 +89,18 @@ class PasteAllOperator(bpy.types.Operator):
         # send the text and receive the returned page
         html = self.send_text(text, format)
 
-        if html == None:
-            self.report('ERROR', "Error in sending the text to the server.")
+        if html is None:
+            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 == None or page == "":
-            self.report('ERROR', "Error in retrieving the page.")
+
+        if page is None or 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
@@ -110,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',
@@ -124,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()
@@ -134,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>")
@@ -145,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:
@@ -191,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',
@@ -209,9 +208,13 @@ def register():
         description='Opens the page with the submitted text.',
         default=True)
 
+    bpy.utils.register_module(__name__)
+
 def unregister():
-    bpy.types.Scene.RemoveProperty("use_webbrowser")
+    del bpy.types.Scene.use_webbrowser
+    bpy.utils.unregister_module(__name__)
 
 if __name__ == "__main__":
     register()
 
+