Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
新增键值对编辑器
  • Loading branch information
Goodjooy authored Nov 12, 2019
1 parent ef3605c commit f6db8e5
Show file tree
Hide file tree
Showing 12 changed files with 1,878 additions and 33 deletions.
795 changes: 778 additions & 17 deletions core/assets/frame_design.fbp

Large diffs are not rendered by default.

864 changes: 863 additions & 1 deletion core/assets/names.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/assets/setting.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"input_clear": true, "finish_exit": false, "skip_exist": false, "open_dir": false, "use_cn": true, "make_new_dir": true, "export_copy": false, "input_filter_mesh": "^.+-mesh\\.[Oo][Bb][Jj]$", "input_filter_tex": "^.+\\.[Pp][Nn][Gg]$", "input_filter": 0, "output_group": 2}
{"input_clear": true, "finish_exit": false, "skip_exist": false, "open_dir": false, "use_cn": true, "make_new_dir": true, "export_copy": false, "input_filter_mesh": "^.+-mesh\\.[Oo][Bb][Jj]$", "input_filter_tex": "^.+\\.[Pp][Nn][Gg]$", "input_filter": 0, "output_group": 0}
Binary file modified core/src/frame_classes/__pycache__/design_frame.cpython-37.pyc
Binary file not shown.
Binary file modified core/src/frame_classes/__pycache__/main_frame.cpython-37.pyc
Binary file not shown.
Binary file not shown.
Binary file modified core/src/frame_classes/__pycache__/setting_frame.cpython-37.pyc
Binary file not shown.
116 changes: 104 additions & 12 deletions core/src/frame_classes/design_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,21 +218,17 @@ def __init__( self, parent ):

bSizer12 = wx.BoxSizer( wx.HORIZONTAL )

self.m_staticText2 = wx.StaticText( self.m_panel2, wx.ID_ANY, u"键值对设置", wx.DefaultPosition, wx.DefaultSize, 0 )
self.m_staticText2.Wrap( -1 )

bSizer12.Add( self.m_staticText2, 1, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )
self.m_button_updata_names = wx.Button( self.m_panel2, wx.ID_ANY, u"在线更新键-值对", wx.DefaultPosition, wx.DefaultSize, 0 )
bSizer12.Add( self.m_button_updata_names, 0, wx.ALL, 5 )

self.m_staticline12 = wx.StaticLine( self.m_panel2, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_VERTICAL )
bSizer12.Add( self.m_staticline12, 0, wx.EXPAND |wx.ALL, 5 )

self.m_bpButton1 = wx.BitmapButton( self.m_panel2, wx.ID_ANY, wx.NullBitmap, wx.DefaultPosition, wx.DefaultSize, wx.BU_AUTODRAW|0 )

self.m_bpButton1.SetBitmap( wx.ArtProvider.GetBitmap( wx.ART_NORMAL_FILE, wx.ART_BUTTON ) )
bSizer12.Add( self.m_bpButton1, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, 5 )
self.m_button_edit_names = wx.Button( self.m_panel2, wx.ID_ANY, u"编辑键-值对", wx.DefaultPosition, wx.DefaultSize, 0 )
bSizer12.Add( self.m_button_edit_names, 0, wx.ALL, 5 )


bSizer10.Add( bSizer12, 0, wx.EXPAND, 5 )
bSizer10.Add( bSizer12, 0, wx.ALIGN_CENTER_HORIZONTAL, 5 )


self.m_panel2.SetSizer( bSizer10 )
Expand Down Expand Up @@ -290,7 +286,8 @@ def __init__( self, parent ):

# Connect Events
self.Bind( wx.EVT_INIT_DIALOG, self.set_info )
self.m_bpButton1.Bind( wx.EVT_BUTTON, self.key_value_setting )
self.m_button_updata_names.Bind( wx.EVT_BUTTON, self.update_names )
self.m_button_edit_names.Bind( wx.EVT_BUTTON, self.edit_names )
self.m_sdbSizer1Apply.Bind( wx.EVT_BUTTON, self.apply_press )
self.m_sdbSizer1Cancel.Bind( wx.EVT_BUTTON, self.cancel_press )
self.m_sdbSizer1OK.Bind( wx.EVT_BUTTON, self.ok_press )
Expand All @@ -303,7 +300,10 @@ def __del__( self ):
def set_info( self, event ):
event.Skip()

def key_value_setting( self, event ):
def update_names( self, event ):
event.Skip()

def edit_names( self, event ):
event.Skip()

def apply_press( self, event ):
Expand All @@ -323,17 +323,109 @@ def ok_press( self, event ):
class MyDialogKetValueSetting ( wx.Dialog ):

def __init__( self, parent ):
wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_DIALOG_STYLE )
wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = u"编辑键值对", pos = wx.DefaultPosition, size = wx.Size( 256,512 ), style = wx.DEFAULT_DIALOG_STYLE )

self.SetSizeHints( wx.DefaultSize, wx.DefaultSize )

bSizer13 = wx.BoxSizer( wx.VERTICAL )

bSizer14 = wx.BoxSizer( wx.VERTICAL )

m_listBox_name_existChoices = []
self.m_listBox_name_exist = wx.ListBox( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, m_listBox_name_existChoices, wx.LB_ALWAYS_SB|wx.LB_HSCROLL|wx.LB_SINGLE )
bSizer14.Add( self.m_listBox_name_exist, 1, wx.ALL|wx.EXPAND, 5 )


bSizer13.Add( bSizer14, 1, wx.EXPAND, 5 )

self.m_staticline13 = wx.StaticLine( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_VERTICAL )
bSizer13.Add( self.m_staticline13, 0, wx.EXPAND |wx.ALL, 5 )

bSizer15 = wx.BoxSizer( wx.VERTICAL )

self.m_staticText3 = wx.StaticText( self, wx.ID_ANY, u"键【KEY】", wx.DefaultPosition, wx.DefaultSize, 0 )
self.m_staticText3.Wrap( -1 )

bSizer15.Add( self.m_staticText3, 1, wx.ALL|wx.EXPAND, 5 )

self.m_textCtrl_new_key = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
bSizer15.Add( self.m_textCtrl_new_key, 0, wx.ALL|wx.EXPAND, 5 )

self.m_staticText4 = wx.StaticText( self, wx.ID_ANY, u"值【value】", wx.DefaultPosition, wx.DefaultSize, 0 )
self.m_staticText4.Wrap( -1 )

bSizer15.Add( self.m_staticText4, 1, wx.ALL|wx.EXPAND|wx.ALIGN_CENTER_HORIZONTAL, 5 )

self.m_textCtrl_new_value = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
bSizer15.Add( self.m_textCtrl_new_value, 0, wx.ALL|wx.EXPAND, 5 )

self.m_staticline16 = wx.StaticLine( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL )
bSizer15.Add( self.m_staticline16, 0, wx.EXPAND |wx.ALL, 5 )

bSizer16 = wx.BoxSizer( wx.HORIZONTAL )

self.m_bpButton_import_names = wx.BitmapButton( self, wx.ID_ANY, wx.NullBitmap, wx.DefaultPosition, wx.DefaultSize, wx.BU_AUTODRAW|0 )

self.m_bpButton_import_names.SetBitmap( wx.ArtProvider.GetBitmap( wx.ART_PLUS, wx.ART_BUTTON ) )
bSizer16.Add( self.m_bpButton_import_names, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )

self.m_staticline17 = wx.StaticLine( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL|wx.LI_VERTICAL )
bSizer16.Add( self.m_staticline17, 0, wx.EXPAND |wx.ALL, 5 )

self.m_button_clear = wx.Button( self, wx.ID_ANY, u"清空", wx.DefaultPosition, wx.DefaultSize, 0 )
bSizer16.Add( self.m_button_clear, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )

self.m_button_add = wx.Button( self, wx.ID_ANY, u"添加", wx.DefaultPosition, wx.DefaultSize, 0 )
bSizer16.Add( self.m_button_add, 0, wx.ALL, 5 )


bSizer15.Add( bSizer16, 0, wx.EXPAND|wx.ALIGN_RIGHT, 5 )


bSizer13.Add( bSizer15, 0, wx.EXPAND, 5 )


self.SetSizer( bSizer13 )
self.Layout()

self.Centre( wx.BOTH )

# Connect Events
self.Bind( wx.EVT_CLOSE, self.close_save )
self.Bind( wx.EVT_INIT_DIALOG, self.editor_init )
self.m_listBox_name_exist.Bind( wx.EVT_LISTBOX, self.edit_exist_item )
self.m_listBox_name_exist.Bind( wx.EVT_LISTBOX_DCLICK, self.view_item )
self.m_bpButton_import_names.Bind( wx.EVT_BUTTON, self.import_names )
self.m_button_clear.Bind( wx.EVT_BUTTON, self.clear_item )
self.m_button_add.Bind( wx.EVT_BUTTON, self.add_item )

def __del__( self ):
pass


# Virtual event handlers, overide them in your derived class
def close_save( self, event ):
event.Skip()

def editor_init( self, event ):
event.Skip()

def edit_exist_item( self, event ):
event.Skip()

def view_item( self, event ):
event.Skip()

def import_names( self, event ):
event.Skip()

def clear_item( self, event ):
event.Skip()

def add_item( self, event ):
event.Skip()


###########################################################################
## Class MyDialogAddFace
###########################################################################
Expand Down
3 changes: 2 additions & 1 deletion core/src/frame_classes/main_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,12 @@ def setting(self, event):
:param event:
:return:
"""
self.__dialog = Setting(self, self.setting_info, self.work_path)
self.__dialog = Setting(self, self.setting_info, self.work_path, self.names)

self.__dialog.ShowModal()
# 重置设置
self.setting_info = self.__dialog.get_setting()
self.names=self.__dialog.get_names()

def resize(self, event):
"""
Expand Down
115 changes: 115 additions & 0 deletions core/src/frame_classes/names_edit_frame.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import json
import os
from collections import OrderedDict

import wx

from core.src.frame_classes.design_frame import MyDialogKetValueSetting


class NamesEditFrame(MyDialogKetValueSetting):
def __init__(self, parent, names, path):
super(NamesEditFrame, self).__init__(parent)
self.names = names
self.edit_group = OrderedDict(self.names)
self.key_group = list(self.edit_group.keys())
self.show_list = []
self.path = path
self.is_changed = False

@staticmethod
def string_format(key, value):
return f'"{key}"->"{value}"'

def get_names(self):
return self.names

def clear_data(self):
self.m_textCtrl_new_value.Clear()
self.m_textCtrl_new_key.Clear()

def editor_init(self, event):
for key, item in self.edit_group.items():
self.show_list.append(f'"{key}"->"{item}"')

self.m_listBox_name_exist.Clear()
self.m_listBox_name_exist.Set(self.show_list)

def view_item(self, event):
index = event.GetSelection()
key = self.key_group[index]
value = self.edit_group.get(key)
wx.MessageBox(f"'{key}'->'{value}'", "信息")

def edit_exist_item(self, event):
index = event.GetSelection()
key = self.key_group[index]
value = self.edit_group.get(key)

self.m_textCtrl_new_key.SetValue(key)
self.m_textCtrl_new_value.SetValue(value)

def add_item(self, event):
key = self.m_textCtrl_new_key.GetValue()
value = self.m_textCtrl_new_value.GetValue()

if key == "" or value == "":
wx.MessageBox("键或值不能为空白!", "错误", wx.ICON_ERROR)

else:
if key in self.key_group:
index = self.key_group.index(key)
feedback = wx.MessageBox(f"【{key}】已经存在键组中,点击【确认】将会使用新值覆盖", "信息", wx.YES_NO | wx.ICON_INFORMATION)
if feedback == wx.YES:
self.edit_group[key] = value
self.m_listBox_name_exist.SetString(index, f'"{key}"->"{value}"')
self.is_changed = True

else:
self.key_group.append(key)
self.edit_group[key] = value
self.is_changed = True
self.m_listBox_name_exist.Append(f'"{key}"->"{value}"')

self.clear_data()

def clear_item(self, event):
self.clear_data()

def import_names(self, event):
overwrite = 0
new_item = 0
dialog = wx.FileDialog(self, "加载键值对文件(json)", os.path.join(self.path, "core\\assets"), "names.json", "*json",
wx.FD_FILE_MUST_EXIST | wx.FD_OPEN)
is_ok = dialog.ShowModal()
if is_ok:
try:
with open(dialog.GetPath(), "r")as file:
temple = json.load(file)
for key, item in temple.items():
if not isinstance(item, str):
raise TypeError("不可用文件")
self.edit_group[key] = item
if key in self.key_group:
overwrite += 1
index = self.key_group.index(key)
self.m_listBox_name_exist.SetString(index, self.string_format(key, item))
else:
new_item += 1
self.m_listBox_name_exist.Append(self.string_format(key, item))

wx.MessageBox(f"导入键值对文件成功!\n\t覆盖:{overwrite}\n\t新增:{new_item}", "信息")
self.is_changed=True
except Exception as info:
wx.MessageBox(f"导入键值对文件出现错误!\n{info.__str__()}")

def close_save(self, event):
if self.is_changed:
feedback = wx.MessageBox("要应用这些变化吗?", "信息", wx.ICON_INFORMATION | wx.YES_NO)
if feedback == wx.YES:
with open(os.path.join(self.path, "core\\assets\\names.json"), "w")as file:
json.dump(self.edit_group, file, indent=4)

self.names = dict(self.edit_group)

super(NamesEditFrame, self).close_save(event)
16 changes: 15 additions & 1 deletion core/src/frame_classes/setting_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
import wx

from core.src.frame_classes.design_frame import MyDialogSetting
from core.src.frame_classes.names_edit_frame import NamesEditFrame
from core.src.static_classes.image_deal import ImageWork
from core.src.static_classes.static_data import GlobalData
from core.src.structs_classes.setting_structs import SettingHolder, PerSetting


class Setting(MyDialogSetting):

def __init__(self, parent, setting_info, work_path):
def __init__(self, parent, setting_info, work_path, names):
super(Setting, self).__init__(parent)
self.names = names
self.frame = parent
self.setting = setting_info
self.path = work_path

self.data = GlobalData()

pic, _ = ImageWork.pic_transform(os.path.join(self.path, "core\\assets\\img.png"),
Expand Down Expand Up @@ -91,5 +94,16 @@ def cancel_press(self, event):
def apply_press(self, event):
self.save_info()

def update_names(self, event):
wx.MessageBox("敬请期待", "信息", wx.ICON_INFORMATION)

def edit_names(self, event):
dialog = NamesEditFrame(self, self.names, self.path)
dialog.ShowModal()
self.names = dialog.get_names()

def get_setting(self):
return self.setting

def get_names(self):
return self.names
Binary file modified core/src/thread_classes/__pycache__/extract_thread.cpython-37.pyc
Binary file not shown.

0 comments on commit f6db8e5

Please sign in to comment.