반응형

/*********************************************************************************************************

-- Title : [PyQt4] SQL Script Converter - dBRang

-- Reference : dBRang
-- Key word : python pyqt pyqt4 qt qt4 파이썬 SQL Script converter 스크립트
*********************************************************************************************************/




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# -*- coding: utf-8 -*-
 
import sys, string
from PyQt4 import QtGui, QtCore
 
class Window(QtGui.QMainWindow):
    def __init__(self):
        super(Window, self).__init__()
        #self.setGeometry(400, 20, 1200, 800)
        self.setFixedSize(1200800)
        self.setWindowTitle("SQL Script Converter")
        self.setWindowIcon(QtGui.QIcon("c:\sqlscriptconverter/img/pythonlogo.png"))
        QtGui.QApplication.setStyle("Cleanlooks")
 
        font = self.font()                                           # set font
        font.setFamily("GulimChe")
        font.setPointSize(10)
        self.setFont(font)
 
        self.statusBar()                                             # set statusbar
 
        self.vListcount = 0                                          # set user variables
        self.vEditchanged = False
        self.vSQLScript = ""
 
        # -- create listwidget objects ------------------------------
        self.tListwidget = QtGui.QListWidget(self)                   # set listwidget
        self.tListwidget.setGeometry(QtCore.QRect(3066220650))
        self.tListwidget.setFont(font)                               # set font of listwidget
 
        self.tListwidget.setStatusTip("This is a QlistWidget object.")
 
        # -- open file and add item ---------------------------------
        tInitfile = open('c:\sqlscriptconverter\convertlist.ini''r')
 
        while True:
            vInitfile = tInitfile.readline()                         # no more line, return "None"
            if not vInitfile:
                break
            self.tListwidget.addItem(vInitfile.replace("\n"""))    # add list item
 
        tInitfile.close()
 
        # -- create button objects ----------------------------------
        tButtonClear = QtGui.QPushButton("Clear"self)              # set clear button
        tButtonClear.clicked.connect(self.on_button_clear)
        tButtonClear.resize(10022)
        tButtonClear.move(3022)
        tButtonClear.setStatusTip("Clear text on the window.")
 
        tButtonConvert = QtGui.QPushButton("Convert(F5)"self)      # set convert button
        tButtonConvert.clicked.connect(self.on_button_convert)
        tButtonConvert.resize(10022)
        tButtonConvert.move(15022)
        tButtonConvert.setStatusTip("Convert your scripts on a rule basis. ")
 
        tButtonExit = QtGui.QPushButton("Exit"self)                # set exit button
        tButtonExit.clicked.connect(QtCore.QCoreApplication.instance().quit)
        tButtonExit.resize(10022)
        tButtonExit.move(107022)
        tButtonExit.setStatusTip("Quit this application.")
 
        # -- create textedit objects -------------------------------
        self.tTextedit = QtGui.QTextEdit(self)                       # set textedit box
        self.tTextedit.move(27066)
        self.tTextedit.resize(900650)
 
        self.tTextedit.textChanged.connect(self.on_text_changed)
        self.tTextedit.setStatusTip("You can paste your script here and convert it.")
 
        # -- create progressbar objects -----------------------------
        self.tProgress = QtGui.QProgressBar(self)                    # set progressbar
        self.tProgress.setGeometry(30734113020)
 
        self.on_load_sql()
 
    def on_load_sql(self):                                           # set initiate loading
        self.vSQLfile = open('c:\sqlscriptconverter\sql.ini''r')
        self.vSQLread = self.vSQLfile.read()
 
        self.tTextedit.setText(self.vSQLread)
 
        self.vSQLfile.close()
 
    def on_text_changed(self):
        self.vEditchanged = True
 
    def on_button_clear(self):                                       # set action of clear button
        self.vEditchanged = False
        self.vSQLScript = ""
        #self.on_load_sql()
        self.tTextedit.clear()
        self.tProgress.setValue(0)
 
    def keyPressEvent(self, e):                                      # system method for F-Key
        if e.key() == QtCore.Qt.Key_F5:
            self.on_button_convert()
 
    def on_button_convert(self):                                     # set actioni of vconvert button
        vKey1 = ""                                                   # 변환될 단어 할당(ex. select)
        vKey2 = ""                                                   # 변환할 단어 할당(ex. SELECT)
        vKeylist      = ["\n""\t""("" "";"","")"]        # 변환 단어 + 리스트 결합
        vKeylistcount = len(vKeylist)                                # 리스트 개수 저장
        vLoop = 0                                                    # 프로그래스바를 위한 Loop 카운팅
 
        self.vListcount = self.tListwidget.count()
        self.vSQLScript = self.tTextedit.toPlainText()
 
        vBarrate = 100. / (self.vListcount * vKeylistcount)
 
        for i in range(1self.vListcount + 1):
            vKey1 = self.tListwidget.item(i-1).text()
            vKey2 = str(vKey1).upper()
 
            for j in range(1, vKeylistcount + 1):
                vLoop += 1
                vSQL1 = vKey1 + vKeylist[j - 1]
                vSQL2 = vKey2 + vKeylist[j - 1]
 
                self.vSQLScript = string.replace(self.vSQLScript, vSQL1, vSQL2)
                self.tProgress.setValue(vBarrate * vLoop)
 
        # -- 불용어 역전환
        xKey = ["skey""wkey""fkey""tkey""account""quotas""_key"".ref""_ref""gkey""dateend"]
        for xxKey in xKey:
            self.vSQLScript = string.replace(self.vSQLScript, xxKey, xxKey.lower())
 
        self.tTextedit.setText(self.vSQLScript)
 
if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    gui = Window()
    gui.show()
    sys.exit(app.exec_())
 

cs



convertlist.ini

sql.ini


반응형

+ Recent posts