class GUIdot_cleanMac(QDialog): def __init__(self, parent = None): super(GUIdot_cleanMac, self).__init__(parent) siguiente_btn = QPushButton('Siguiente') layout = QVBoxLayout() layout.addWidget(QLabel('Seleccione memoria:')) hlayout = QHBoxLayout() hlayout.addStretch() hlayout.addWidget(siguiente_btn) self.lista = QListWidget() nodos = self.getNodos() self.lista.addItems(nodos) layout.addWidget(self.lista) layout.addLayout(hlayout) layout.addWidget(QLabel('Hecho por: www.ehmsoft.com')) self.setLayout(layout) self.connect(siguiente_btn, SIGNAL('clicked()'), self.siguienteClicked) self.setWindowTitle('Dot Clean') if len(nodos) > 0: self.lista.setCurrentRow(0) def getNodos(self): #Lista todos los volumenes y quita el Disco Duro del sistema path = '/Volumes' folders = os.listdir(path) try: folders.remove('Macintosh HD') except ValueError: carpetas = copy.copy(folders) for folder in carpetas: if os.path.isdir(os.path.join('/Volumes', folder)): if os.path.exists(os.path.join('/Volumes', folder, 'Applications')): folders.remove(folder) finally: return folders def dot_clean(self, path): return os.system('dot_clean %s' % path) def siguienteClicked(self): if self.lista.currentItem(): selected = self.lista.currentItem().text() path = os.path.join('/Volumes', selected) if self.dot_clean(path) == 0: title = 'Proceso exitoso' msg = u'Se limpió la memoria con éxito' else: title = 'Proceso fallido' msg = u'Ocurrió un error inesperado. Verifique que la memoria esté montada.' else: title = 'Proceso fallido' msg = u'No se encuentra ninguna memoria, por favor introduzca una y vuelva a iniciar la apliación' QMessageBox.information(self, title, msg) self.close()
class ListWindow(QWidget): def __init__(self, list_text, pic_path): super(ListWindow, self).__init__() self.doubleclick_fun = None self._set_items(list_text, pic_path) def _set_items(self, list_text, pic_path): """ set the layout of listwidget :param list_text: list contains [title, subtitle] :param pic_path: string or list of strings """ print list_text self.list_widget = QListWidget() ly_vbox = QVBoxLayout() if type(pic_path) is not list: for item in list_text: self._setItem(item[0], item[1], pic_path) else: for i in range(len(list_text)): self._setItem(list_text[i][0], list_text[i][1], pic_path[i]) ly_vbox.addWidget(self.list_widget) self.list_widget.itemDoubleClicked.connect(self.item_doubleclick_slot) self.setLayout(ly_vbox) self.resize(300, 400) buttonBox = QDialogButtonBox(QDialogButtonBox.Ok |QDialogButtonBox.Cancel) ly_vbox.addWidget(buttonBox) buttonBox.accepted.connect(self.check_test) buttonBox.rejected.connect(self.reject) self.check_test() def check_test(self): pass def reject(self): print "XX" def _setItem(self, title, subtitle, pic_path): item_widget = QListWidgetItem() item_widget.setSizeHint(QSize(90, 60)) self.list_widget.addItem(item_widget) label = MyLable(title, subtitle, pic_path) self.list_widget.setItemWidget(item_widget, label) def item_doubleclick_slot(self): if self.doubleclick_fun: widget = self.list_widget.itemWidget(self.list_widget.currentItem()) # get MyLabel widget self.doubleclick_fun(widget.get_lb_title(), widget.get_lb_subtitle()) def set_doubleclick_slot(self, fun): """set item double click slot""" self.doubleclick_fun = fun
class Console(): def __init__(self, targetLayoutContainer): self.textarea = QTextEdit() self.commits = QListWidget() self.commits.addAction(QAction('Rollback to this revision', self.commits, triggered=self.rollback)) self.commits.setContextMenuPolicy(Qt.ActionsContextMenu) self.widget = QTabWidget() self.widget.addTab(self.textarea, 'Log') self.widget.addTab(self.commits, 'Commits') targetLayoutContainer.addWidget(self.widget) def color(self, module, function, color, *args): print module, function, args prettyString = '<font color="' + color + '"><b>', module, '</b><i>::', function, '</i> --> ', ''.join(args), '</font>' self.textarea.append(''.join(prettyString)) def info(self, module, function, *args): print module, function, args prettyString = '<font color="black"><b>', module, '</b><i>::', function, '</i> --> ', ''.join(args), '</font>' self.textarea.append(''.join(prettyString)) def error(self, module, function, *args): print module, function, args prettyString = '<font color="red"><b>', module, '</b><i>::', function, '</i> --> ', ''.join(args), '</font>' self.textarea.append(''.join(prettyString)) def warn(self, module, function, *args): print module, function, args prettyString = '<font color="#BE9900"><b>', module, '</b><i>::', function, '</i> --> ', ''.join(args), '</font>' self.textarea.append(''.join(prettyString)) def set_commits(self, commits): self.commits.clear() for commit in commits: self.commits.addItem(commit) def clear(self): self.textarea.clear() def rollback(self): targetCommit = self.commits.currentItem().text().split(' ')[0] if QMessageBox.warning(None, 'Rollback to commit?', 'All commits after ' + targetCommit + ' will be lost, proceed?', QMessageBox.Yes, QMessageBox.No) == QMessageBox.Yes: rollback(targetCommit)
class EditMovieWindow(QDialog): def __init__(self, parent): super(EditMovieWindow, self).__init__(parent) self.setModal(True) self.resize(500, 500) #self.setWindowTitle("Edit Movie: {}".format(movieObject.name)) self.movieObject = None mainLayout = QVBoxLayout(self) getMoviesBtn = QPushButton("Get movies from Movie DB") self.resultListView = QListWidget() self.resultListView.itemDoubleClicked.connect(self.editData) mainLayout.addWidget(getMoviesBtn) mainLayout.addWidget(self.resultListView) getMoviesBtn.clicked.connect(self.getMoviesAction) def getMoviesAction(self): movieList = dataDownloader.movieDBSearch(self.movieObject.name) for movie in movieList: movieItem = MovieItem(movie, self.restultListView) def editData(self): selectedItem = self.resultListView.currentItem() data = selectedItem.movieData # todo download new poster if data["poster_path"]: dataDownloader.downloadImage(data["poster_path"], self.movieObject.name) # todo download backdrop image if data["backdrop_path"]: dataDownloader.downloadImage(data["backdrop_path"], self.movieObject.name) # todo edit data in database self.movieObject.editData(data) self.accept() def setMovie(self, movieObject): self.setWindowTitle("Edit Movie: {}".format(movieObject.name)) self.movieObject
class Form(QDialog): def __init__(self, state, info, parent=None): super().__init__(parent) Lib.prepareModalDialog(self) self.state = state ListWidgetItem.info = info ListWidgetItem.refresh = self.refresh self.info = info self.helpPage = info.help self.createWidgets() self.layoutWidgets() self.setWindowTitle("{} — {}".format(self.info.name, QApplication.applicationName())) self.refresh() settings = QSettings() self.updateToolTips( bool( int( settings.value(Gopt.Key.ShowDialogToolTips, Gopt.Default.ShowDialogToolTips)))) def createWidgets(self): self.listWidget = QListWidget() self.buttonLayout = QVBoxLayout() for icon, text, slot, tip in ((":/add.svg", "&Add", self.add, """\ <p><b>Add</b></p><p>Add an item to the {} list.</p>""".format(self.info.name)), (":/edit.svg", "&Edit", self.edit, """\ <p><b>Edit</b></p><p>Edit the {} list's current item.</p>""".format(self.info.name)), (":/delete.svg", "&Remove...", self.remove, """\ <p><b>Remove</b></p><p>Remove the {} list's current item.</p>""".format(self.info.name)), (":/help.svg", "Help", self.help, """\ Help on the {} dialog""".format(self.info.name)), (":/dialog-close.svg", "&Close", self.accept, """\ <p><b>Close</b></p><p>Close the dialog.</p>""")): button = QPushButton(QIcon(icon), text) button.setFocusPolicy(Qt.NoFocus) if text in {"&Close", "Help"}: self.buttonLayout.addStretch() self.buttonLayout.addWidget(button) button.clicked.connect(slot) self.tooltips.append((button, tip)) self.tooltips.append((self.listWidget, self.info.desc)) def layoutWidgets(self): layout = QHBoxLayout() layout.addWidget(self.listWidget) layout.addLayout(self.buttonLayout) self.setLayout(layout) def refresh(self, *, text=None): self.listWidget.clear() cursor = self.info.db.cursor() for row, record in enumerate(cursor.execute(self.info.SELECT)): item = ListWidgetItem(record[0]) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEditable | Qt.ItemIsEnabled) item.setBackground(self.palette().base() if row % 2 else self.palette().alternateBase()) self.listWidget.addItem(item) if self.listWidget.count(): self.listWidget.setCurrentRow(0) if text is not None: for i in range(self.listWidget.count()): if self.listWidget.item(i).text() == text: self.listWidget.setCurrentRow(i) break def add(self): item = ListWidgetItem(ADDING) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEditable | Qt.ItemIsEnabled) self.listWidget.insertItem(0, item) self.listWidget.setCurrentRow(0) self.listWidget.editItem(item) def edit(self): item = self.listWidget.currentItem() if item is not None: self.listWidget.editItem(item) def remove(self): # No need to restore focus widget row = self.listWidget.currentRow() item = self.listWidget.item(row) if item is None: return with Lib.Qt.DisableUI(self, forModalDialog=True): reply = QMessageBox.question( self, "Remove {} — {}".format(self.info.name, QApplication.applicationName()), "Remove {} “{}”?".format(self.info.name, item.text()), QMessageBox.Yes | QMessageBox.No) if reply == QMessageBox.Yes: cursor = self.info.db.cursor() cursor.execute(self.info.DELETE, (item.text(), )) item = self.listWidget.takeItem(row) del item def help(self): self.state.help(self.helpPage)
class Panel(QWidget): def __init__(self, state, parent=None): super().__init__(parent=parent) self.state = state self.createWidgets() self.layoutWidgets() self.createConnections() self.tooltips.append((self, """<p><b>Groups panel</b></p> <p>This panel shows the groups the current entry belongs to.</p>""")) def createWidgets(self): self.label = QLabel("Gro&ups") self.groupsList = QListWidget() self.tooltips.append((self.groupsList, """ <p><b>Groups</b> (Alt+U)</p> <p>A (possibly empty) list of the current entry's groups.</p>""")) self.label.setBuddy(self.groupsList) self.closeButton = QToolButton() self.closeButton.setIcon(QIcon(":/hide.svg")) self.closeButton.setFocusPolicy(Qt.NoFocus) self.tooltips.append((self.closeButton, """<p><b>Hide</b></p> <p>Hide the Groups panel.</p> <p>Use <b>Spelling→Show Suggestions and Groups</b> to show it again.</p>""")) self.helpButton = QToolButton() self.helpButton.setIcon(QIcon(":/help.svg")) self.helpButton.setFocusPolicy(Qt.NoFocus) self.tooltips.append((self.helpButton, "Help on the Groups panel.")) def layoutWidgets(self): layout = QVBoxLayout() hbox = QHBoxLayout() hbox.addWidget(self.label) hbox.addStretch() hbox.addWidget(self.closeButton) hbox.addWidget(self.helpButton) layout.addLayout(hbox) layout.addWidget(self.groupsList) self.setLayout(layout) def createConnections(self): self.closeButton.clicked.connect(self.state.window.closeGroups) self.helpButton.clicked.connect(self.help) self.groupsList.itemDoubleClicked.connect( self.state.viewFilteredPanel.setGroup) def updateUi(self): enable = bool(self.state.model) and self.state.mode not in { ModeKind.NO_INDEX, ModeKind.CHANGE } self.setEnabled(enable) if enable: (self.state.window.entryActions.addToNormalGroupAction.setEnabled( self.state.model.normalGroupCount())) (self.state.window.entryActions.addToLinkedGroupAction.setEnabled( self.state.model.linkedGroupCount())) self.state.window.entryActions.removeFromGroupAction.setEnabled( self.groupsList.currentItem() is not None) def updateGroups(self): self.groupsList.clear() eid = self.state.viewAllPanel.view.selectedEid if eid is not None: for gid, name, linked in self.state.model.groupsForEid( eid, withLinks=True): item = QListWidgetItem(name) item.setData(Qt.UserRole, gid) item.setIcon( QIcon(":/grouplink.svg" if linked else ":/groups.svg")) self.groupsList.addItem(item) if self.groupsList.count(): self.groupsList.setCurrentRow(0) self.updateUi() self.state.viewFilteredPanel.groupChanged() def clear(self): self.groupsList.clear() self.updateUi() def help(self): self.state.help("xix_ref_panel_grp.html") def __getattr__(self, name): return getattr(self.groupsList, name)
class Form(QDialog): def __init__(self, term, state, parent=None): super().__init__(parent) Lib.prepareModalDialog(self) self.addingText = term self.state = state ListWidgetItem.model = state.model ListWidgetItem.refresh = self.refresh self.buttons = [] self.createWidgets() self.layoutWidgets() self.createConnections() self.setWindowTitle("Edit Groups — {}".format( QApplication.applicationName())) self.refresh() settings = QSettings() self.updateToolTips( bool( int( settings.value(Gopt.Key.ShowDialogToolTips, Gopt.Default.ShowDialogToolTips)))) def createWidgets(self): self.listWidget = QListWidget() self.buttonLayout = QVBoxLayout() self.linkButton = None for icon, text, slot, tip in ((":/add.svg", "&Add", self.add, """\ <p><b>Add</b> (Alt+A)</p><p>Add a new Normal Group.</p>"""), (":/edit.svg", "&Rename", self.rename, """\ <p><b>Rename</b> (Alt+R)</p><p>Rename the current Group.</p>"""), (":/grouplink.svg", "&Link", self.link, """\ <p><b>Link</b> (Alt+L)</p><p>Change the current group into a Linked Group.</p> <p>This means that the pages of every entry in this group will be merged and synchronized, and any future changes to the pages of any entries in this group will be propagated to all the other entries in this group to keep them all synchronized.</p>"""), (":/groups.svg", "&Unlink", self.unlink, """\ <p><b>Unlink</b> (Alt+U)</p><p>Change the current group into a Normal (unlinked) Group. If the linked group has entries, the <b>Delete Linked Group</b> dialog will pop up.</p>"""), (":/groupset.svg", "&View", self.viewGroup, """\ <p><b>View</b> (Alt+V)</p><p>View the current group in the Filtered View.</p>"""), (":/delete.svg", "&Delete", self.delete, """\ <p><b>Delete</b> (Alt+D)</p><p>Remove entries from the current normal group and then delete the group. If the current group is a linked group that has entries, the <b>Delete Linked Group</b> dialog will pop up.</p>"""), (":/help.svg", "Help", self.help, """\ Help on the Groups dialog"""), (":/dialog-close.svg", "&Close", self.accept, """\ <p><b>Close</b></p><p>Close the dialog.</p>""")): button = QPushButton(QIcon(icon), text) button.setFocusPolicy(Qt.NoFocus) if text in {"&Close", "Help"}: self.buttonLayout.addStretch() else: self.buttons.append(button) self.buttonLayout.addWidget(button) button.clicked.connect(slot) self.tooltips.append((button, tip)) if text == "&Link": self.linkButton = button button.setEnabled(False) elif text == "&Unlink": self.unlinkButton = button button.setEnabled(False) self.tooltips.append((self.listWidget, "List of Groups")) def layoutWidgets(self): layout = QHBoxLayout() layout.addWidget(self.listWidget) layout.addLayout(self.buttonLayout) self.setLayout(layout) def createConnections(self): self.listWidget.currentRowChanged.connect(self.updateUi) def updateUi(self): for button in self.buttons: button.setEnabled(True) item = self.listWidget.currentItem() if item is not None: gid = item.data(Qt.UserRole) self.linkButton.setEnabled(self.state.model.safeToLinkGroup(gid)) self.unlinkButton.setEnabled(self.state.model.isLinkedGroup(gid)) def refresh(self, *, text=None, index=None): self.listWidget.clear() for row, (gid, name, linked) in enumerate(self.state.model.allGroups()): item = ListWidgetItem(name) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEditable | Qt.ItemIsEnabled) item.setBackground(self.palette().base() if row % 2 else self.palette().alternateBase()) item.setData(Qt.UserRole, gid) item.setIcon( QIcon(":/grouplink.svg" if linked else ":/groups.svg")) self.listWidget.addItem(item) if self.listWidget.count(): self.listWidget.setCurrentRow(0) if index is not None: self.listWidget.setCurrentRow(index) elif text is not None: for i in range(self.listWidget.count()): if self.listWidget.item(i).text() == text: self.listWidget.setCurrentRow(i) break self.updateUi() def add(self): item = ListWidgetItem(self.addingText, adding=True) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEditable | Qt.ItemIsEnabled) self.listWidget.insertItem(0, item) self.listWidget.setCurrentRow(0) for button in self.buttons: button.setEnabled(False) self.listWidget.editItem(item) def rename(self): item = self.listWidget.currentItem() if item is not None: for button in self.buttons: button.setEnabled(False) self.listWidget.editItem(item) def link(self): item = self.listWidget.currentItem() if item is not None: gid = item.data(Qt.UserRole) if not self.state.model.safeToLinkGroup(gid): return # Should never happen self.state.model.linkGroup(gid) self.refresh(index=self.listWidget.currentRow()) def unlink(self): item = self.listWidget.currentItem() if item is not None: gid = item.data(Qt.UserRole) if not self.state.model.groupMemberCount(gid): self.state.model.unlinkGroup(gid) else: with Lib.Qt.DisableUI(self, forModalDialog=True): form = Forms.DeleteOrUnlink.Form("Unlink", gid, self.state, self) form.exec_() self.refresh(index=self.listWidget.currentRow()) def viewGroup(self): item = self.listWidget.currentItem() if item: self.state.viewFilteredPanel.setGroup(item) def delete(self): # No need to restore focus widget row = self.listWidget.currentRow() item = self.listWidget.item(row) if item is None: return gid = item.data(Qt.UserRole) for button in self.buttons: button.setEnabled(False) deleteItem = False if (not self.state.model.isLinkedGroup(gid) or not self.state.model.groupMemberCount(gid)): with Lib.Qt.DisableUI(self, forModalDialog=True): reply = QMessageBox.question( self, "Delete Group — {}".format(QApplication.applicationName()), "<p>Delete Group “{}”?</p>".format(item.text()), QMessageBox.Yes | QMessageBox.No) if reply == QMessageBox.Yes: self.state.model.deleteGroup(gid) deleteItem = True else: with Lib.Qt.DisableUI(self, forModalDialog=True): form = Forms.DeleteOrUnlink.Form("Delete", gid, self.state, self) deleteItem = form.exec_() if deleteItem: item = self.listWidget.takeItem(row) del item self.updateUi() def help(self): self.state.help("xix_ref_dlg_groups.html")