Advertisement
Guest User

Untitled

a guest
Feb 29th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. class VIEW3D_PT_snappanel_toolshelf(Panel):
  2. bl_label = "Snap"
  3. bl_space_type = 'VIEW_3D'
  4. bl_region_type = 'TOOLS'
  5. #bl_options = {'HIDE_HEADER'}
  6.  
  7. #show_text = ToolSelectPanelHelper._layout_generator_detect_from_region(layout, context.region, scale_y)
  8.  
  9. #show_text = False
  10.  
  11. @staticmethod
  12. def ts_width(layout, region, scale_y):
  13. """
  14. Choose an appropriate layout for the toolbar.
  15. """
  16. # Currently this just checks the width,
  17. # we could have different layouts as preferences too.
  18. system = bpy.context.preferences.system
  19. view2d = region.view2d
  20. view2d_scale = (
  21. view2d.region_to_view(1.0, 0.0)[0] -
  22. view2d.region_to_view(0.0, 0.0)[0]
  23. )
  24. width_scale = region.width * view2d_scale / system.ui_scale
  25.  
  26. if width_scale > 160.0:
  27. show_text = True
  28. else:
  29. show_text = False
  30.  
  31. return show_text
  32.  
  33.  
  34. def draw(self, _context):
  35. layout = self.layout
  36.  
  37. show_text = self.ts_width(layout, region, scale_y)
  38. print(show_text)
  39.  
  40. if show_text is True:
  41.  
  42. layout.operator("view3d.snap_selected_to_cursor", text="Selection to Cursor", icon = "SELECTIONTOCURSOR").use_offset = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement