def keyPressEvent(self, event): log.info("Key Press") key = event.key(); key = Qt.Key(key); # Ignore unknown keys # and if modifier keys come alone if key == Qt.Key_unknown or key in (Qt.Key_Control, Qt.Key_Alt, Qt.Key_AltGr, Qt.Key_Shift): return # Pressing Backspace will clear the content if key == Qt.Key_Backspace: self.setText(None) self.clearKeySequence() return # Checking for key combinations modifiers = event.modifiers(); if(modifiers & Qt.NoModifier): return if(modifiers & Qt.ShiftModifier): key += Qt.SHIFT if(modifiers & Qt.ControlModifier): key += Qt.CTRL if(modifiers & Qt.AltModifier): key += Qt.ALT self.setKeySequence(QKeySequence(key))
def save(self): log.info("Saving Hotkey stuff in Hotkeydialog") for i in range(0, self.ui.formLayout.rowCount()): key = self.ui.formLayout.itemAt(i, QFormLayout.LabelRole).widget().text() edit = self.ui.formLayout.itemAt(i, QFormLayout.FieldRole).widget() if key not in self.shortcuts: raise RuntimeError self.shortcuts[key].setKey(edit.key_sequence)
def setupUnrar(unrar_path): global supported_archives unrar = which(unrar_path) if unrar is None: log.warning("UnRAR executable not accessible: %s" % unrar_path) log.warning("Disabling rar archive support...") rarfile.UNRAR_TOOL = None supported_archives = [x for x in supported_archives if x not in rar_like_archives] else: log.info("UnRAR executable accessible: %s" % unrar) log.info("Enabling rar archive support...") rarfile.UNRAR_TOOL = unrar supported_archives += rar_like_archives
def execDialog(self): """ execute dialog and apply settings if pressed OK """ dialog = SettingsDialog(self.settings.copy(), self.shortcuts) if dialog.exec_(): log.info("Saving settings...") oldpath = self.settings[MANGA_SETTINGS_PATH] newpath = dialog.settings[MANGA_SETTINGS_PATH] # copy old file to new location if newpath doesn't exist if oldpath != newpath and not os.path.exists(newpath): copy(oldpath, newpath) self.settings = dialog.settings self.refreshMangaSettings() return True return False
def open(self): """ Opens the path the layer was constructed with. Handles the type of the path appropriately and returns a list of pairs with (path, Layer) entries or a PIL.Image if self.path is an image or None if it failed to load anything """ entries = None if isImage(self.path): # got an image, load it! if self.archive: # load the image from the archive! log.info("Open image '%s' in archive '%s'" % (self.path, self.archive.file)) file = self.archive.open(self.path) try: image = Image.open(file).convert("RGB") return image except IOError as ex: log.error("Failed loading image '%s' in archive '%s'" % (self.path, self.archive.file)) return None return image else: log.info("Open image '%s' from filesystem" % self.path) return Image.open(self.path).convert("RGB") elif isZip(self.path): # got a zipfile, open it! if self.archive: log.info("Open zip '%s' in archive '%s'" % (self.path, self.archive.file)) file = self.archive.open(self.path) archive = Zip(file) else: log.info("Open zip '%s' from filesystem" % self.path) archive = Zip(self.path) name_pairs = [(name, Layer(name, archive)) for name in archive.names if isRar(name) or isZip(name) or isImage(name)] entries = dict(name_pairs) elif isRar(self.path) and isRARactive(): # got a rarfile, open it! if self.archive: log.info("Open rar '%s' in archive '%s'" % (self.path, self.archive.file)) #file = self.archive.open(self.path) #archive = Rar(file) log.error("Opening rar archives inside another archive isn't supported!") raise RuntimeError("Opening rar archives inside another archive isn't supported!") else: log.info("Open rar '%s' from filesystem" % self.path) archive = Rar(self.path) name_pairs = [(name, Layer(name, archive)) for name in archive.names if isRar(name) or isZip(name) or isImage(name)] entries = dict(name_pairs) elif os.path.isdir(self.path): # load names in directory log.info("Open directory '%s' from filesystem" % self.path) dir = os.listdir(self.path) # save all names in directory name_pairs = [(d, Layer(os.path.join(self.path, d))) for d in dir if isSupportedArchive(os.path.join(self.path, d)) or isImage(d)] entries = dict(name_pairs) else: log.warning("Unknown file: %s" % self.path) return None return entries
def mousePressEvent(self, event): log.info("Mouse press")