Skip to content

Instantly share code, notes, and snippets.

@sambler
Created May 10, 2017 10:53
Show Gist options
  • Save sambler/f3941e682527df428c40ce212f3c9374 to your computer and use it in GitHub Desktop.
Save sambler/f3941e682527df428c40ce212f3c9374 to your computer and use it in GitHub Desktop.
Small blender addon to toggle the DPI settings
# made for https://blender.stackexchange.com/q/79333/935
bl_info = {
"name": "Set DPI",
"author": "sambler",
"version": (1, 0),
"blender": (2, 75, 0),
"location": "Info header",
"description": "Toggle between two DPI settings",
"category": "System",
}
import bpy
low_res_dpi = 72
hi_res_dpi = 120
class SetDPI(bpy.types.Operator):
bl_idname = 'wm.set_dpi'
bl_label = 'Toggle dpi setting'
def execute(self, context):
syspref = context.user_preferences.system
if syspref.dpi <= low_res_dpi:
syspref.dpi = hi_res_dpi
else:
syspref.dpi = low_res_dpi
return {'FINISHED'}
def SetDPI_menu(self, context):
if context.user_preferences.system.dpi <= low_res_dpi:
i = 'FULLSCREEN_ENTER'
else:
i = 'FULLSCREEN_EXIT'
self.layout.operator( SetDPI.bl_idname, text="", icon=i )
def register():
bpy.utils.register_class(SetDPI)
bpy.types.INFO_HT_header.prepend(SetDPI_menu)
def unregister():
bpy.types.INFO_HT_header.remove(SetDPI_menu)
bpy.utils.unregister_class(SetDPI)
if __name__ == "__main__":
register()
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment