Skip to content

Commit

Permalink
新增在图像编辑器查看高清大图功能,增加防社死按钮
Browse files Browse the repository at this point in the history
  • Loading branch information
zk-wz committed Feb 15, 2022
1 parent 0c7377f commit 3c09f3e
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 5 deletions.
7 changes: 6 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"author" : "掌控-物质",
"description" : "能让你在blender更方便的追(mo)番(yu)",
"blender" : (2, 80, 0),
"version" : (1, 1, 0),
"version" : (1, 3, 0),
"location" : "",
"warning" : "",
"category" : "Bangumi"
Expand Down Expand Up @@ -36,9 +36,14 @@
Bangumi_Calendar,

Imgapi_Refresh,
Switch_to_ImgEditor,
rand_img_father_panel,
Rand_Img_Settings,
Rand_Img_Pic,

ImgEditor_RandImg_Refresh,
Quick_Switch,
imgeditor_randimg_father,

Refresh_Yiyan,
yiyan_father_panel,
Expand Down
2 changes: 1 addition & 1 deletion imgapi_spider.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def imgapi_dl(imgapi_style,imgapi_category):
if not os.path.exists(pic_path):
os.makedirs(pic_path)

pic_path = os.path.join(pic_path, "img.jpg")
pic_path = os.path.join(pic_path, "rand_img.jpg")

with open(pic_path, 'wb') as f:
f.write(img.content)
Expand Down
69 changes: 69 additions & 0 deletions operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,68 @@ def execute(self, context):
return {"FINISHED"}


class ImgEditor_RandImg_Refresh(bpy.types.Operator):
bl_idname = "bangumi.img_editor_rand_img_refresh"
bl_label = "刷新图片"
bl_description = "刷新图片"
bl_options = {"REGISTER"}

@classmethod
def poll(cls, context):
return True

def execute(self, context):
ui.imgapi_unregister()

bangumi_property=context.scene.bangumi_property
imgapi_spider.imgapi_dl(bangumi_property.imgapi_style,bangumi_property.imgapi_category)

if not test_img_exist():
pic_path=os.path.join(os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), "img"), "rand_img"), "rand_img.jpg")
bpy.ops.image.open(filepath=pic_path)

bpy.ops.image.reload()

ui.imgapi_register()
return {"FINISHED"}


class Quick_Switch(bpy.types.Operator):
bl_idname = "bangumi.quick_switch"
bl_label = "防社死"
bl_description = "防社死"
bl_options = {"REGISTER"}

@classmethod
def poll(cls, context):
return True

def execute(self, context):
context.area.ui_type = "VIEW_3D"
return {"FINISHED"}


class Switch_to_ImgEditor(bpy.types.Operator):
bl_idname = "bangumi.switch_to_img_editor"
bl_label = "在图片编辑器中打开"
bl_description = "在图片编辑器中打开"
bl_options = {"REGISTER"}

@classmethod
def poll(cls, context):
return True

def execute(self, context):
if not test_img_exist():
pic_path=os.path.join(os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), "img"), "rand_img"), "rand_img.jpg")
bpy.ops.image.open(filepath=pic_path)

context.area.ui_type = "IMAGE_EDITOR"
bpy.ops.image.reload()
return {"FINISHED"}




class Change_calender(bpy.types.Operator):
bl_idname = "bangumi.change_calender"
Expand Down Expand Up @@ -200,6 +262,13 @@ def execute(self, context):
return {"FINISHED"}


def test_img_exist():
for i in bpy.data.images:
if i.name == "rand_img.jpg":
return True
return False


def get_yiyan():
yiyan_path=os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), "src"), "yiyan")
with open(yiyan_path,"rb") as f:
Expand Down
38 changes: 36 additions & 2 deletions ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ def draw(self, context):
refresh=row2.column()
refresh.operator("bangumi.imgapi_refresh",text="",icon='FILE_REFRESH')

row3=layout.row()
row3.operator("bangumi.switch_to_img_editor",icon="OUTLINER_OB_IMAGE")


#随机涩图图片显示面板
class Rand_Img_Pic(bpy.types.Panel,Bangumi_Panel):
Expand All @@ -197,11 +200,41 @@ class Rand_Img_Pic(bpy.types.Panel,Bangumi_Panel):
bl_parent_id = "N_PT_Rand_Img_Father"

def draw(self, context):
layout = self.layout
layout = self.layout.box()
pic = other_pic["imgapi"]["rand_img"]
pic_scale = context.scene.bangumi_property.imgapi_scale
layout.template_icon(pic.icon_id,scale=pic_scale)

#随机涩图图像编辑器总面板
class imgeditor_randimg_father(bpy.types.Panel):
bl_idname = "N_PT_ImgEditor_RandImg_Father"
bl_label = "随机涩图"
bl_space_type = "IMAGE_EDITOR"
bl_region_type = "UI"
bl_category = "涩涩"

def draw_header(self,context):
self.layout.label(text="",icon='FUND')

def draw(self, context):
layout = self.layout
bangumi_property = context.scene.bangumi_property

style=layout.row()
if bangumi_property.imgapi_category != "cosplay":
style.prop(bangumi_property,"imgapi_style")

category=layout.row()
category.prop(bangumi_property,"imgapi_category")

refresh=layout.row()
refresh.operator("bangumi.img_editor_rand_img_refresh",icon='FILE_REFRESH')

row3=layout.row()
row3.operator("bangumi.quick_switch",icon='ERROR')




class yiyan_father_panel(bpy.types.Panel,Bangumi_Panel):
bl_idname = "N_PT_Yiyan_Father"
Expand Down Expand Up @@ -229,6 +262,7 @@ class Yiyan(bpy.types.Panel,Bangumi_Panel):
bl_label = "一言"
bl_parent_id = "N_PT_Yiyan_Father"


def draw(self, context):
layout = self.layout.box().column(align=True)
layout.operator("bangumi.nothing",text=context.scene.bangumi_property.yiyan,emboss=False)
Expand Down Expand Up @@ -348,7 +382,7 @@ def ui_unregister():
# 将imgapi封面导入为blender icon
def imgapi_register():
imgapi_pic2icon = bpy.utils.previews.new()
imgapi_pic_path=os.path.join(os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), "img"), "rand_img"), 'img.jpg')
imgapi_pic_path=os.path.join(os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), "img"), "rand_img"), 'rand_img.jpg')
error_path=os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), "img"), "error.png")
try:
if not os.path.exists(imgapi_pic_path):
Expand Down
2 changes: 1 addition & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class bangumi_props(bpy.types.PropertyGroup):
("suiji","随机","随机")
]
imgapi_category:bpy.props.EnumProperty(items=ImgApi_Categories, name="图片类型", default="dongman")
imgapi_scale:bpy.props.FloatProperty(name="图片缩放", default=12.0)
imgapi_scale:bpy.props.FloatProperty(name="图片缩放", default=10.0)

yiyan=get_yiyan()
yiyan:bpy.props.StringProperty(name="一言", default=get_yiyan_saying(yiyan))
Expand Down

0 comments on commit 3c09f3e

Please sign in to comment.