def installAssets(self, assets_path): assets = QDir(assets_path) assets.mkdir("plugins") assets.cd("plugins") assets.mkdir("animate") QFile.copy(":/animate.css", assets_path + "/plugins/animate/animate.css")
def __init__(self, parent=None): super(MainApp, self).__init__(parent) self.setupUi(self) #init statusbar self.setStyleSheet("QStatusBar::item { border: 0px solid black }; ") self.statusBar = QLabel() self.statusbar.addWidget(self.statusBar) self.statusBar.setText("No configuration file loaded.") #object variables self.currentPlugin = False self.pluginContainer = None self.selectedElement = None self.unsavedContent = False self.editorContainer = None self.ignoreWidgetsToSettingsData = False self.fileHandler = None self.lastFile = "" #buttons self.button_add.setEnabled(False) self.button_del.setEnabled(False) #signals self.actionLoad_Configuration.triggered.connect(self.loadFileDialog) self.actionSave_Configuration.triggered.connect(self.saveFile) self.actionSave_Configuration_File_As.triggered.connect(self.saveFileAs) self.actionNew_Configuration_File.triggered.connect(self.newFile) self.actionExit.triggered.connect(self.closeEventButton) self.actionAbout_This_Program.triggered.connect(self.showAboutWidget) self.button_add.clicked.connect(self.showAddSettingWidget) self.button_del.clicked.connect(self.deleteSetting) #treemodel self.treeView.setContextMenuPolicy(Qt.CustomContextMenu) self.treeView.customContextMenuRequested.connect(self.treeViewOpenMenu) self.treeView.mousePressEvent = MethodType(mousePressEvent, self.treeView) self.activeModel = SettingTree(self) self.proxyModel = FilterProxyModel(self) self.proxyModel.setSourceModel(self.activeModel) self.treeView.setModel(self.proxyModel) self.treeView.setColumnHidden(1, True) self.completeModel = SettingTree(HeaderData(True), self) #plugin content self.contentXML = None #icon self.icon = "" dataDir = QDir(os.path.dirname(os.path.realpath(__file__))) dataDir.cd("data") if dataDir.exists("icon.png"): self.icon = dataDir.absoluteFilePath("icon.png") self.setWindowIcon(QIcon(self.icon)) #programm configuration for window size and last filename self.programConfig = ProgramConfiguration(self) self.programConfig.loadConfiguration()
def setUp(self) -> None: self.newItemDefaultName = "NewEntry.md" self.itemProvider = EntryProviderFile(self.newItemDefaultName) dir = QDir('/tmp') dir.mkdir('retext_itemprovider_tests') dir.cd('retext_itemprovider_tests') self.testDir = dir self.itemProvider.setDirectory("/tmp/retext_itemprovider_tests")
def installAssets(self, assets_path): assets = QDir(assets_path) assets.mkdir("plugins") assets.cd("plugins") assets.mkdir("animate") dst = os.path.join(assets_path, "plugins", "animate", "animate.css") QFile.copy(":/animate.css", dst) os.chmod( dst, stat.S_IWRITE | stat.S_IREAD | stat.S_IWGRP | stat.S_IRGRP | stat.S_IROTH)
def loadProject(self, filename): if self.reloadProject(filename): # create temp dir for undo redo tempPath = self.site.source_path[self.site.source_path.rfind("/") + 1:] temp = QDir(QDir.tempPath() + "/FlatSiteBuilder") temp.mkdir(tempPath) temp.cd(tempPath) temp.mkdir("pages") temp.mkdir("posts") return True else: return False
def installAssets(self, assets_path): assets = QDir(assets_path) assets.mkdir("plugins") assets.cd("plugins") assets.mkdir("revolution-slider") assets.cd("revolution-slider") assets.mkdir("css") assets.mkdir("js") assets.mkdir("assets") QFile.copy(":/css", assets_path + "/plugins/revolution-slider/css") QFile.copy(":/js", assets_path + "/js") QFile.copy(":/js/plugins", assets_path + "/plugins/revolution-slider/js") QFile.copy(":/assets", assets_path + "/plugins/revolution-slider/assets")
def Successful_Tmp(self):# CheckTmpDir, StateTmpDir failed = lambda: not self.tdir or not self.tdir.isValid() if failed():# not successfully self.tdir = QTemporaryDir() if failed(): QMessageBox.critical(self, "Unexpected Failurer", "The application has detected a problem trying to\nCreate or Access a Temporary File!.") return None else: self.tdir.setAutoRemove(True) d = QDir(self.tdir.path()) if not d.exists("ninja-ide"): if not d.mkdir("ninja-ide"): self.tdir = None d.cd("ninja-ide") return d
def _appBundlePluginsPath(cls, appDirPath): ''' path to plugin directory of OSX app's bundle (especially when sandboxed, i.e. in a cls-contained bundle w/o shared libraries) If not (platform is OSX and app has PlugIns dir in the bundle), returns None. On other platforms (or when OSX app is not sandboxed) plugins are not usually bundled, but in the shared install directory of the Qt package. Implementation: use Qt since it understands colons (e.g. ':/') for resource paths. (Instead of Python os.path, which is problematic.) Convert string to QDir, move it around, convert back to string of abs path without colons. ''' # appDirPath typically "/Users/<user>/Library/<appName>.app/Contents/MacOS" on OSX. appDir = QDir(appDirPath) if not appDir.cdUp(): logAlert("Could not cdUp from appDir") # assert like ..../Contents if appDir.cd("PlugIns"): # !!! Capital I result = appDir.absolutePath() # assert like ..../Contents/PlugIns else: logAlert("Could not cd to PlugIns") result = None assert result is None or isinstance(result, str) return result
def initPlugins(self): #scan for plugins and import them pgmPath = os.path.dirname(os.path.realpath(__file__)) self.pluginContainer = [] pluginMainPath = QDir(pgmPath) if pluginMainPath.cd("plugins"): pluginEntries = pluginMainPath.entryList(QDir.Dirs, QDir.NoSort) if "." in pluginEntries: pluginEntries.remove(".") if ".." in pluginEntries: pluginEntries.remove("..") for item in pluginEntries: itemImport = "plugins." + item module = importlib.import_module(itemImport) pluginPath = QDir(pluginMainPath) pluginPath.cd(item) newPlugin = module.Plugin() self.pluginContainer.append([newPlugin,pluginPath]) return True else: return False
def Successful_Tmp(self): # CheckTmpDir, StateTmpDir failed = lambda: not self.tdir or not self.tdir.isValid() if failed(): # not successfully self.tdir = QTemporaryDir() if failed(): QMessageBox.critical( self, "Unexpected Failurer", "The application has detected a problem trying to\nCreate or Access a Temporary File!." ) return None else: self.tdir.setAutoRemove(True) d = QDir(self.tdir.path()) if not d.exists("ninja-ide"): if not d.mkdir("ninja-ide"): self.tdir = None d.cd("ninja-ide") return d
def scan_for_color_schemas(self) -> dict: """Scans <app data>/color_schemes subdirectories for color schemas. Returns a dictionary with information about the color schemes that were found""" # Get the list of all subdirectories path = self.get_appdata_path() + "/color_schemas" directory = QDir(path) # Create directory if it doesn't exist if not directory.exists(path): try: directory.mkpath(path) except Exception: print(f"Failed to create path: {path}") subdirectories = directory.entryList(QDir.Dirs | QDir.NoDotAndDotDot) schemas = dict() # Iterate over subdirectories to check if they contain color schemas for subdirectory in subdirectories: directory.cd(subdirectory) entries = directory.entryList(QDir.Files) # Check if schema file is present if "schema.toml" in entries: schema_info = dict() filepath = path + "/" + subdirectory + "/" + "schema.toml" # Try to parse color schema try: schema = toml.load(filepath) name = schema["Schema name"] schema_info["name"] = name schema_info["path"] = filepath schemas[name] = schema_info except Exception as e: print( f"Failed to parse color schema at path: {filepath}. Error: {str(e)}" ) return schemas
def loadProject(self, filename): self.default_path = filename[0:-9] # - /Site.qml if self.reloadProject(filename): # create temp dir for undo redo tempPath = self.site.source_path[self.site.source_path.rfind("/") + 1:] temp = QDir(os.path.join(QDir.tempPath(), "FlatSiteBuilder")) temp.mkdir(tempPath) temp.cd(tempPath) temp.mkdir("pages") temp.mkdir("posts") # in case these subfolders were empty and not published to github dir = QDir(self.site.source_path) dir.mkdir("pages") dir.mkdir("posts") dir.mkdir("assets") dir.cd("assets") dir.mkdir("images") return True else: return False
def initUI(self): self.setWindowTitle("userFirefox - userChrome tweak manager") self.setGeometry(300, 300, 640, 640) self.layoutBox = LayoutBox() self.setLayout(self.layoutBox) currentDir = QDir().current() logging.info("Current application dir: %s", currentDir.path()) currentDir.setFilter( QDir.Filters(24577) ) #filter only dirs 0x001 and no dots 0x2000 and 0x4000 results to 0d24577 tweakCats = currentDir.entryList() tweaksAvail = {} tweaksTree = {} logging.debug("List of tweak categoriess: %s", tweakCats) for tCat in tweakCats: categoryDir = QDir() categoryDir.setPath(currentDir.path()) categoryDir.cd(tCat) categoryDir.setFilter( QDir.Filters(2)) #filter files 0x002 results to 0d2 logging.debug("Tweaks in category %s are %s", tCat, categoryDir.entryList()) tweaksAvail[tCat] = categoryDir.entryList() logging.info("Dictionary of all available tweaks: %s", tweaksAvail) for tCat in tweaksAvail: logging.debug(tCat) tweaksTree["_uFFTree"] = {} tweaksTree[tCat] = QTreeWidgetItem( self.layoutBox.filesBox.availableTweaks) tweaksTree[tCat].setText(0, tCat) for tName in tweaksAvail[tCat]: tweaksTree["_uFFTree"][tName] = QTreeWidgetItem( tweaksTree[tCat]) tweaksTree["_uFFTree"][tName].setText(0, tName) #qtreetop = QTreeWidgetItem(self.layoutBox.filesBox.availableTweaks) #qtreetop.setText(0, "baf") self.show()
def scan_for_css_styles(self) -> dict: """Scans <app data>/css_styles subdirectories for css styles. Returns a dictionary with information about the styles that were found""" # Get the list of all subdirectories path = self.get_appdata_path() + "/css_styles" directory = QDir(path) if not directory.exists(): try: directory.mkpath(path) except Exception: print(f"Failed to create path: {path}") return dict() subdirectories = directory.entryList(QDir.Dirs | QDir.NoDotAndDotDot) styles = dict() # Iterate over subdirectories to check if they contain styles for subdirectory in subdirectories: directory.cd(subdirectory) entries = directory.entryList(QDir.Files) # Check if necessary files are present if "description.toml" in entries and "style.css" in entries: # Parse description try: style_info = toml.load(path + "/" + subdirectory + "/" + "description.toml") style_info[ "path"] = path + "/" + subdirectory + "/" + "style.css" styles[style_info["identifier"]] = style_info except Exception as e: print( f"Failed to parse css style at path: {path + '/' + subdirectory}. Error: {str(e)}" ) return styles
class Exportdialog(rcspy_Exportdialog.Ui_Dialog, QtWidgets.QDialog): def __init__(self, parent): super(Exportdialog, self).__init__(parent) self.setupUi(self) self.File_list.setSelectionMode(QAbstractItemView.ExtendedSelection) self.channel_list.setSelectionMode(QAbstractItemView.ExtendedSelection) self.connectevent() self.expath = "" self.radioMSEED.setChecked(True) self.radioSEED.setEnabled(False) def getFiles(self, Files): self.Files = Files for file in self.Files.files: listitem = QListWidgetItem(file) listitem.setText(file.name) self.File_list.addItem(listitem) def connectevent(self): self.btnOK.clicked.connect(self.Onbtnok) self.btn_Cancel.clicked.connect(self.Onbtncancel) self.File_list.itemSelectionChanged.connect( self.OnFilelist_selectionchange) self.channel_list.itemSelectionChanged.connect( self.Onchannellist_selectionchange) self.allchannel_checkbox.stateChanged.connect(self.Onallchannel_change) self.btn_set_folder.clicked.connect(self.set_exfolder) def set_exfolder(self): foldername = QFileDialog.getExistingDirectory(self, 'save folder') if foldername != "": self.expath = foldername self.Exfolder_edit.setText(foldername) def Onallchannel_change(self): if self.allchannel_checkbox.isChecked() == True: self.channel_list.selectAll() else: self.channel_list.clearSelection() self.single_channel_checkbox.setEnabled(True) def OnFilelist_selectionchange(self): self.channel_list.clear() if len(self.File_list.selectedItems()) == 1: self.channel_list.setEnabled(True) self.allchannel_checkbox.setEnabled(True) file = self.File_list.selectedItems()[0].parent for station in file.stations: listitem = QListWidgetItem(station) listitem.setText(station.name) self.channel_list.addItem(listitem) if len(self.File_list.selectedItems()) > 1: for item in self.File_list.selectedItems(): file = item.parent for station in file.stations: listitem = QListWidgetItem(station) listitem.setText(station.name) self.channel_list.addItem(listitem) self.channel_list.setEnabled(False) self.allchannel_checkbox.setChecked(True) self.allchannel_checkbox.setEnabled(False) self.radioMSEED.setChecked(True) def Onchannellist_selectionchange(self): count = self.channel_list.count() if len(self.channel_list.selectedItems()) == count: self.allchannel_checkbox.setChecked(True) else: self.allchannel_checkbox.setChecked(False) def Onbtncancel(self): self.close() def Onbtnok(self): if self.expath == "": QMessageBox.about(self, "tips", "please set export folder") elif len(self.File_list.selectedItems()) == 0: QMessageBox.about(self, "tips", "please set export files") else: self.dir = QDir() self.dir.cd(self.expath) self.pgb = QProgressBar(self) self.pgb.setWindowTitle("Exporting") self.pgb.setGeometry(140, 380, 260, 25) self.pgb.show() if self.radioMSEED.isChecked(): self.Export2mseed() if self.radioASCII.isChecked(): self.Export2Ascii() if self.radioSAC.isChecked(): self.Export2sac() self.pgb.close() QMessageBox.about(self, "tips", "finished") def Export2mseed(self): self.allnum = len(self.File_list.selectedItems()) self.currnum = 0 if self.allnum == 1: self.allnum = len(self.channel_list.selectedItems()) * 3 exstream = obspy.core.Stream() append = exstream.append for item in self.channel_list.selectedItems(): for channel in item.parent.channels: append(channel.tr) step = self.currnum * 100 / self.allnum self.pgb.setValue(int(step)) self.currnum = self.currnum + 1 file = self.File_list.selectedItems()[0].parent filesave = self.expath + "/" + str(file.ename) + ".mseed" ''' single channel ''' if self.single_channel_checkbox.isChecked() == True: self.currnum = 0 if self.dir.exists(file.ename) == False: self.dir.mkdir(file.ename) filesave = self.expath + "/" + file.ename + "/" for tr in exstream: tr.write(filesave + str(tr.id) + ".mseed", format='MSEED') step = self.currnum * 100 / self.allnum self.pgb.setValue(int(step)) self.currnum = self.currnum + 1 else: exstream.write(filesave, format='MSEED') else: ''' single channel ''' if self.single_channel_checkbox.isChecked() == True: for item in self.File_list.selectedItems(): self.allnum = self.allnum + len(item.parent.stations) * 3 for item in self.File_list.selectedItems(): file = item.parent if self.dir.exists(file.ename) == False: self.dir.mkdir(file.ename) filesave = self.expath + "/" + str(file.ename) + "/" for tr in file.stream: tr.write(filesave + str(tr.id) + ".mseed", format='MSEED') self.currnum = self.currnum + 1 step = self.currnum * 100 / self.allnum self.pgb.setValue(int(step)) else: for item in self.File_list.selectedItems(): file = item.parent filesave = self.expath + "/" + str(file.ename) + ".mseed" file.stream.write(filesave, format='MSEED') self.currnum = self.currnum + 1 step = self.currnum * 100 / self.allnum self.pgb.setValue(int(step)) def Export2Ascii(self): self.allnum = len(self.File_list.selectedItems()) self.currnum = 0 if self.allnum == 1: self.allnum = len(self.channel_list.selectedItems()) * 3 exstream = obspy.core.Stream() append = exstream.append for item in self.channel_list.selectedItems(): for channel in item.parent.channels: append(channel.tr) self.currnum = self.currnum + 1 step = self.currnum * 100 / self.allnum self.pgb.setValue(int(step)) file = self.File_list.selectedItems()[0].parent filesave = self.expath + "/" + str(file.ename) + ".ascii" ''' single channel ''' if self.single_channel_checkbox.isChecked() == True: if self.dir.exists(file.ename) == False: self.dir.mkdir(file.ename) filesave = self.expath + "/" + file.ename + "/" for tr in exstream: tr.write(filesave + str(tr.id) + ".ascii", format='SLIST') else: exstream.write(filesave, format='SLIST') else: ''' single channel ''' if self.single_channel_checkbox.isChecked() == True: for item in self.File_list.selectedItems(): self.allnum = self.allnum + len(item.parent.stations) * 3 for item in self.File_list.selectedItems(): file = item.parent if self.dir.exists(file.ename) == False: self.dir.mkdir(file.ename) filesave = self.expath + "/" + str(file.ename) + "/" for tr in file.stream: tr.write(filesave + str(tr.id) + ".ascii", format='SLIST') self.currnum = self.currnum + 1 step = self.currnum * 100 / self.allnum self.pgb.setValue(int(step)) else: for item in self.File_list.selectedItems(): file = item.parent filesave = self.expath + "/" + str(file.ename) + ".ascii" file.stream.write(filesave, format='SLIST') self.currnum = self.currnum + 1 step = self.currnum * 100 / self.allnum self.pgb.setValue(int(step)) def Export2sac(self): self.allnum = len(self.File_list.selectedItems()) self.currnum = 0 if self.allnum == 1: self.allnum = len(self.channel_list.selectedItems()) * 3 exstream = obspy.core.Stream() append = exstream.append for item in self.channel_list.selectedItems(): for channel in item.parent.channels: append(channel.tr) self.currnum = self.currnum + 1 step = self.currnum * 100 / self.allnum self.pgb.setValue(int(step)) file = self.File_list.selectedItems()[0].parent if self.dir.exists(file.ename) == False: self.dir.mkdir(file.ename) for tr in exstream: filesave = self.expath + "/" + file.ename + "/" + str( tr.id) + ".SAC" tr.write(filesave, format='SAC') else: self.allnum = 0 for item in self.File_list.selectedItems(): self.allnum = self.allnum + len(item.parent.stations) * 3 for item in self.File_list.selectedItems(): if self.dir.exists(item.parent.ename) == False: self.dir.mkdir(item.parent.ename) filedir = self.expath + "/" + item.parent.ename + "/" for tr in item.parent.stream: filesave = filedir + tr.id + ".SAC" tr.write(filesave, format='SAC') self.currnum = self.currnum + 1 step = self.currnum * 100 / self.allnum self.pgb.setValue(int(step))