This repository has been archived by the owner on Oct 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
197 lines (157 loc) · 6.96 KB
/
main.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
# -*- coding: utf-8 *-*
#
# This file is part of Minecraft backup Manager
#
# Minecraft Backup Manager is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# Minecraft Backup Manager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Minecraft Backup Manager. If not, see <http://www.gnu.org/licenses/>.
#
# Source: https://github.com/LuqueDaniel/Minecraft_backup.git
# Minecraft Backup Manager
from minecraft_backup.resources import IMAGES
from minecraft_backup.core import configuration
from minecraft_backup.core.backup_manager import load_backup_list
from minecraft_backup.core.backup_manager import remove_backup_name
from minecraft_backup.core.backup_manager import remove_backup
from minecraft_backup.core.backup_manager import restore_backup
from minecraft_backup.gui.center_widget import center_widget
from minecraft_backup.gui.msg_box import msg_about_qt
from minecraft_backup.gui.msg_box import msg_backup_folder_not_exists
from minecraft_backup.gui.msg_box import msg_remove_backup
from minecraft_backup.gui.msg_box import msg_restore_backup
from minecraft_backup.gui.msg_box import msg_restore_finishied
from minecraft_backup.gui.dialogs import config_window
from minecraft_backup.gui.dialogs import about_minebackup
from minecraft_backup.gui.dialogs import new_backup_window
# PyQt4.QtGui
from PyQt4.QtGui import QApplication
from PyQt4.QtGui import QMainWindow
from PyQt4.QtGui import QLabel
from PyQt4.QtGui import QPixmap
from PyQt4.QtGui import QIcon
from PyQt4.QtGui import QListWidget
from PyQt4.QtGui import QListWidgetItem
from PyQt4.QtGui import QPushButton
from PyQt4.QtGui import QMenu
# PyQt4.QtCore
from PyQt4.QtCore import QCoreApplication
from PyQt4.QtCore import SIGNAL
from PyQt4.QtCore import QRect
from PyQt4.QtCore import QTextCodec
# os
from os import path
# sys
import sys
class main_window(QMainWindow):
def __init__(self):
super(main_window, self).__init__()
self.setWindowTitle('Minecraft Backup Manager')
self.setGeometry(0, 0, 700, 520)
self.setMinimumSize(700, 520)
self.setMaximumSize(700, 520)
center_widget(self)
#Header
self.header_label = QLabel(self)
self.header_label.resize(700, 170)
self.header_label.setPixmap(QPixmap(IMAGES['header']))
#menu_about
self.menu_about = QMenu(self)
self.menu_about.addAction('About Minecraft Backup Manager',
lambda: self.open_about_minebackup())
self.menu_about.addAction('About Qt', lambda: msg_about_qt(self))
#btn_config
self.btn_config = QPushButton(QIcon(IMAGES['config_icon']), '', self)
self.btn_config.setGeometry(QRect(7, 7, 32, 32))
self.btn_config.setToolTip('Configuration')
#btn_about
self.btn_about = QPushButton('About', self)
self.btn_about.setGeometry(QRect(45, 7, 80, 32))
self.btn_about.setMenu(self.menu_about)
# list_backup
self.list_backup = QListWidget(self)
self.list_backup.setGeometry(QRect(20, 190, 450, 310))
# btn_new_backup
self.btn_new_backup = QPushButton('New backup', self)
self.btn_new_backup.setGeometry(QRect(485, 190, 200, 30))
# btn_restore_backup
self.btn_restore_backup = QPushButton('Restore backup', self)
self.btn_restore_backup.setGeometry(QRect(485, 260, 200, 30))
self.btn_restore_backup.setEnabled(False)
# btn_remove_backup
self.btn_remove_backup = QPushButton('Remove Backup', self)
self.btn_remove_backup.setGeometry(QRect(485, 300, 200, 30))
self.btn_remove_backup.setEnabled(False)
# CONNECT SIGNALS
self.connect(self.btn_config, SIGNAL('clicked()'), self.open_config)
self.connect(self.btn_new_backup, SIGNAL('clicked()'),
self.open_new_backup)
self.connect(self.btn_remove_backup, SIGNAL('clicked()'),
self.remove_backup)
self.connect(self.btn_restore_backup, SIGNAL('clicked()'),
self.restore_backup)
self.connect(self.list_backup,
SIGNAL('itemClicked(QListWidgetItem *)'),
self.enabled_buttons)
self.load_backup_list()
def load_backup_list(self):
self.list_backup.clear()
self.backup_list = load_backup_list()
if self.backup_list is not False:
for backup in self.backup_list.values():
if path.exists(backup['path']):
self.list_item = QListWidgetItem(backup['name'])
self.list_item.setToolTip('<b>Directory:</b> %s' %
backup['path'])
self.list_backup.addItem(self.list_item)
else:
msg_backup_folder_not_exists(self, backup['name'])
remove_backup_name(backup['name'])
def remove_backup(self):
self.remove_question = msg_remove_backup(self)
if self.remove_question is not False:
self.backup_name = self.list_backup.currentItem().text()
remove_backup(unicode(self.backup_name))
self.load_backup_list()
def restore_backup(self):
self.restore_question = msg_restore_backup(self)
if self.restore_question is not False:
self.backup_name = self.list_backup.currentItem().text()
restore_backup(unicode(self.backup_name))
msg_restore_finishied(self, self.backup_name)
def enabled_buttons(self):
self.btn_remove_backup.setEnabled(True)
self.btn_restore_backup.setEnabled(True)
def open_config(self):
self.configuration_window = config_window.config_window(self)
self.configuration_window.show()
def open_about_minebackup(self):
self.about_minebackup = about_minebackup.about_minebackup(self)
self.about_minebackup.show()
def open_new_backup(self):
self.new_backup_window = new_backup_window.new_backup_window(self)
self.new_backup_window.show()
# CONNECT SIGNALS
self.connect(self.new_backup_window, SIGNAL('close()'),
self.load_backup_list)
def start():
app = QApplication(sys.argv)
QCoreApplication.setApplicationName('Minecraft Backup Manager')
QCoreApplication.setApplicationVersion('1.0')
#Set Application icon
app.setWindowIcon(QIcon(IMAGES['minebackup_icon']))
#Codec for QString
QTextCodec.setCodecForCStrings(QTextCodec.codecForName('utf-8'))
#Create configuration
configuration.config()
minebackup = main_window()
minebackup.show()
sys.exit(app.exec_())