diff --git a/GUI.py b/GUI.py index 5fa9ea8..5e91033 100644 --- a/GUI.py +++ b/GUI.py @@ -34,7 +34,7 @@ def __init__( self, parent ): wSizer_L1 = wx.WrapSizer( wx.HORIZONTAL, wx.WRAPSIZER_DEFAULT_FLAGS ) - self.version = wx.Button( self, wx.ID_ANY, u"#V000.00.00", wx.DefaultPosition, wx.Size( 80,25 ), wx.BORDER_NONE ) + self.version = wx.Button( self, wx.ID_ANY, u"#V000.00.00", wx.DefaultPosition, wx.Size( 80,25 ), wx.BORDER_NONE|wx.BU_LEFT ) self.version.SetForegroundColour( wx.Colour( 255, 255, 255 ) ) self.version.SetBackgroundColour( wx.Colour( 242, 171, 57 ) ) @@ -46,7 +46,7 @@ def __init__( self, parent ): wSizer_L1.Add( self.Network, 0, 0, 5 ) - self.Weather = wx.Button( self, wx.ID_ANY, u"---", wx.DefaultPosition, wx.Size( 90,25 ), wx.BORDER_NONE ) + self.Weather = wx.Button( self, wx.ID_ANY, u"---", wx.DefaultPosition, wx.Size( 90,25 ), wx.BORDER_NONE|wx.BU_LEFT ) self.Weather.SetFont( wx.Font( 8, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, "Microsoft YaHei UI" ) ) self.Weather.SetForegroundColour( wx.Colour( 255, 255, 255 ) ) self.Weather.SetBackgroundColour( wx.Colour( 242, 171, 57 ) ) diff --git a/GUI_Music.py b/GUI_Music.py index f0c123e..e71813e 100644 --- a/GUI_Music.py +++ b/GUI_Music.py @@ -17,45 +17,94 @@ class Main ( wx.Frame ): def __init__( self, parent ): - wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"Music", pos = wx.DefaultPosition, size = wx.Size( 400,300 ), style = wx.CAPTION|wx.CLOSE_BOX|wx.TAB_TRAVERSAL ) + wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"Music", pos = wx.DefaultPosition, size = wx.Size( 400,310 ), style = wx.CAPTION|wx.CLOSE_BOX|wx.TAB_TRAVERSAL ) self.SetSizeHints( wx.DefaultSize, wx.DefaultSize ) self.SetBackgroundColour( wx.Colour( 255, 255, 255 ) ) bSizer2 = wx.BoxSizer( wx.VERTICAL ) + self.NoteBook = wx.Notebook( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0 ) + self.A = wx.Panel( self.NoteBook, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL ) + bSizer21 = wx.BoxSizer( wx.VERTICAL ) + wSizer1 = wx.WrapSizer( wx.HORIZONTAL, wx.WRAPSIZER_DEFAULT_FLAGS ) - self.File = wx.FilePickerCtrl( self, wx.ID_ANY, wx.EmptyString, u"Select a file", u"wav File|*.wav|mp3 File|*.mp3|ogg File|*.ogg|flac File|*.flac", wx.DefaultPosition, wx.Size( 300,-1 ), wx.FLP_FILE_MUST_EXIST|wx.FLP_OPEN|wx.FLP_SMALL|wx.FLP_USE_TEXTCTRL ) + self.File = wx.FilePickerCtrl( self.A, wx.ID_ANY, wx.EmptyString, u"Select a file", u"wav File|*.wav|mp3 File|*.mp3|ogg File|*.ogg|flac File|*.flac", wx.DefaultPosition, wx.Size( 285,-1 ), wx.FLP_FILE_MUST_EXIST|wx.FLP_OPEN|wx.FLP_SMALL|wx.FLP_USE_TEXTCTRL ) wSizer1.Add( self.File, 0, wx.ALL, 5 ) - self.B_Play = wx.Button( self, wx.ID_ANY, u"Play", wx.DefaultPosition, wx.Size( 60,-1 ), 0 ) + self.B_Play = wx.Button( self.A, wx.ID_ANY, u"Play", wx.DefaultPosition, wx.Size( 60,-1 ), 0 ) wSizer1.Add( self.B_Play, 0, wx.ALL, 5 ) - bSizer2.Add( wSizer1, 0, 0, 5 ) + bSizer21.Add( wSizer1, 0, 0, 5 ) InfoChoices = [] - self.Info = wx.ListBox( self, wx.ID_ANY, wx.DefaultPosition, wx.Size( 400,150 ), InfoChoices, wx.LB_NEEDED_SB ) - bSizer2.Add( self.Info, 0, wx.ALL, 5 ) + self.Info = wx.ListBox( self.A, wx.ID_ANY, wx.DefaultPosition, wx.Size( 400,150 ), InfoChoices, wx.LB_NEEDED_SB ) + bSizer21.Add( self.Info, 0, wx.ALL, 5 ) wSizer2 = wx.WrapSizer( wx.HORIZONTAL, wx.WRAPSIZER_DEFAULT_FLAGS ) - self.m_staticText1 = wx.StaticText( self, wx.ID_ANY, u"Export:", wx.DefaultPosition, wx.DefaultSize, 0 ) + self.m_staticText1 = wx.StaticText( self.A, wx.ID_ANY, u"Export:", wx.DefaultPosition, wx.DefaultSize, 0 ) self.m_staticText1.Wrap( -1 ) wSizer2.Add( self.m_staticText1, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) Save_TypeChoices = [ u"OGG", u"MP3", u"WAV" ] - self.Save_Type = wx.Choice( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, Save_TypeChoices, 0 ) + self.Save_Type = wx.Choice( self.A, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, Save_TypeChoices, 0 ) self.Save_Type.SetSelection( 0 ) wSizer2.Add( self.Save_Type, 0, wx.ALL, 5 ) - self.Save = wx.FilePickerCtrl( self, wx.ID_ANY, wx.EmptyString, u"Save as", u"*.*", wx.DefaultPosition, wx.DefaultSize, wx.FLP_SAVE ) + self.Save = wx.FilePickerCtrl( self.A, wx.ID_ANY, wx.EmptyString, u"Save as", u"*.*", wx.DefaultPosition, wx.DefaultSize, wx.FLP_SAVE ) wSizer2.Add( self.Save, 0, wx.ALL, 5 ) - bSizer2.Add( wSizer2, 0, 0, 5 ) + bSizer21.Add( wSizer2, 0, 0, 5 ) + + + self.A.SetSizer( bSizer21 ) + self.A.Layout() + bSizer21.Fit( self.A ) + self.NoteBook.AddPage( self.A, u"格式转换器", False ) + self.B = wx.Panel( self.NoteBook, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL ) + bSizer3 = wx.BoxSizer( wx.VERTICAL ) + + wSizer3 = wx.WrapSizer( wx.HORIZONTAL, wx.WRAPSIZER_DEFAULT_FLAGS ) + + self.m_staticText2 = wx.StaticText( self.B, wx.ID_ANY, u"缓存文件夹", wx.DefaultPosition, wx.DefaultSize, 0 ) + self.m_staticText2.Wrap( -1 ) + + wSizer3.Add( self.m_staticText2, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) + + self.B_CachePath = wx.DirPickerCtrl( self.B, wx.ID_ANY, wx.EmptyString, u"Select a folder", wx.DefaultPosition, wx.Size( 250,-1 ), wx.DIRP_DEFAULT_STYLE ) + wSizer3.Add( self.B_CachePath, 0, wx.ALL, 5 ) + + + bSizer3.Add( wSizer3, 0, wx.ALIGN_CENTER_HORIZONTAL, 5 ) + + wSizer31 = wx.WrapSizer( wx.HORIZONTAL, wx.WRAPSIZER_DEFAULT_FLAGS ) + + self.m_staticText21 = wx.StaticText( self.B, wx.ID_ANY, u"导出文件夹", wx.DefaultPosition, wx.DefaultSize, 0 ) + self.m_staticText21.Wrap( -1 ) + + wSizer31.Add( self.m_staticText21, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) + + self.B_ExportPath = wx.DirPickerCtrl( self.B, wx.ID_ANY, wx.EmptyString, u"Select a folder", wx.DefaultPosition, wx.Size( 250,-1 ), wx.DIRP_DEFAULT_STYLE ) + wSizer31.Add( self.B_ExportPath, 0, wx.ALL, 5 ) + + + bSizer3.Add( wSizer31, 0, wx.ALIGN_CENTER_HORIZONTAL, 5 ) + + self.B_BRUN = wx.Button( self.B, wx.ID_ANY, u"导出", wx.DefaultPosition, wx.Size( 200,-1 ), 0 ) + bSizer3.Add( self.B_BRUN, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5 ) + + + self.B.SetSizer( bSizer3 ) + self.B.Layout() + bSizer3.Fit( self.B ) + self.NoteBook.AddPage( self.B, u"网易云缓存转换器", True ) + + bSizer2.Add( self.NoteBook, 1, wx.EXPAND |wx.ALL, 5 ) self.SetSizer( bSizer2 ) @@ -68,6 +117,7 @@ def __init__( self, parent ): self.File.Bind( wx.EVT_FILEPICKER_CHANGED, self.import_file ) self.B_Play.Bind( wx.EVT_BUTTON, self.Play ) self.Save.Bind( wx.EVT_FILEPICKER_CHANGED, self.SaveOnFileChanged ) + self.B_BRUN.Bind( wx.EVT_BUTTON, self.B_RUN ) def __del__( self ): pass @@ -86,4 +136,7 @@ def Play( self, event ): def SaveOnFileChanged( self, event ): event.Skip() + def B_RUN( self, event ): + event.Skip() + diff --git a/GUI_SSC.py b/GUI_SSC.py index e9f3b6d..ece48c1 100644 --- a/GUI_SSC.py +++ b/GUI_SSC.py @@ -194,7 +194,7 @@ def __init__( self, parent ): self.A.SetSizer( bSizer21 ) self.A.Layout() bSizer21.Fit( self.A ) - self.NoteBook.AddPage( self.A, u"条形码登记", True ) + self.NoteBook.AddPage( self.A, u"条形码登记", False ) self.m_panel2 = wx.Panel( self.NoteBook, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL ) bSizer4 = wx.BoxSizer( wx.VERTICAL ) @@ -267,6 +267,34 @@ def __init__( self, parent ): self.D.Layout() bSizer61.Fit( self.D ) self.NoteBook.AddPage( self.D, u"节点", False ) + self.E = wx.Panel( self.NoteBook, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL ) + bSizer62 = wx.BoxSizer( wx.VERTICAL ) + + self.E_FilePath = wx.StaticText( self.E, wx.ID_ANY, u"---", wx.DefaultPosition, wx.Size( 250,-1 ), 0 ) + self.E_FilePath.Wrap( -1 ) + + bSizer62.Add( self.E_FilePath, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5 ) + + self.E_Tip = wx.StaticText( self.E, wx.ID_ANY, u"---", wx.DefaultPosition, wx.Size( 250,-1 ), 0 ) + self.E_Tip.Wrap( -1 ) + + bSizer62.Add( self.E_Tip, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5 ) + + self.E_QRcode = wx.Button( self.E, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.Size( 300,300 ), wx.BORDER_NONE ) + self.E_QRcode.SetBackgroundColour( wx.Colour( 192, 192, 192 ) ) + + bSizer62.Add( self.E_QRcode, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5 ) + + self.E_SendBottom = wx.Button( self.E, wx.ID_ANY, u"开始传输", wx.DefaultPosition, wx.Size( 250,-1 ), 0 ) + self.E_SendBottom.Enable( False ) + + bSizer62.Add( self.E_SendBottom, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5 ) + + + self.E.SetSizer( bSizer62 ) + self.E.Layout() + bSizer62.Fit( self.E ) + self.NoteBook.AddPage( self.E, u"传输", True ) bSizer2.Add( self.NoteBook, 0, 0, 0 ) @@ -297,6 +325,7 @@ def __init__( self, parent ): self.A_GRID.Bind( wx.EVT_KEY_DOWN, self.Hot_Key_Down ) self.A_GRID.Bind( wx.EVT_KILL_FOCUS, self.A_GRIDOnKillFocus ) self.C_PathBox.Bind( wx.EVT_LISTBOX, self.C_Check ) + self.E_SendBottom.Bind( wx.EVT_BUTTON, self.E_Send ) def __del__( self ): pass @@ -353,4 +382,7 @@ def A_GRIDOnKillFocus( self, event ): def C_Check( self, event ): event.Skip() + def E_Send( self, event ): + event.Skip() + diff --git a/M_Music.py b/M_Music.py index 339adba..17060f0 100644 --- a/M_Music.py +++ b/M_Music.py @@ -6,6 +6,7 @@ import GUI_Music import pydub,pydub.playback +import Netease_cloud_CaChe # 网易云音乐缓存转换MP3算法 ############################## # GUI的函数桥接 @@ -17,6 +18,8 @@ def __init__(self, parent): # 定义主函数 GUI_Music.Main.__init__(self, parent) + self.NoteBook.SetSelection(0) + def import_file(self, event): global audio_data @@ -58,6 +61,20 @@ def SaveOnFileChanged(self, event): elif self.Save_Type.GetString(self.Save_Type.GetSelection()) == 'WAV': audio_data.export(self.Save.GetPath() + '.wav', format="wav") + #B------------------------------------------------------------------------- + + def B_RUN(self, event): + self.B_BRUN.Enable(False) + + UC_PATH = self.B_CachePath.GetPath() + MP3_PATH = self.B_ExportPath.GetPath() + if UC_PATH != '' and MP3_PATH != '': + transform = Netease_cloud_CaChe.Transform() + print(UC_PATH) + transform.do_transform(UC_PATH,MP3_PATH + '/') + + self.B_BRUN.Enable(True) + def Close(self, event): self.Destroy() diff --git a/M_SSC.py b/M_SSC.py index fc59b32..2c3eb09 100644 --- a/M_SSC.py +++ b/M_SSC.py @@ -2,12 +2,19 @@ # import ############################## import wx -import xlwt,xlrd +import xlwt +import xlrd import wx.lib.plot as plot -import win32api,win32con +import win32api +import win32con import os -import time,datetime -import ctypes +import time +import datetime +import socket +import shutil +from subprocess import Popen +import qrcode + from gsnodegraph import EVT_GSNODEGRAPH_ADDNODEBTN import nodes @@ -25,7 +32,7 @@ def __init__(self, parent): # 定义主函数 GUI_SSC.Main.__init__(self, parent) - global key_list,window_frame + global key_list, window_frame window_frame = self key_list = [] @@ -34,13 +41,13 @@ def __init__(self, parent): self.NoteBook.ChangeSelection(0) - for i in range(0,50): + for i in range(0, 50): i_a = 801 + i self.A_GRID.SetRowLabelValue(i, '0' + str(i_a)) self.A_Save_path.SetPath(get_desktop()) - self.A_Edit_State_Colour.SetBackgroundColour((192,192,192)) + self.A_Edit_State_Colour.SetBackgroundColour((192, 192, 192)) self.A_Edit_State_Text.SetLabel('静待') # Setup the node registry @@ -66,20 +73,20 @@ def __init__(self, parent): "FILTER": "#558333", # Green "BLEND": "#498DB8", # Light blue "COLOR": "#C2AF3A", # Yellow - "TRANSFORM": "#6B8B8B", # Blue-grey + "TRANSFORM": "#6B8B8B", # Blue-grey "OUTPUT": "#B33641" # Red } } # Init the nodegraph - ##print(self.NoteBook.GetPage(3)) - ng = NodeGraph(self.NoteBook.GetPage(3), registry=node_registry, config=config,size=(500,600)) + # print(self.NoteBook.GetPage(3)) + ng = NodeGraph(self.NoteBook.GetPage( + 3), registry=node_registry, config=config, size=(500, 600)) # Add nodes to the node graph ng.AddNode("excel_importid", pos=wx.Point(100, 10)) ng.AddNode("output_nodeid", pos=wx.Point(300, 10)) - + ng.Bind(EVT_GSNODEGRAPH_ADDNODEBTN, self.OnAddNodeMenuBtn) - def Hot_Key_Down(self, event): ''' @@ -114,14 +121,14 @@ def Hot_Key_Down(self, event): print(key_list) self.A_key_list.SetLabel(str(key_list)) else: - string = str(''.join(map(str,key_list))) + string = str(''.join(map(str, key_list))) self.A_NUM.SetLabel('学号:' + string) Y = self.A_Kind_choice.GetSelection() - for i in range(0,50): + for i in range(0, 50): if self.A_GRID.GetRowLabelValue(i) == string: self.A_GRID.SetCellValue(i, Y, '√') - self.A_GRID.MakeCellVisible(i,Y) + self.A_GRID.MakeCellVisible(i, Y) self.A_key_list.SetLabel('[]') key_list.clear() @@ -129,17 +136,17 @@ def Hot_Key_Down(self, event): # 检测未登记名单 self.A_Report.SetValue('没有任何数据的栏目:') i_weight = 0 - for i in range(0,50): - for i_2 in range(0,5): - if self.A_GRID.GetCellValue(i,i_2) != '': + for i in range(0, 50): + for i_2 in range(0, 5): + if self.A_GRID.GetCellValue(i, i_2) != '': i_weight = i_weight + 1 - + if i_weight == 0: - self.A_Report.AppendText(self.A_GRID.GetRowLabelValue(i) + ' / ') + self.A_Report.AppendText( + self.A_GRID.GetRowLabelValue(i) + ' / ') i_weight = 0 - def Replace(self, event): ''' 重置输入栏 @@ -155,112 +162,114 @@ def Export(self, event): workbook = xlwt.Workbook(encoding="utf-8") worksheet = workbook.add_sheet("Sheet1") - for i in range(0,50): - for i_2 in range(0,5): - worksheet.write(i,i_2 + 1, self.A_GRID.GetCellValue(i,i_2)) - print(i,i_2) + for i in range(0, 50): + for i_2 in range(0, 5): + worksheet.write(i, i_2 + 1, self.A_GRID.GetCellValue(i, i_2)) + print(i, i_2) if self.A_Class.GetSelection() == 0: - for i in range(0,50): - worksheet.write(i,0, '0' + str(101 + i)) + for i in range(0, 50): + worksheet.write(i, 0, '0' + str(101 + i)) elif self.A_Class.GetSelection() == 1: - for i in range(0,50): - worksheet.write(i,0, '0' + str(201 + i)) + for i in range(0, 50): + worksheet.write(i, 0, '0' + str(201 + i)) elif self.A_Class.GetSelection() == 2: - for i in range(0,50): - worksheet.write(i,0, '0' + str(301 + i)) + for i in range(0, 50): + worksheet.write(i, 0, '0' + str(301 + i)) elif self.A_Class.GetSelection() == 3: - for i in range(0,50): - worksheet.write(i,0, '0' + str(401 + i)) + for i in range(0, 50): + worksheet.write(i, 0, '0' + str(401 + i)) elif self.A_Class.GetSelection() == 4: - for i in range(0,50): - worksheet.write(i,0, '0' + str(501 + i)) + for i in range(0, 50): + worksheet.write(i, 0, '0' + str(501 + i)) elif self.A_Class.GetSelection() == 5: - for i in range(0,50): - worksheet.write(i,0, '0' + str(601 + i)) + for i in range(0, 50): + worksheet.write(i, 0, '0' + str(601 + i)) elif self.A_Class.GetSelection() == 6: - for i in range(0,50): - worksheet.write(i,0, '0' + str(701 + i)) + for i in range(0, 50): + worksheet.write(i, 0, '0' + str(701 + i)) elif self.A_Class.GetSelection() == 7: - for i in range(0,50): - worksheet.write(i,0, '0' + str(801 + i)) + for i in range(0, 50): + worksheet.write(i, 0, '0' + str(801 + i)) elif self.A_Class.GetSelection() == 8: - for i in range(0,50): - worksheet.write(i,0, '0' + str(901 + i)) + for i in range(0, 50): + worksheet.write(i, 0, '0' + str(901 + i)) if self.A_Save_path.GetPath()[-1] == '\\': - export_name = self.A_Save_path.GetPath() + 'Export_' + str(datetime.date.today()) + '_' + str(self.A_Class.GetSelection() + 1) + '.xls' + export_name = self.A_Save_path.GetPath() + 'Export_' + str(datetime.date.today()) + \ + '_' + str(self.A_Class.GetSelection() + 1) + '.xls' else: - export_name = self.A_Save_path.GetPath() + '\Export_' + str(datetime.date.today()) + '_' + str(self.A_Class.GetSelection() + 1) + '.xls' + export_name = self.A_Save_path.GetPath() + '\Export_' + str(datetime.date.today()) + \ + '_' + str(self.A_Class.GetSelection() + 1) + '.xls' workbook.save(export_name) - workbook.save('./DATA/SSC/' + 'Export_' + str(datetime.date.today()) + '_' + str(self.A_Class.GetSelection()) + '.xls') # 缓存 + workbook.save('./DATA/SSC/' + 'Export_' + str(datetime.date.today() + ) + '_' + str(self.A_Class.GetSelection()) + '.xls') # 缓存 print('save finish') if self.A_Auto_Focus.IsChecked() == True: - os.system('explorer.exe' + ' /select,' + export_name) # 打开资源管理器并选中导出文件 + os.system('explorer.exe' + ' /select,' + + export_name) # 打开资源管理器并选中导出文件 self.A_Export.Enable(True) - def Change_Class(self, event): ''' 更改班级时 ''' if self.A_Class.GetSelection() == 0: self.A_GRID.ClearGrid() - for i in range(0,50): + for i in range(0, 50): i_a = 101 + i self.A_GRID.SetRowLabelValue(i, '0' + str(i_a)) elif self.A_Class.GetSelection() == 1: self.A_GRID.ClearGrid() - for i in range(0,50): + for i in range(0, 50): i_a = 201 + i self.A_GRID.SetRowLabelValue(i, '0' + str(i_a)) elif self.A_Class.GetSelection() == 2: self.A_GRID.ClearGrid() - for i in range(0,50): + for i in range(0, 50): i_a = 301 + i self.A_GRID.SetRowLabelValue(i, '0' + str(i_a)) elif self.A_Class.GetSelection() == 3: self.A_GRID.ClearGrid() - for i in range(0,50): + for i in range(0, 50): i_a = 401 + i self.A_GRID.SetRowLabelValue(i, '0' + str(i_a)) elif self.A_Class.GetSelection() == 4: self.A_GRID.ClearGrid() - for i in range(0,50): + for i in range(0, 50): i_a = 501 + i self.A_GRID.SetRowLabelValue(i, '0' + str(i_a)) elif self.A_Class.GetSelection() == 5: self.A_GRID.ClearGrid() - for i in range(0,50): + for i in range(0, 50): i_a = 601 + i self.A_GRID.SetRowLabelValue(i, '0' + str(i_a)) elif self.A_Class.GetSelection() == 6: self.A_GRID.ClearGrid() - for i in range(0,50): + for i in range(0, 50): i_a = 701 + i self.A_GRID.SetRowLabelValue(i, '0' + str(i_a)) elif self.A_Class.GetSelection() == 7: self.A_GRID.ClearGrid() - for i in range(0,50): + for i in range(0, 50): i_a = 801 + i self.A_GRID.SetRowLabelValue(i, '0' + str(i_a)) elif self.A_Class.GetSelection() == 8: self.A_GRID.ClearGrid() - for i in range(0,50): + for i in range(0, 50): i_a = 901 + i self.A_GRID.SetRowLabelValue(i, '0' + str(i_a)) - def A_GRIDOnGridSelectCell(self, event): ''' 单元格被选中时 ''' - self.A_GRID.SetGridLineColour(wx.Colour(0,128,255)) - - self.A_Edit_State_Colour.SetBackgroundColour((0,128,255)) + self.A_GRID.SetGridLineColour(wx.Colour(0, 128, 255)) + + self.A_Edit_State_Colour.SetBackgroundColour((0, 128, 255)) self.A_Edit_State_Text.SetLabel('监听') def A_GRIDOnKillFocus(self, event): @@ -275,7 +284,7 @@ def A_GRIDOnKillFocus(self, event): else: self.A_GRID.SetGridLineColour('black') - self.A_Edit_State_Colour.SetBackgroundColour((192,192,192)) + self.A_Edit_State_Colour.SetBackgroundColour((192, 192, 192)) self.A_Edit_State_Text.SetLabel('静待') def A_GRIDOnGridEditorHidden(self, event): @@ -283,14 +292,14 @@ def A_GRIDOnGridEditorHidden(self, event): 退出编辑模式时 ''' if self.A_GRID.IsSelection() == True: - self.A_GRID.SetGridLineColour(wx.Colour(0,128,255)) - - self.A_Edit_State_Colour.SetBackgroundColour((0,128,255)) + self.A_GRID.SetGridLineColour(wx.Colour(0, 128, 255)) + + self.A_Edit_State_Colour.SetBackgroundColour((0, 128, 255)) self.A_Edit_State_Text.SetLabel('监听') else: self.A_GRID.SetGridLineColour('black') - self.A_Edit_State_Colour.SetBackgroundColour((192,192,192)) + self.A_Edit_State_Colour.SetBackgroundColour((192, 192, 192)) self.A_Edit_State_Text.SetLabel('静待') def A_GRIDOnGridEditorShown(self, event): @@ -303,12 +312,12 @@ def A_GRIDOnGridLabelLeftDClick(self, event): ''' 双击顶部标签栏->切换录入行 ''' - ##print(self.A_GRID.GetSelectedCols()) + # print(self.A_GRID.GetSelectedCols()) self.A_Kind_choice.SetSelection(self.A_GRID.GetSelectedCols()[0]) event.Skip() - #C------------------------------------------------------------------------- - def C_Check(self,event): + # C------------------------------------------------------------------------- + def C_Check(self, event): name = self.C_PathBox.GetString(self.C_PathBox.GetSelections()[0]) try: data = xlrd.open_workbook(name) @@ -319,8 +328,10 @@ def C_Check(self,event): table = data.sheets()[0] self.NoteBook.ChangeSelection(2) - self.C_Class.SetLabel('班级:' + str(table.col_values(0, start_rowx=0, end_rowx=None)[0][0:2])) - self.C_NUM.SetLabel('总人数:' + str(len(table.col_values(0, start_rowx=0, end_rowx=None)))) + self.C_Class.SetLabel( + '班级:' + str(table.col_values(0, start_rowx=0, end_rowx=None)[0][0:2])) + self.C_NUM.SetLabel( + '总人数:' + str(len(table.col_values(0, start_rowx=0, end_rowx=None)))) fileinfo = os.stat(name) self.C_ListBox.Clear() @@ -329,7 +340,8 @@ def C_Check(self,event): self.C_ListBox.Append("文件大小:" + str(fileinfo.st_size) + "字节") self.C_ListBox.Append("最后一次访问时间:" + str(formatTime(fileinfo.st_atime))) self.C_ListBox.Append("最后一次修改时间:" + str(formatTime(fileinfo.st_mtime))) - self.C_ListBox.Append("最后一次状态变化的时间:" + str(formatTime(fileinfo.st_ctime))) + self.C_ListBox.Append( + "最后一次状态变化的时间:" + str(formatTime(fileinfo.st_ctime))) self.C_ListBox.Append("保护模式:" + str(fileinfo.st_mode)) self.C_ListBox.Append("节点号:" + str(fileinfo.st_ino)) self.C_ListBox.Append("连接数:" + str(fileinfo.st_nlink)) @@ -338,13 +350,53 @@ def C_Check(self,event): def C_CheckDC(self, event): return super().C_CheckDC(event) - #D---------------------------------------------------------------------- + # D---------------------------------------------------------------------- def OnAddNodeMenuBtn(self, event): print("Open add node menu") - - #Main---------------------------------------------------------------------- - def NoteBookOnNotebookPageChanged(self,event): + + # E---------------------------------------------------------------------- + def E_Send(self, event): + # 获取本机计算机名称 + hostname = socket.gethostname() + # 获取本机ip + ip = socket.gethostbyname(hostname) + + print(ip) + + HOST = ip + PORT = 1919 + + FilePath = str(self.E_FilePath.GetLabel()) + #print(FilePath[FilePath.rfind('\\') +1:]) + + shutil.copyfile(FilePath,'./Cache/' + FilePath[FilePath.rfind('\\') +1:]) + + ##message = open(FilePath,encoding='utf-8').readlines() + ##print(message) + + Popen('python -m http.server ' + str(PORT) + ' --bind ' + str(HOST) + ' --directory ./Cache/', shell=True) + + ##handler = http.server.SimpleHTTPRequestHandler + ##httpd = socketserver.TCPServer((HOST, PORT), handler) + ##print ("HTTP server is at: http://%s:%d/" % (HOST, PORT)) + ##httpd.serve_forever() + + img = qrcode.make(str(HOST) + ':' + str(PORT) + '/' + FilePath[FilePath.rfind('\\') +1:]) + with open('./Cache/M_SSC_E_QRcode.png', 'wb') as f: + img.save(f) + + img = wx.Image('./Cache/M_SSC_E_QRcode.png').Scale(300, 300) #通过wx.Image 加载图片,并缩放图片到长宽为25,25的尺寸 + bitmap = wx.Bitmap(img,wx.BITMAP_SCREEN_DEPTH) #转换图片为位图 + self.E_QRcode.SetBitmap(bitmap) + + self.E_Tip.SetLabel('服务器启动成功!IP地址:' + str(ip)) + self.E_SendBottom.Enable(False) + + + # Main------------------------------------------------------------------- + + def NoteBookOnNotebookPageChanged(self, event): if self.NoteBook.GetSelection() == 3: print('初始化D') self.D_init() @@ -353,11 +405,11 @@ def MainOnSize(self, event): ''' 主界面->窗口大小调整 ''' - for i in range(0,self.A_GRID.GetNumberCols()): + for i in range(0, self.A_GRID.GetNumberCols()): size = self.GetSize()[0] / self.A_GRID.GetNumberCols() - 30 - self.A_GRID.SetColSize(i,int(size)) + self.A_GRID.SetColSize(i, int(size)) - ##self.A_GRID.SetSize(self.GetSize()[0],200) + # self.A_GRID.SetSize(self.GetSize()[0],200) event.Skip() def Resize(self): @@ -381,6 +433,7 @@ def Close(self, event): # File Class ########################################################################### + class FileDrop(wx.FileDropTarget): def __init__(self, window): @@ -389,7 +442,7 @@ def __init__(self, window): self.window = window def OnDropFiles(self, x, y, filenames): - + for name in filenames: print(name) @@ -397,31 +450,44 @@ def OnDropFiles(self, x, y, filenames): end = int(len(name)) file_type = str(name)[font: end] - if file_type == 'xls': - if window_frame.C_PathBox.FindString(name) == -1: # 防止重复导入 - window_frame.C_PathBox.Append(name) - window_frame.NoteBook.ChangeSelection(2) + if window_frame.NoteBook.GetSelection() == 4: + + window_frame.E_FilePath.SetLabel(name) + window_frame.E_SendBottom.Enable(True) else: - wx.CallAfter(wx.MessageBox, '文件类型:' + file_type + '[不支持]' + '\n' + '强行加载可能会导致未知错误!', caption='文件处理') + if file_type == 'xls': + if window_frame.C_PathBox.FindString(name) == -1: # 防止重复导入 + window_frame.C_PathBox.Append(name) + window_frame.NoteBook.ChangeSelection(2) + + else: + wx.CallAfter(wx.MessageBox, '文件类型:' + file_type + + '[不支持]' + '\n' + '强行加载可能会导致未知错误!', caption='文件处理') return True ############################## # 主函数 ############################## + + def main(): app = wx.App(False) frame = CalcFrame(None) frame.Show(True) app.MainLoop() + def get_desktop(): - key =win32api.RegOpenKey(win32con.HKEY_CURRENT_USER,r'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders',0,win32con.KEY_READ) - return win32api.RegQueryValueEx(key,'Desktop')[0] + key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, + r'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders', 0, win32con.KEY_READ) + return win32api.RegQueryValueEx(key, 'Desktop')[0] + def formatTime(atime): - return time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(atime)) + return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(atime)) + if __name__ == "__main__": main() diff --git a/Main.py b/Main.py index af62785..7ef5ae9 100644 --- a/Main.py +++ b/Main.py @@ -84,8 +84,7 @@ import threading # 多线程 import sys import os -import win32com.client -import win32api +import win32gui, win32com.client, win32api import psutil import time import PIL.Image @@ -96,7 +95,8 @@ import gc # 内存回收 import ctypes ##from ctypes import WinDLL # 运行Windows DLL -import imghdr +import imghdr # 检测图片类型 +import RBS_windows_api ########################################################################### # Class Main @@ -263,6 +263,12 @@ def __init__(self, parent): print('屏幕PPI值:' + str(wx.Display.GetPPI(wx.Display())) + '\n彩色模式:' + str(wx.ColourDisplay()) + '\nGUI大小:' + str( self.Size)) + + ##dialog_hwnd = win32gui.FindWindow(None,'RBS_Software') + ##password_hwnd = win32gui.GetDlgItem(dialog_hwnd, -31979) + + self.windowEffect = RBS_windows_api.WindowEffect() + ##self.windowEffect.setAeroEffect(int(self.GetHandle())) def Sacc(self, event): """ @@ -522,21 +528,8 @@ def CMD_INOnTextEnter(self,event): self.CMD(self.CMD_IN.GetValue()) self.CMD_IN.SetValue('') - def move_start(self, frame_pos): - ##print(frame_pos) - self.SetPosition(frame_pos) - def OnLeftDown(self, event): - thread = WorkerThread(self) - self.threads.append(thread) - thread.start() - - def OnLeftUp(self, event): - if self.threads: - self.threads[0].timeToQuit.set() - self.threads.remove(self.threads[0]) - - ##print('退出线程') + self.windowEffect.moveWindow(self.GetHandle()) def Change_Size(self, event): print(self.GetSize()) @@ -3212,6 +3205,7 @@ def OnDropFiles(self, x, y, filenames): ########################################################################### # 窗口拖动处理Class # Window Move Class +# warning:此类已弃用! ########################################################################### class WorkerThread(threading.Thread): def __init__(self, frame): @@ -3267,6 +3261,12 @@ def __init__(self,parent): self.Append(cmi) self.Bind(wx.EVT_MENU, self.Refresh, cmi) + self.window = self.GetInvokingWindow() + print(self.window) + self.windowEffect = RBS_windows_api.WindowEffect() + #self.windowEffect.setAeroEffect(int(self.window.GetHandle())) + + def OnMinimize(self,event): self.parent.Ico() def OnClose(self,event): diff --git a/Netease_cloud_CaChe.py b/Netease_cloud_CaChe.py new file mode 100644 index 0000000..3fb5f96 --- /dev/null +++ b/Netease_cloud_CaChe.py @@ -0,0 +1,72 @@ +# -*- coding:utf-8 -*- +# 网易云音乐缓存转MP3算法 + +import os +import re +import requests + +UC_PATH = 'D:\网易云音乐\缓存\Cache/' # 缓存路径 例 D:/CloudMusic/Cache/ +MP3_PATH = './' # 存放歌曲路径 + +class Transform(): + def do_transform(self,UC_PATH,MP3_PATH): + files = os.listdir(UC_PATH + '/') + for file in files: + if file[-2:] == 'uc': # 后缀uc结尾为歌曲缓存 + print(file) + uc_file = open(UC_PATH + '/' + file, mode='rb') + uc_content = uc_file.read() + mp3_content = bytearray() + for byte in uc_content: + byte ^= 0xa3 + mp3_content.append(byte) + song_id = self.get_songid_by_filename(file) + song_name, singer_name = self.get_song_info(song_id) + mp3_file_name = MP3_PATH + '%s - %s.mp3' % (singer_name, song_name) + mp3_file = open(mp3_file_name, 'wb') + mp3_file.write(mp3_content) + uc_file.close() + mp3_file.close() + print('success %s' % mp3_file_name) + + def get_songid_by_filename(self, file_name): + match_inst = re.match('\d*', file_name) # -前面的数字是歌曲ID,例:1347203552-320-0aa1 + if match_inst: + return match_inst.group() + return '' + + def get_song_info(self, song_id): + if not song_id: + return str(song_id), '' + + try: + url = 'https://api.imjad.cn/cloudmusic/' # 请求url例子:https://api.imjad.cn/cloudmusic/?type=detail&id=1347203552 + payload = {'type': 'detail', 'id': song_id} + reqs = requests.get(url, params=payload) + jsons = reqs.json() + song_name = jsons['songs'][0]['name'] + singer = jsons['songs'][0]['ar'][0]['name'] + return song_name, singer + except: + return str(song_id), 'UnName' + +def check_path(UC_PATH,MP3_PATH): + if not os.path.exists(UC_PATH): + print('缓存路径错误: %s' % UC_PATH) + return False + if not os.path.exists(MP3_PATH): + print('目标路径错误: %s' % MP3_PATH) + return False + + if UC_PATH[-1] != '/': # 容错处理 防止绝对路径结尾不是/ + UC_PATH += '/' + if MP3_PATH[-1] != '/': + MP3_PATH += '/' + return UC_PATH,MP3_PATH + +if __name__ == '__main__': + if not check_path(): + exit() + + transform = Transform() + transform.do_transform(UC_PATH,MP3_PATH) \ No newline at end of file diff --git a/RBS_PLC.py b/RBS_PLC.py deleted file mode 100644 index 61bde19..0000000 --- a/RBS_PLC.py +++ /dev/null @@ -1,81 +0,0 @@ -import win32api,win32con -import time -import os -import shutil - -from time import sleep -from shutil import copytree, move -from psutil import disk_partitions - -def get_desktop_dir(format:None) -> str: - """ - 获取桌面路径 - """ - key =win32api.RegOpenKey(win32con.HKEY_CURRENT_USER,r'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders',0,win32con.KEY_READ) - return win32api.RegQueryValueEx(key,'Desktop')[0] - -def make_folder(): - Dpath = get_desktop_dir() - - local_time = time.strftime("%Y-%m-%d", time.localtime()) - print(local_time) - - for i in ['语文','数学','英语','物理','生物','地理','政治','数据缓存','其他']: - if not os.path.exists(Dpath + '/' + i): - os.makedirs(Dpath + '/' + i) - print('文件夹已创建:' + Dpath + '/' + i) - else: - print('文件夹已存在:' + Dpath + '/' + i) - - for i in ['语文','数学','英语','物理','生物','地理','政治','数据缓存','其他']: - if not os.path.exists(Dpath + '/' + i + '/' + local_time): - os.makedirs(Dpath + '/' + i + '/' + local_time) - print('副文件夹已创建:' + Dpath + '/' + i + '/' + local_time) - else: - print('副文件夹已存在:' + Dpath + '/' + i + '/' + local_time) - -def Cache_file(): - path_xml = get_desktop_dir() - filelist = os.listdir(path_xml) - path1 = get_desktop_dir() - path2 = get_desktop_dir() + '/数据缓存/' - - for type in ['.xls','.xlsx','.docx','.pptx']: - for files in filelist: - filename1 = os.path.splitext(files)[1] # 读取文件后缀名 - filename0 = os.path.splitext(files)[0] #读取文件名 - print(filename1) - m = filename1 == type - print(m) - if m : - full_path = os.path.join(path1, files) - despath = path2 + filename0+type #.jpg为你的文件类型,即后缀名,读者自行修改 - shutil.move(full_path, despath) - else : - continue - -def move_U_to_desk(): - while True: - # 设置休眠时间 - sleep(5) - # 检测所有的驱动器,进行遍历寻找哦 - for item in disk_partitions(): - if 'removable' in item.opts: - driver, opts = item.device, item.opts - # 输出可移动驱动器符号 - print('发现usb驱动:', driver) - # 复制移动驱动器的根目录 - copytree(driver, r'D:\usb') - print('正在复制所有U盘文件到本地...') - - if opts == 'rw, remoevable': - print('复制完成') - break - # 没有找到可输出驱动器 - else: - driver, opts = item.device, item.opts - print('不可用的驱动器:' + driver) - print('---------') - -if __name__ == "__main__": - print('RBS_PLC // Version = 0.0.1') \ No newline at end of file diff --git a/RBS_windows_api.py b/RBS_windows_api.py new file mode 100644 index 0000000..0b09dfd --- /dev/null +++ b/RBS_windows_api.py @@ -0,0 +1,212 @@ +# coding:utf-8 +#作者:之一Yo +#出处:https://www.cnblogs.com/zhiyiYo/p/14643698.html +#版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。 + + +from ctypes import POINTER, c_bool, sizeof, windll,pointer,c_int,byref,WinDLL +from ctypes.wintypes import DWORD, HWND, ULONG, LONG, LPCVOID + +from win32 import win32api, win32gui +from win32.lib import win32con + +from ctypes import POINTER, Structure +from enum import Enum + +#———————————————————————————————————————————————————————————————————————————————————————— + +class DWMNCRENDERINGPOLICY(Enum): + DWMNCRP_USEWINDOWSTYLE = 0 + DWMNCRP_DISABLED = 1 + DWMNCRP_ENABLED = 2 + DWMNCRP_LAS = 3 + + +class DWMWINDOWATTRIBUTE(Enum): + DWMWA_NCRENDERING_ENABLED = 1 + DWMWA_NCRENDERING_POLICY = 2 + DWMWA_TRANSITIONS_FORCEDISABLED = 3 + DWMWA_ALLOW_NCPAINT = 4 + DWMWA_CAPTION_BUTTON_BOUNDS = 5 + DWMWA_NONCLIENT_RTL_LAYOUT = 6 + DWMWA_FORCE_ICONIC_REPRESENTATION = 7 + DWMWA_FLIP3D_POLICY = 8 + DWMWA_EXTENDED_FRAME_BOUNDS = 9 + DWMWA_HAS_ICONIC_BITMAP = 10 + DWMWA_DISALLOW_PEEK = 11 + DWMWA_EXCLUDED_FROM_PEEK = 12 + DWMWA_CLOAK = 13 + DWMWA_CLOAKED = 14 + DWMWA_FREEZE_REPRESENTATION = 25 + DWMWA_LAST = 16 + + +class MARGINS(Structure): + _fields_ = [ + ("cxLeftWidth", c_int), + ("cxRightWidth", c_int), + ("cyTopHeight", c_int), + ("cyBottomHeight", c_int), + ] +#———————————————————————————————————————————————————————————————————————————————————————— + +class WINDOWCOMPOSITIONATTRIB(Enum): + WCA_UNDEFINED = 0, + WCA_NCRENDERING_ENABLED = 1, + WCA_NCRENDERING_POLICY = 2, + WCA_TRANSITIONS_FORCEDISABLED = 3, + WCA_ALLOW_NCPAINT = 4, + WCA_CAPTION_BUTTON_BOUNDS = 5, + WCA_NONCLIENT_RTL_LAYOUT = 6, + WCA_FORCE_ICONIC_REPRESENTATION = 7, + WCA_EXTENDED_FRAME_BOUNDS = 8, + WCA_HAS_ICONIC_BITMAP = 9, + WCA_THEME_ATTRIBUTES = 10, + WCA_NCRENDERING_EXILED = 11, + WCA_NCADORNMENTINFO = 12, + WCA_EXCLUDED_FROM_LIVEPREVIEW = 13, + WCA_VIDEO_OVERLAY_ACTIVE = 14, + WCA_FORCE_ACTIVEWINDOW_APPEARANCE = 15, + WCA_DISALLOW_PEEK = 16, + WCA_CLOAK = 17, + WCA_CLOAKED = 18, + WCA_ACCENT_POLICY = 19, + WCA_FREEZE_REPRESENTATION = 20, + WCA_EVER_UNCLOAKED = 21, + WCA_VISUAL_OWNER = 22, + WCA_LAST = 23 + + +class ACCENT_STATE(Enum): + """ 客户区状态枚举类 """ + ACCENT_DISABLED = 0, + ACCENT_ENABLE_GRADIENT = 1, + ACCENT_ENABLE_TRANSPARENTGRADIENT = 2, + ACCENT_ENABLE_BLURBEHIND = 3, # Aero效果 + ACCENT_ENABLE_ACRYLICBLURBEHIND = 4, # 亚克力效果 + ACCENT_INVALID_STATE = 5 + + +class ACCENT_POLICY(Structure): + """ 设置客户区的具体属性 """ + _fields_ = [ + ('AccentState', DWORD), + ('AccentFlags', DWORD), + ('GradientColor', DWORD), + ('AnimationId', DWORD), + ] + + +class WINDOWCOMPOSITIONATTRIBDATA(Structure): + _fields_ = [ + ('Attribute', DWORD), + ('Data', POINTER(ACCENT_POLICY)), # POINTER()接收任何ctypes类型,并返回一个指针类型 + ('SizeOfData', ULONG), + ] + + +#———————————————————————————————————————————————————————————————————————————————————————— +class Windows_shadow(): + + def __init__(self): + self.dwmapi = WinDLL("dwmapi") + self.DwmExtendFrameIntoClientArea = self.dwmapi.DwmExtendFrameIntoClientArea + self.DwmSetWindowAttribute = self.dwmapi.DwmSetWindowAttribute + self.DwmExtendFrameIntoClientArea.restype = LONG + self.DwmSetWindowAttribute.restype = LONG + self.DwmSetWindowAttribute.argtypes = [c_int, DWORD, LPCVOID, DWORD] + self.DwmExtendFrameIntoClientArea.argtypes = [c_int, POINTER(MARGINS)] + + def addShadowEffect(self, hWnd): + """ 给窗口添加阴影 + + Parameter + ---------- + hWnd: int or `sip.voidptr` + 窗口句柄 + """ + hWnd = int(hWnd) + self.DwmSetWindowAttribute( + hWnd, + DWMWINDOWATTRIBUTE.DWMWA_NCRENDERING_POLICY.value, + byref(c_int(DWMNCRENDERINGPOLICY.DWMNCRP_ENABLED.value)), + 4, + ) + margins = MARGINS(-1, -1, -1, -1) + self.DwmExtendFrameIntoClientArea(hWnd, byref(margins)) + + +class WindowEffect(): + """ 调用windows api实现窗口效果 """ + + def __init__(self): + # 调用api + self.SetWindowCompositionAttribute = windll.user32.SetWindowCompositionAttribute + self.SetWindowCompositionAttribute.restype = c_bool + self.SetWindowCompositionAttribute.argtypes = [ + c_int, POINTER(WINDOWCOMPOSITIONATTRIBDATA)] + # 初始化结构体 + self.accentPolicy = ACCENT_POLICY() + self.winCompAttrData = WINDOWCOMPOSITIONATTRIBDATA() + self.winCompAttrData.Attribute = WINDOWCOMPOSITIONATTRIB.WCA_ACCENT_POLICY.value[0] + self.winCompAttrData.SizeOfData = sizeof(self.accentPolicy) + self.winCompAttrData.Data = pointer(self.accentPolicy) + + def setAcrylicEffect(self, hWnd: int, gradientColor: str = 'F2F2F230', + isEnableShadow: bool = True, animationId: int = 0): + """ 开启亚克力效果 + + Parameters + ---------- + hWnd: int + 窗口句柄 + + gradientColor: str + 十六进制亚克力混合色,对应 RGBA 四个分量 + + isEnableShadow: bool + 是否启用窗口阴影 + + animationId: int + 控制磨砂动画 + """ + # 亚克力混合色 + gradientColor = gradientColor[6:] + gradientColor[4:6] + \ + gradientColor[2:4] + gradientColor[:2] + gradientColor = DWORD(int(gradientColor, base=16)) + # 磨砂动画 + animationId = DWORD(animationId) + # 窗口阴影 + accentFlags = DWORD(0x20 | 0x40 | 0x80 | + 0x100) if isEnableShadow else DWORD(0) + self.accentPolicy.AccentState = ACCENT_STATE.ACCENT_ENABLE_ACRYLICBLURBEHIND.value[0] + self.accentPolicy.GradientColor = gradientColor + self.accentPolicy.AccentFlags = accentFlags + self.accentPolicy.AnimationId = animationId + # 开启亚克力 + self.SetWindowCompositionAttribute(hWnd, pointer(self.winCompAttrData)) + + def setAeroEffect(self, hWnd: int): + """ 开启 Aero 效果 + + Parameter + ---------- + hWnd: int + 窗口句柄 + """ + self.accentPolicy.AccentState = ACCENT_STATE.ACCENT_ENABLE_BLURBEHIND.value[0] + # 开启Aero + self.SetWindowCompositionAttribute(hWnd, pointer(self.winCompAttrData)) + + def moveWindow(self, hWnd: int): + """ 移动窗口 + + Parameter + ---------- + hWnd: int or `sip.voidptr` + 窗口句柄 + """ + win32gui.ReleaseCapture() + win32api.SendMessage(hWnd, win32con.WM_SYSCOMMAND, + win32con.SC_MOVE + win32con.HTCAPTION, 0) + diff --git a/T_Test3.py b/T_Test3.py new file mode 100644 index 0000000..352119b --- /dev/null +++ b/T_Test3.py @@ -0,0 +1,144 @@ +# coding:utf-8 + +from ctypes import POINTER, c_bool, sizeof, windll,pointer,c_int +from ctypes.wintypes import DWORD, HWND, ULONG + +from win32 import win32api, win32gui +from win32.lib import win32con + +from ctypes import POINTER, Structure +from ctypes.wintypes import DWORD, HWND, ULONG +from enum import Enum + + +class WINDOWCOMPOSITIONATTRIB(Enum): + WCA_UNDEFINED = 0, + WCA_NCRENDERING_ENABLED = 1, + WCA_NCRENDERING_POLICY = 2, + WCA_TRANSITIONS_FORCEDISABLED = 3, + WCA_ALLOW_NCPAINT = 4, + WCA_CAPTION_BUTTON_BOUNDS = 5, + WCA_NONCLIENT_RTL_LAYOUT = 6, + WCA_FORCE_ICONIC_REPRESENTATION = 7, + WCA_EXTENDED_FRAME_BOUNDS = 8, + WCA_HAS_ICONIC_BITMAP = 9, + WCA_THEME_ATTRIBUTES = 10, + WCA_NCRENDERING_EXILED = 11, + WCA_NCADORNMENTINFO = 12, + WCA_EXCLUDED_FROM_LIVEPREVIEW = 13, + WCA_VIDEO_OVERLAY_ACTIVE = 14, + WCA_FORCE_ACTIVEWINDOW_APPEARANCE = 15, + WCA_DISALLOW_PEEK = 16, + WCA_CLOAK = 17, + WCA_CLOAKED = 18, + WCA_ACCENT_POLICY = 19, + WCA_FREEZE_REPRESENTATION = 20, + WCA_EVER_UNCLOAKED = 21, + WCA_VISUAL_OWNER = 22, + WCA_LAST = 23 + + +class ACCENT_STATE(Enum): + """ 客户区状态枚举类 """ + ACCENT_DISABLED = 0, + ACCENT_ENABLE_GRADIENT = 1, + ACCENT_ENABLE_TRANSPARENTGRADIENT = 2, + ACCENT_ENABLE_BLURBEHIND = 3, # Aero效果 + ACCENT_ENABLE_ACRYLICBLURBEHIND = 4, # 亚克力效果 + ACCENT_INVALID_STATE = 5 + + +class ACCENT_POLICY(Structure): + """ 设置客户区的具体属性 """ + _fields_ = [ + ('AccentState', DWORD), + ('AccentFlags', DWORD), + ('GradientColor', DWORD), + ('AnimationId', DWORD), + ] + + +class WINDOWCOMPOSITIONATTRIBDATA(Structure): + _fields_ = [ + ('Attribute', DWORD), + ('Data', POINTER(ACCENT_POLICY)), # POINTER()接收任何ctypes类型,并返回一个指针类型 + ('SizeOfData', ULONG), + ] + + +#———————————————————————————————————————————————————————————————————————————————————————— + +class WindowEffect(): + """ 调用windows api实现窗口效果 """ + + def __init__(self): + # 调用api + self.SetWindowCompositionAttribute = windll.user32.SetWindowCompositionAttribute + self.SetWindowCompositionAttribute.restype = c_bool + self.SetWindowCompositionAttribute.argtypes = [ + c_int, POINTER(WINDOWCOMPOSITIONATTRIBDATA)] + # 初始化结构体 + self.accentPolicy = ACCENT_POLICY() + self.winCompAttrData = WINDOWCOMPOSITIONATTRIBDATA() + self.winCompAttrData.Attribute = WINDOWCOMPOSITIONATTRIB.WCA_ACCENT_POLICY.value[0] + self.winCompAttrData.SizeOfData = sizeof(self.accentPolicy) + self.winCompAttrData.Data = pointer(self.accentPolicy) + + def setAcrylicEffect(self, hWnd: int, gradientColor: str = 'F2F2F230', + isEnableShadow: bool = True, animationId: int = 0): + """ 开启亚克力效果 + + Parameters + ---------- + hWnd: int + 窗口句柄 + + gradientColor: str + 十六进制亚克力混合色,对应 RGBA 四个分量 + + isEnableShadow: bool + 是否启用窗口阴影 + + animationId: int + 控制磨砂动画 + """ + # 亚克力混合色 + gradientColor = gradientColor[6:] + gradientColor[4:6] + \ + gradientColor[2:4] + gradientColor[:2] + gradientColor = DWORD(int(gradientColor, base=16)) + # 磨砂动画 + animationId = DWORD(animationId) + # 窗口阴影 + accentFlags = DWORD(0x20 | 0x40 | 0x80 | + 0x100) if isEnableShadow else DWORD(0) + self.accentPolicy.AccentState = ACCENT_STATE.ACCENT_ENABLE_ACRYLICBLURBEHIND.value[0] + self.accentPolicy.GradientColor = gradientColor + self.accentPolicy.AccentFlags = accentFlags + self.accentPolicy.AnimationId = animationId + # 开启亚克力 + self.SetWindowCompositionAttribute(hWnd, pointer(self.winCompAttrData)) + + def setAeroEffect(self, hWnd: int): + """ 开启 Aero 效果 + + Parameter + ---------- + hWnd: int + 窗口句柄 + """ + self.accentPolicy.AccentState = ACCENT_STATE.ACCENT_ENABLE_BLURBEHIND.value[0] + # 开启Aero + self.SetWindowCompositionAttribute(hWnd, pointer(self.winCompAttrData)) + + def moveWindow(self, hWnd: int): + """ 移动窗口 + + Parameter + ---------- + hWnd: int or `sip.voidptr` + 窗口句柄 + """ + win32gui.ReleaseCapture() + win32api.SendMessage(hWnd, win32con.WM_SYSCOMMAND, + win32con.SC_MOVE + win32con.HTCAPTION, 0) + diff --git a/T_Test4.py b/T_Test4.py new file mode 100644 index 0000000..f635ab2 --- /dev/null +++ b/T_Test4.py @@ -0,0 +1,127 @@ +# -*- coding: utf-8 -*- +""" +Created on Thu Dec 27 19:22:11 2018 +#QQ群:476842922(欢迎加群讨论学习 +@author: Administrator +""" +import wx + +class AppFrame( wx.Frame ) : + + def __init__( self ) : + + wx.Frame.__init__( self, None, title="Am I transparent?", + style=wx.DEFAULT_FRAME_STYLE | wx.STAY_ON_TOP ) + self.SetClientSize( (300, 300) ) + + self.alphaValue = 255 + self.alphaIncrement = -4 + + pnl = wx.Panel( self ) + self.stTxt = wx.StaticText( pnl, -1, str( self.alphaValue ), (25, 25) ) + self.stTxt.SetFont( wx.Font( 18, wx.SWISS, wx.NORMAL, wx.NORMAL ) ) + + self.changeAlpha_timer = wx.Timer( self ) + self.changeAlpha_timer.Start( 50 ) # 20 changes per second + self.Bind( wx.EVT_TIMER, self.ChangeAlpha ) + + self.Bind( wx.EVT_CLOSE, self.OnCloseWindow ) + + #end AppFrame class + + #-------------------------------------------------------- + + def ChangeAlpha( self, evt ) : + """ The term "alpha" means variable transparency + as opposed to a "mask" which is binary transparency. + alpha == 255 : fully opaque + alpha == 0 : fully transparent (mouse is ineffective!) + + Only top-level controls can be transparent; no other controls can. + This is because they are implemented by the OS, not wx. + """ + + self.alphaValue += self.alphaIncrement + if (self.alphaValue) <= 0 or (self.alphaValue >= 255) : + + # Reverse the increment direction. + self.alphaIncrement = -self.alphaIncrement + + if self.alphaValue <= 0 : + self.alphaValue = 0 + + if self.alphaValue > 255 : + self.alphaValue = 255 + #end if + + self.stTxt.SetLabel( str( self.alphaValue ) ) + + # Note that we no longer need to use ctypes or win32api to + # make transparent windows, however I'm not removing the + # MakeTransparent code from this sample as it may be helpful + # to someone for other uses, someday. + + #self.MakeTransparent( self.alphaValue ) + + # Instead, just call the SetTransparent() method + self.SetTransparent( self.alphaValue ) # Easy ! + + #end ChangeAlpha def + + #-------------------------------------------------------- + + def OnCloseWindow( self, evt ) : + + self.changeAlpha_timer.Stop() + del self.changeAlpha_timer # avoid a memory leak + self.Destroy() + + #----------------------------------------------------- + + def MakeTransparent( self, amount ) : + """ + This is how the method SetTransparent() is implemented + on all MS Windows platforms. + """ + import os + if os.name == 'nt' : # could substitute: sys.platform == 'win32' + + hwnd = self.GetHandle() + try : + import ctypes # DLL library interface constants' definitions + _winlib = ctypes.windll.user32 # create object to access DLL file user32.dll + style = _winlib.GetWindowLongA( hwnd, 0xffffffec ) + style |= 0x00080000 + _winlib.SetWindowLongA( hwnd, 0xffffffec, style ) + _winlib.SetLayeredWindowAttributes( hwnd, 0, amount, 2 ) + + except ImportError : + + import win32api, win32con, winxpgui + _winlib = win32api.LoadLibrary( "user32" ) + pSetLayeredWindowAttributes = win32api.GetProcAddress( + _winlib, "SetLayeredWindowAttributes" ) + if pSetLayeredWindowAttributes == None : + return + exstyle = win32api.GetWindowLong( hwnd, win32con.GWL_EXSTYLE ) + if 0 == ( exstyle & 0x80000 ) : + win32api.SetWindowLong( hwnd, + win32con.GWL_EXSTYLE, + exstyle | 0x80000 ) + winxpgui.SetLayeredWindowAttributes( hwnd, 0, amount, 2 ) + else : + print('#### OS Platform must be MS Windows') + self.Destroy() + #end if + #end MakeTransparent def + +#end AppFrame class + +#======================================================= + +if __name__ == '__main__' : + + app = wx.App( False ) + frm = AppFrame() + frm.Show() + app.MainLoop()