def loadIcons(): """ loadIcons() Load all icons in the icon dir. """ # Get directory containing the icons iconDir = os.path.join(iep.iepDir, 'resources', 'icons') # Construct other icons dummyIcon = IconArtist().finish() iep.icons = ssdf.new() for fname in os.listdir(iconDir): if fname.startswith('iep'): continue if fname.endswith('.png'): try: # Short and full name name = fname.split('.')[0] ffname = os.path.join(iconDir, fname) # Create icon icon = QtGui.QIcon() icon.addFile(ffname, QtCore.QSize(16, 16)) # Store iep.icons[name] = icon except Exception as err: iep.icons[name] = dummyIcon print('Could not load icon %s: %s' % (fname, str(err)))
def loadIcons(): """ loadIcons() Load all icons in the icon dir. """ # Get directory containing the icons iconDir = os.path.join(iep.iepDir, 'resources', 'icons') # Construct other icons dummyIcon = IconArtist().finish() iep.icons = ssdf.new() for fname in os.listdir(iconDir): if fname.startswith('iep'): continue if fname.endswith('.png'): try: # Short and full name name = fname.split('.')[0] ffname = os.path.join(iconDir,fname) # Create icon icon = QtGui.QIcon() icon.addFile(ffname, QtCore.QSize(16,16)) # Store iep.icons[name] = icon except Exception as err: iep.icons[name] = dummyIcon print('Could not load icon %s: %s' % (fname, str(err)))
def addStarredDir(self, path): """ Add the given path to the starred directories. """ # Create new dict newProject = ssdf.new() newProject.path = path.normcase() # Normalize case! newProject.name = path.basename newProject.addToPythonpath = False # Add it to the config self.parent().config.starredDirs.append(newProject) # Update list self._projects.updateProjectList()
def loadTool(self, toolId, splitWith=None): """ Load a tool by creating a dock widget containing the tool widget. """ # A tool id should always be lower case toolId = toolId.lower() # Close old one if toolId in self._activeTools: old = self._activeTools[toolId].widget() self._activeTools[toolId].setWidget(QtGui.QWidget(pyzo.main)) if old: old.close() old.deleteLater() # Get tool class (returns None on failure) toolClass = self.getToolClass(toolId) if toolClass is None: return # Already loaded? reload! if toolId in self._activeTools: self._activeTools[toolId].reload(toolClass) return # Obtain name from buffered list of names for toolDes in self._toolInfo: if toolDes.id == toolId: name = toolDes.name break else: name = toolId # Make sure there is a config entry for this tool if not hasattr(pyzo.config.tools, toolId): pyzo.config.tools[toolId] = ssdf.new() # Create dock widget and add in the main window dock = ToolDockWidget(pyzo.main, self) dock.setTool(toolId, name, toolClass) if splitWith and splitWith in self._activeTools: otherDock = self._activeTools[splitWith] pyzo.main.splitDockWidget(otherDock, dock, QtCore.Qt.Horizontal) else: pyzo.main.addDockWidget(QtCore.Qt.RightDockWidgetArea, dock) # Add to list self._activeTools[toolId] = dock self.updateToolInstances()
def __init__(self, parent): QtGui.QWidget.__init__(self, parent) # Get config toolId = self.__class__.__name__.lower( ) + '2' # This is v2 of the file browser if toolId not in pyzo.config.tools: pyzo.config.tools[toolId] = ssdf.new() self.config = pyzo.config.tools[toolId] # Ensure three main attributes in config for name in ['expandedDirs', 'starredDirs']: if name not in self.config: self.config[name] = [] # Ensure path in config if 'path' not in self.config or not os.path.isdir(self.config.path): self.config.path = os.path.expanduser('~') # Check expandedDirs and starredDirs. # Make Path instances and remove invalid dirs. Also normalize case, # should not be necessary, but maybe the config was manually edited. expandedDirs, starredDirs = [], [] for d in self.config.starredDirs: if 'path' in d and 'name' in d and 'addToPythonpath' in d: if os.path.isdir(d.path): d.path = Path(d.path).normcase() starredDirs.append(d) for p in set([str(p) for p in self.config.expandedDirs]): if os.path.isdir(p): p = Path(p).normcase() # Add if it is a subdir of a starred dir for d in starredDirs: if p.startswith(d.path): expandedDirs.append(p) break self.config.expandedDirs, self.config.starredDirs = expandedDirs, starredDirs # Create browser(s). self._browsers = [] for i in [0]: self._browsers.append(Browser(self, self.config)) # Layout layout = QtGui.QVBoxLayout(self) self.setLayout(layout) layout.addWidget(self._browsers[0]) layout.setSpacing(0) layout.setContentsMargins(4, 4, 4, 4)
def __init__(self, parent): QtGui.QWidget.__init__(self, parent) # Get config toolId = self.__class__.__name__.lower() + '2' # This is v2 of the file browser if toolId not in pyzo.config.tools: pyzo.config.tools[toolId] = ssdf.new() self.config = pyzo.config.tools[toolId] # Ensure three main attributes in config for name in ['expandedDirs', 'starredDirs']: if name not in self.config: self.config[name] = [] # Ensure path in config if 'path' not in self.config or not os.path.isdir(self.config.path): self.config.path = os.path.expanduser('~') # Check expandedDirs and starredDirs. # Make Path instances and remove invalid dirs. Also normalize case, # should not be necessary, but maybe the config was manually edited. expandedDirs, starredDirs = [], [] for d in self.config.starredDirs: if 'path' in d and 'name' in d and 'addToPythonpath' in d: if os.path.isdir(d.path): d.path = Path(d.path).normcase() starredDirs.append(d) for p in set([str(p) for p in self.config.expandedDirs]): if os.path.isdir(p): p = Path(p).normcase() # Add if it is a subdir of a starred dir for d in starredDirs: if p.startswith(d.path): expandedDirs.append(p) break self.config.expandedDirs, self.config.starredDirs = expandedDirs, starredDirs # Create browser(s). self._browsers = [] for i in [0]: self._browsers.append( Browser(self, self.config) ) # Layout layout = QtGui.QVBoxLayout(self) self.setLayout(layout) layout.addWidget(self._browsers[0]) layout.setSpacing(0) layout.setContentsMargins(4,4,4,4)
def random_struct(self, level, maxn=16): level -= 1 # Create struct and amount of elements s = ssdf.new() n = random.randrange(0, maxn) # Fill for i in range(n): # Get name n = random.randrange(0, maxn) name = random.choice(NAMECHARS[:-10]) name += ''.join(random.sample(NAMECHARS,n)) if name.startswith('__'): name = 'x' + name # Get value s[name] = self.random_object(level) if random.random() > 0.5: return s else: return s.__dict__
# Create main window, using the selected locale frame = MainWindow(None, appLocale) # Enter the main loop QtGui.qApp.exec_() ## Init # List of names that are later overriden (in main.py) editors = None # The editor stack instance shells = None # The shell stack instance main = None # The mainwindow icon = None # The icon parser = None # The source parser status = None # The statusbar (or None) # Get directories of interest pyzoDir, appDataDir = getResourceDirs() # Whether the config file should be saved _saveConfigFile = True # Create ssdf in module namespace, and fill it config = ssdf.new() loadConfig() # Init default style name (set in main.restorePyzoState()) defaultQtStyleName = ''