-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmineNemorge.py
214 lines (175 loc) · 6.4 KB
/
mineNemorge.py
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import sys,os
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QMainWindow,QAction,qApp, QApplication, QWidget, QLineEdit,\
QPushButton,QVBoxLayout, QHBoxLayout, QLabel,QFileDialog,QProgressBar,QMessageBox
from zipping_module import zipit
from rename_module import renameit
class Nemorge(QWidget):
def __init__(self):
super(Nemorge, self).__init__()
self.link = QLineEdit(self)
self.link.setPlaceholderText("Go to your path...")
self.opn = QPushButton("Open")
self.cpr = QPushButton("Compress")
self.rnm = QPushButton("Rename")
self.lbl1 = QLabel("Clean")
self.lbl2 = QLabel(" ")
self.prgrs = QProgressBar()
self.msg = QMessageBox()
self.msg.setIcon(QMessageBox.Warning)
self.msg.setText('Are you sure to rename without compressing!')
self.msg.setWindowTitle('Warning')
self.msg.setStandardButtons(QMessageBox.Yes|QMessageBox.Cancel)
self.var = 0
self.init_ui()
def init_ui(self):
v_layout = QVBoxLayout()
h_layout1 = QHBoxLayout()
h_layout2 = QHBoxLayout()
h_layout2.addStretch()
h_layout3 = QHBoxLayout()
h_layout4 = QHBoxLayout()
h_layout1.addWidget(self.link)
h_layout1.addWidget(self.opn)
h_layout2.addWidget(self.rnm)
h_layout2.addWidget(self.cpr)
h_layout3.addWidget(self.lbl2)
h_layout4.addWidget(self.prgrs)
v_layout.addLayout(h_layout3)
v_layout.addLayout(h_layout1)
v_layout.addLayout(h_layout2)
v_layout.addStretch()
v_layout.addLayout(h_layout4)
v_layout.addWidget(self.lbl1)
self.opn.clicked.connect(self.opn_file)
self.cpr.clicked.connect(self.zipping)
self.rnm.clicked.connect(self.renaming)
self.setLayout(v_layout)
self.show()
def opn_file(self):
self.prgrs.setValue(0)
try:
path = QFileDialog.getExistingDirectory(self, 'select a file', '')
if path:
self.link.setText(path)
self.lbl1.setText('Valid')
self.var = 0
else:
self.lbl1.setText('Invalid')
except:
pass
def zipping(self):
try:
work_path = self.link.text()
os.chdir(work_path)
zipit()
self.var = 1
except:
pass
def renaming(self):
try:
work_path = self.link.text()
if work_path:
if self.var == 0:
self.msg.show()
whichBtn = self.msg.exec_()
if whichBtn == QMessageBox.Yes:
os.chdir(work_path)
renameit()
else:
pass
else:
print('from outer one')
os.chdir(work_path)
renameit()
except:
pass
def prgrs_bar(self):
#Todo Connect filesize with value of progressbar
#Todo this is how set progressbar self.prgrs.setValue(value)
pass
class menubar(QMainWindow):
def __init__(self):
super(menubar, self).__init__()
self.setWindowIcon(QIcon('image/programIcon.png'))
self.statusBar().showMessage('')
self.form_widget = Nemorge()
self.setCentralWidget(self.form_widget)
self.init_ui()
def init_ui(self):
# make a menu bar
bar = self.menuBar()
# make main menus
file = bar.addMenu('File')
edit = bar.addMenu('Edit')
run = bar.addMenu('Run')
# make actions of menus
opn_icon = QIcon('image/open-file.png')
opn_action = QAction(opn_icon,'&Open',self)
opn_action.setShortcut('Ctrl+O')
opn_action.setStatusTip('open a file')
qut_icon = QIcon('image/quit.png')
qut_action = QAction(qut_icon,'&Quit',self)
qut_action.setShortcut('Ctrl+Q')
qut_action.setStatusTip('quit the program')
cpy_icon = QIcon('image/copy.png')
cpy_action = QAction(cpy_icon, '&Copy',self)
cpy_action.setShortcut('Ctrl+C')
cpy_action.setStatusTip('copy current selected')
cut_icon = QIcon('image/cut.png')
cut_action = QAction(cut_icon, '&Cut',self)
cut_action.setShortcut('Ctrl+X')
cut_action.setStatusTip('cut current selected')
pst_icon = QIcon('image/paste.png')
pst_action = QAction(pst_icon, '&Paste',self)
pst_action.setShortcut('Ctrl+V')
pst_action.setStatusTip('paste from clipboard')
comp_icon = QIcon('image/comp.png')
comp_action = QAction(comp_icon, '&Compress',self)
comp_action.setShortcut('Ctrl+R')
comp_action.setStatusTip('Compress all uncompressed folders')
renm_icon = QIcon('image/renm.png')
renm_action = QAction(renm_icon,'&Rename',self)
renm_action.setShortcut('Ctrl+N')
renm_action.setStatusTip('Rename all folders and files')
# put actions in their menus
file.addAction(opn_action)
file.addSeparator()
file.addAction(qut_action)
edit.addAction(cpy_action)
edit.addAction(cut_action)
edit.addAction(pst_action)
run.addAction(comp_action)
run.addAction(renm_action)
# actions signals and slots
file.triggered.connect(self.file_respond)
edit.triggered.connect(self.edit_respond)
run.triggered.connect(self.run_respond)
self.setWindowTitle('Nemorge')
self.resize(450,250)
self.show()
def file_respond(self,q):
signal = q.text()
if signal == '&Open':
self.form_widget.opn_file()
elif signal == '&Quit':
qApp.quit()
def edit_respond(self,q):
signal = q.text()
var = self.form_widget.link.text()
if signal == '&Copy':
qApp.clipboard().setText(var)
elif signal == '&Cut':
qApp.clipboard().setText(var)
self.form_widget.link.clear()
elif signal == '&Paste':
self.form_widget.link.setText(qApp.clipboard().text())
def run_respond(self,q):
signal = q.text()
if signal == '&Compress':
self.form_widget.zipping()
elif signal == '&Rename':
self.form_widget.renaming()
app = QApplication(sys.argv)
win = menubar()
sys.exit(app.exec_())