diff --git a/Modules/WcModule.py b/Modules/WcModule.py index 47fd132..0a97d17 100644 --- a/Modules/WcModule.py +++ b/Modules/WcModule.py @@ -10,10 +10,11 @@ font = None # "AdobeHeitiStd-Regular.otf" file = None # "../resources/111.txt" mask = None # "../resources/mask.png" stopwords = None # {'王勃', '一'} +codec = None -def generate(size, maxword, font, file, mask, stopwords): - raw_data = open(file, encoding="utf-8").read() +def generate(size, maxword, font, file, mask, stopwords, codec): + raw_data = open(file, encoding=f"{codec}").read() ls = jieba.lcut(raw_data) for word in ls: if len(word) == 1: diff --git a/Wordcloud_GUI/main.py b/Wordcloud_GUI/main.py index 7f5d3ea..c1d49de 100644 --- a/Wordcloud_GUI/main.py +++ b/Wordcloud_GUI/main.py @@ -4,12 +4,13 @@ import tkinter as tk from tkinter import filedialog import WcModule import sys +import chardet root = tk.Tk() root.withdraw() WcModule.size = 210 WcModule.maxword = 75 -WcModule.font = "AdobeHeitiStd-Regular.otf" +WcModule.font = "msyh.ttc" WcModule.file = "../resources/111.txt" WcModule.mask = "../resources/mask.png" WcModule.stopwords = {'王勃', '一'} @@ -24,7 +25,7 @@ class mainthread: self.mainWindow.StopWordEdit.setEchoMode(QLineEdit.Normal) self.mainWindow.StopWordEdit.textChanged.connect(self.textChanged) self.mainWindow.StopWordApplyButton.clicked.connect(self.Confirm_input) - self.mainWindow.FontSelectBox.addItems(['Adobe 黑体 Std R', '华文行楷 R', '楷体 R', '微软雅黑 R', '宋体 R', '幼圆 R']) + self.mainWindow.FontSelectBox.addItems(['微软雅黑 R', '华文行楷 R', '楷体 R', 'Adobe 黑体 Std R', '宋体 R', '幼圆 R']) self.mainWindow.FontSelectBox.currentIndexChanged.connect(self.selectionChange) self.mainWindow.FontSizeSelectBox.valueChanged.connect(self.valueChange1) self.mainWindow.MaxWordCountBox.valueChanged.connect(self.valueChange2) @@ -34,23 +35,57 @@ class mainthread: def Choose_File(self): file_path = filedialog.askopenfilename() WcModule.file = file_path - self.mainWindow.FilePathPreview.setText(file_path) cursor = self.mainWindow.LogBrowser.textCursor() - cursor.movePosition(QtGui.QTextCursor.End) - cursor.insertText(f"[Sys]:File path selected:{file_path}\n") - self.mainWindow.LogBrowser.setTextCursor(cursor) - self.mainWindow.LogBrowser.ensureCursorVisible() + if file_path == "": + self.mainWindow.FilePathPreview.setText(file_path) + cursor.movePosition(QtGui.QTextCursor.End) + cursor.insertText(f"[Sys]:File path unselected\n") + self.mainWindow.LogBrowser.setTextCursor(cursor) + self.mainWindow.LogBrowser.ensureCursorVisible() + else: + self.mainWindow.FilePathPreview.setText(file_path) + data = open(file=file_path, mode='rb') + result = chardet.detect(data.read()) + result = result["encoding"] + cursor.movePosition(QtGui.QTextCursor.End) + cursor.insertText(f"[Sys]:File path selected:{file_path}\n") + self.mainWindow.LogBrowser.setTextCursor(cursor) + self.mainWindow.LogBrowser.ensureCursorVisible() + if "GB" in result: + WcModule.codec = "gbk" + cursor.movePosition(QtGui.QTextCursor.End) + cursor.insertText(f"[Sys]:File codec detected: GB2312(GBK)\n") + self.mainWindow.LogBrowser.setTextCursor(cursor) + self.mainWindow.LogBrowser.ensureCursorVisible() + elif "utf" in result: + WcModule.codec = "utf-8" + cursor.movePosition(QtGui.QTextCursor.End) + cursor.insertText(f"[Sys]:File codec detected: UTF-8\n") + self.mainWindow.LogBrowser.setTextCursor(cursor) + self.mainWindow.LogBrowser.ensureCursorVisible() + else: + cursor.movePosition(QtGui.QTextCursor.End) + cursor.insertText(f"[Sys]:File codec detection Failed\n") + self.mainWindow.LogBrowser.setTextCursor(cursor) + self.mainWindow.LogBrowser.ensureCursorVisible() # 蒙版选择 def Choose_Mask(self): mask_path = filedialog.askopenfilename() WcModule.mask = mask_path cursor = self.mainWindow.LogBrowser.textCursor() - self.mainWindow.MaskPathPreview.setText(mask_path) - cursor.movePosition(QtGui.QTextCursor.End) - cursor.insertText(f"[Sys]:Mask path selected:{mask_path}\n") - self.mainWindow.LogBrowser.setTextCursor(cursor) - self.mainWindow.LogBrowser.ensureCursorVisible() + if mask_path == "": + self.mainWindow.FilePathPreview.setText(mask_path) + cursor.movePosition(QtGui.QTextCursor.End) + cursor.insertText(f"[Sys]:Mask path unselected\n") + self.mainWindow.LogBrowser.setTextCursor(cursor) + self.mainWindow.LogBrowser.ensureCursorVisible() + else: + self.mainWindow.MaskPathPreview.setText(mask_path) + cursor.movePosition(QtGui.QTextCursor.End) + cursor.insertText(f"[Sys]:Mask path selected:{mask_path}\n") + self.mainWindow.LogBrowser.setTextCursor(cursor) + self.mainWindow.LogBrowser.ensureCursorVisible() def valueChange1(self): font_size = 10 * self.mainWindow.FontSizeSelectBox.value() @@ -70,6 +105,7 @@ class mainthread: @staticmethod def textChanged(text): global input_words + input_words = None input_words = text @staticmethod @@ -83,10 +119,10 @@ class mainthread: cursor.insertText(f"[Sys]:Generating.....\n") self.mainWindow.LogBrowser.setTextCursor(cursor) self.mainWindow.LogBrowser.ensureCursorVisible() - WcModule.generate(WcModule.size, WcModule.maxword, WcModule.font, WcModule.file, WcModule.mask, WcModule.stopwords) + WcModule.generate(WcModule.size, WcModule.maxword, WcModule.font, WcModule.file, WcModule.mask, WcModule.stopwords, WcModule.codec) -fontlist = ("AdobeHeitiStd-Regular.otf", "STXINGKA.TTF", "simkai.ttf", "msyh.ttc", "simsun.ttc", "SIMYOU.TTF") +fontlist = ("msyh.ttc", "STXINGKA.TTF", "simkai.ttf", "AdobeHeitiStd-Regular.otf", "simsun.ttc", "SIMYOU.TTF") if __name__ == '__main__': app = QApplication(sys.argv) diff --git a/resources/111g.txt b/resources/111g.txt new file mode 100644 index 0000000..b8483ce --- /dev/null +++ b/resources/111g.txt @@ -0,0 +1,76 @@ +55_1 پ҂S پ҂Sܡֽa磬Ʉe֧lΣģ򹫻xv壬¹ڔ_ס̫ԭ޽̡Yt[r͵]皧˶졣˼Ԗ|ʩľ_˺Һ֡δyጢlo£˼ƝwrҲMɡλmԄtƣLԻԻˣǿYyԊ߲ݡOʌO\ҌNСӣőMܡ˾WЗl܇H˼£˽Kǰҡ൴WNΣ^NԻˡհ_ʮ𡣷Mѣɽֹع£ˮB•໡f£nᡣҲBqϡwۣMҸڡΣλΣ텢¡挍ˬؓxo˼ +55_2 ȸ퍵ַ ^·vp_ַdѾɣAHϪYeнģĺѡ +55_3 瘷[@x퍵ý YM޴ѡ÷Ӣ@~ˮŪ녞뺡տգϲƽӡ +55_4 ɽͤҹ ĽeɽͤҹɭҰCŽro͡ɫɷ̶Ӱdδ@ֶճ +55_5 ԁL CC塣򌟟Fɽ麡ȥ̟oEϢ顣ɽˮo• +55_6 Q揽޸ɼҡȪҺrе⡣ϣmWȻ܇[OhPƣϼ孽ܳdo㰐̓˽A +55_7 [ WϿͣEڷȡhgȻ`⠖ϼףȻb녱늲⣬;[BBǽ⭂Rךw[y١룬طzd׷lήጉm +55_8 s ǭŮLľüʼs_޹R퍣yм_]വÄٳ녡 +55_9 ҹL ҹLδ룬¶⣬ӳǾ_wbboţLܹ裬mί|rշQhҷijLȣҹvѡw_Pˣ_px{y˼Ԃ˼ԂflQPŔ࣬T·Lһͽ㡣 +55_10 ɏɏw ɏwGˮܽ¡LDwmL֣_ȹpu~Z̶Oƽ֎Խ˼ࡣ˼࣬ڲvqδ߀ϒɏĺĺɏDZرM潼ҡٵϰɣ~罭ϒɏɏɏ~γB~䱾üta˲Ɲexrz٣źBzo̎A̡ϧ⣬߀߱tɏйɏҹδЪʎLֵؽ¡ɏҹ꣬ǼԽŮηסǧY⣬Pɽ·ء +55_11 R_ R__f^܎_δͣ[PҰLϲݡбȪ·nnï䡣_ͬlњd[[wǼҫ起\ᭇ|L^ָδmӳգGuLͤ_У׵ǧ݆wٴB鿌𡣏ǴУCĴ_ɡ\ҹţ_ᡕδաڴ䣬yRQt٣üTmgM·ĺgɫءxσɃwP˘ppȡɫˣDzyCݞʢAɑzҹ潼ҡ潼ًDA|@Ƭrfո_ؘ̎~ȸSm +55_12 w wR侣Q[T衣w녣麟ĺɽꡣf̶ӰƣQƎ׶wеӽڣL +55_13 Ū ŪɽB녎͡܎ϴrͯŮoҊڡ¶yӚLb˼b˼ͽG pwP +56_1 }Ȫ ʯ㣬мȪm޹ɽã•ҰҡӰh~⣬仨ǰdǢ؎rϦ +56_2 ^ ֥ܹҰIʢҎģ̉铣CСɽӛ[DnAɵã顣 +56_3 ɢP Pɽ赩_ʯ·omRTȥţTR֣B񡣼P߶ȣǗ]ء +56_4 eѦA ͶF·ت򡣱ǧͬƯĹoՓȥcסljˡ +56_5 ؄eѦA ³֣Lh\_R^侁L졣òǧعꡣF;ΨМI߀Ȼ +56_6 [X w㣬_ᯡ~Rɽ·MeҰ}ϗUӰT p쟩 +56_7 ƽ ǧ[顣ߵ͌h Ȫ•~ŷɫɽbĺ̎MLĺԳ塣 +56_8 ͱR F;ޣ̓IMϡ_δѣǺ`|r񣬚qĺͬw +56_9 Tf RҰΣeǑKVɽơL~s¶֦ͤ޷hgġ +56_10 ATٸ AFգͤʳꡣ֪磬ѱȻ֘ǵգl·LȥȥεL߅ +56_11 ٸ֮ IoأLcxe⣬ͬǻ[ˡȴ֪o·Ůմ +56_12 ٴ |@仨ɫB£L^BwX~ˮ֪ɽԺY̎Ⱦ̉m +56_13 d Ո@誚ãxfӡmСLȥᣬLw~Ӱ衣ɽ˲ϧΨηG̓ +56_14 @ ϼpġɽɮϣhaQ١ݱͤϣ_ԺfxSd +56_15 ^E ɏ݃}ֺNLE\ؾʯ衣jAR㣬AӰǰhҕ̓ +56_16 ɽٛʿ 񶴂Ht֦¶o~녡бɽӰɳġ𷽴dӭ֡ +56_17 ɏ ͈@rLɡԮ}QFgָ녟[|QTKϣÓmWB֥ +56_18 ߀ fZyȸrȪݾGMŽYX~ְˮB·ɽ߀}ƽxM +56_19 ƴ@ ͶɽwyƌMˮLR߻͔㡣LСȻһǵ⡣ +56_20 ^ȑ ܚ[fEԡϝ~G{q飬ʯࡣܳαݡ +56_21 ՄeLʷ e·NǧذꡣգӱƪҰɫ\Fɽ┿ĺK֪yٷѵȻ +56_22 ȸ퍵b ٣дdwbGRɽ~MtйƬNȪ•᝾Ӱǰᱯh·e +56_23 L 緸㣬ϦPL֣ճΞͯԳី߀Пocهጳ +56_24 ~ȸ˶ P~ȸĺǡo̎_ƽϯξͣŃδAx䣬lҊ__顣檱mˣӳ]ءg۱M蠑lݡ\ţ_lٿp_ɡ +56_25 b[Te đ]·[Ӿ뽭ɡSoҹ•NeޣLvxgXɽh˼y +56_26 l b֕£ߺǡΣwϣؘŌٴgԘӰFYʧoΡʹ˛jɽwҹΞ +56_27 к `^½烉ɫ̓r氵Գɽ©ԣΞɢҰLHlPF +56_28 ҹ TR֣Σᯡ߽^•[LӰͯĺ鮣ɽŮҹ{衣˕rlh֪[ġ +56_29 † mA˪磬¶_ɢ̥]N¶ĕ޲ݣՑKƽ֥֡ٿՇ@ϢޝMY +56_30 G 豼֣ͱb᪡UoΣQāyrбTӰơˮ\侣ɽ䵤¡LO~¶̶֦ˮmڸl֪ +56_31 ˮß ɹٳȥxʼ@wfԊgLۡҸQ֘ϟMޒɣ]ؽP{Ͽͣ\tɡʯƫ˹ţ}ӛꡣܽܘ䣬ΣȪʯώXɳ𱱴rB̎GǰбȤh˼s +56_32 [^ٛʿһeԊ ʯDֵy뺶`mصMңʹώrɡF^o녰񉯿աҰ¶ɽ~LȪڣԊƹͬNʯ裬Ġw +56_33 P uofۣPvz档ȥ˽Iɽ³ +56_34 b ǧ룬һw߀@YҊ仨w +56_35 ݣ̿ϼɽˮ·漴w +56_36 ɽҹ _Ұңyƌˡ£eһҴ +56_37 f ɽm~҈@M֪oXB• +56_38 [ oOIС񳯻£X⡣ +56_39 @ ɽȪ̎һ@߀ǧˡ +56_40 Ȫ ֽTprɫpˡ +56_41 dzǴ ɽ\¡飬̎˴ +56_42 ld Y~w˻մ߅پ̎Խlˡ +56_43 ҹd ҰϦ侣ɽ֡߀ɢdż١ +56_44 R |ˮwwωmw򉌢eǾ[ˡȥ˻e·w[ޡľ~£ʳ +56_45 ͤҹ̈́e ͰˮɽM녡ͤҹlҊxty\w϶ˡżxͤڣɽҹ +56_46 e ÿͷNcleˡȻœIlmLeɽFࡣ;⣬߀ΡUmvmδ_Lp߀ˁ˪AQĩFɫ\HӳηˣΠ +56_47 ٛʮ Ұ˼éɽː֡Ψ̎LСƫ˲ݣͥƽԊcƣԵÕɼҡy_wMāPլeˡL{FٱֱԺYS_ +56_48 紺Ұ 紺ףɽLࡣlROӳ߅ͤ +56_49 ɽ LќfwrٸLɽɽS~w +56_50 ܎rף~t޺Mw +56_51 ҹ˼ Äe֑ѱl׃ɫ{Q٣˼˺ΘOg˼࣬šwСwι˄eɽ£ҹҹnʹb˼տG +56_52 ʼƽϢ ^ILɽ·dгϦo̎lҡ +56_53 Lxh YoȥLʯɽδѣ·ա +56_54 հ} hoOẲʡɽFY[ӎוr߀ +56_55 ꖹ_Tоջ֪;ƣռҡ +56_56 ュ̈́e lֵͤŽXŴeͿ[xۡwۚwTУϽl^һˮXɽǃl +56_57 о ¾l_ϯlͿͱхп࣬Ǐı؁ +56_58 ҹsw ɽFʼããϽ˪nn˼oѣֵҹ𡣏xؘ_L¶Ƚ˹ѹ磬˼Ҋ +56_59 仨䣨Ԋd 仨䣬仨ĮĮG~ӳ࣬cϽxӰyAۣh^Ļ仨wÁyᡡ仨M˚ww仨ȣ՚@ߘ䡣仨ѷ˴_x_of_Ǽt߀ʢ겻ٵã֦yʡԇ͵[仨Yĺ仨gc仨Ժ_pߡ +56_60 ՑѷԪ սԭƽҰ˪mãȾe¡٣ǧϡɽ⣬w +56_61 [ɽ ԴˮKo·ɽˡȄʯͶȪ䣬rŘ¡oбBBᣬB~[Qǧg磬Ԫ녽{溣Գɉm˪읡s֣wFᯡr`^]ʯmIgɽR񉯗ĺҹ鶴YꎡʒʒxӰ__lġlɽ[ã҂֡ +56_62 ꖘ]м˴ L BL·RŮbʡ֪Ϧ߀Ǽyֶȡ +56_63 ͤͬA ^оҕA񴰵¶~÷L䴺_Ffɳ_۸贵ĺ귺܇ diff --git a/temp.py b/temp.py index e69de29..8b13789 100755 --- a/temp.py +++ b/temp.py @@ -0,0 +1 @@ +