def __init__(self, state=None, **args): super().__init__(**args) layout = QtWidgets.QHBoxLayout(self) scene = DesktopScene(self) if state is not None: if 'items' in state: try: levels.real.collect([ t[0] for t in state['items'] if isinstance(t[0], int) ]) items = [] for t in state['items']: if t[0] == 'stack': item = StackItem.fromState(scene, t) else: item = CoverItem.fromState(scene, t) scene.addItem(item) except Exception as e: logging.warning(__name__, "Could not restore cover desk: " + str(e)) if 'domain' in state: scene.domain = domains.domainById(state['domain']) self.view = QtWidgets.QGraphicsView(scene) self.view.setAcceptDrops(True) self.view.setAlignment(Qt.AlignLeft | Qt.AlignTop) self.view.setDragMode(QtWidgets.QGraphicsView.ScrollHandDrag) #self.view.scene().selectionChanged.connect(self.selectionChanged) layout.addWidget(self.view) self.view.ensureVisible(0, 0, 1, 1, 0, 0)
def __init__(self, state=None, **args): super().__init__(**args) layout = QtWidgets.QHBoxLayout(self) scene = DesktopScene(self) if state is not None: if 'items' in state: try: levels.real.collect([t[0] for t in state['items'] if isinstance(t[0], int)]) items = [] for t in state['items']: if t[0] == 'stack': item = StackItem.fromState(scene, t) else: item = CoverItem.fromState(scene, t) scene.addItem(item) except Exception as e: logging.warning(__name__, "Could not restore cover desk: "+str(e)) if 'domain' in state: scene.domain = domains.domainById(state['domain']) self.view = QtWidgets.QGraphicsView(scene) self.view.setAcceptDrops(True) self.view.setAlignment(Qt.AlignLeft | Qt.AlignTop) self.view.setDragMode(QtWidgets.QGraphicsView.ScrollHandDrag) #self.view.scene().selectionChanged.connect(self.selectionChanged) layout.addWidget(self.view) self.view.ensureVisible(0, 0, 1, 1, 0, 0)
def __init__(self, name, path, domain, extensions, enabled: bool): super().__init__() self.name = name self.path = path self.domain = domains.domainById(domain) if isinstance(domain, int) else domain self.scanTimer = QtCore.QTimer() self.scanTimer.setInterval(200) self.scanTimer.timeout.connect(self.checkScan) self.extensions = list(extensions) self.enabled = False if enabled and not config.options.filesystem.disable: self.enable() else: self.files = {}
def loadFromDb(self, idList, level=None): """Load elements specified by *idList* from the database into *level* which defaults to the real level.""" if level is None: level = self if len(idList) == 0: # queries will fail otherwise return [] csIdList = db.csList(idList) # bare elements result = db.query(""" SELECT el.domain, el.id, el.file, el.type, f.url, f.length FROM {0}elements AS el LEFT JOIN {0}files AS f ON el.id = f.element_id WHERE el.id IN ({1}) """.format(db.prefix, csIdList)) for domainId, id, file, elementType, url, length in result: _dbIds.add(id) if file: level.elements[id] = elements.File(domains.domainById(domainId), level, id, url=URL(url), length=length, type=elements.ContainerType(elementType)) else: level.elements[id] = elements.Container(domains.domainById(domainId), level, id, type=elements.ContainerType(elementType)) # contents result = db.query(""" SELECT el.id, c.position, c.element_id FROM {0}elements AS el JOIN {0}contents AS c ON el.id = c.container_id WHERE el.id IN ({1}) ORDER BY position """.format(db.prefix, csIdList)) for id, pos, contentId in result: level.elements[id].contents.insert(pos, contentId) # parents result = db.query(""" SELECT el.id, c.container_id FROM {0}elements AS el JOIN {0}contents AS c ON el.id = c.element_id WHERE el.id IN ({1}) """.format(db.prefix, csIdList)) for id, contentId in result: level.elements[id].parents.append(contentId) # tags result = db.query(""" SELECT el.id, t.tag_id, t.value_id FROM {0}elements AS el JOIN {0}tags AS t ON el.id = t.element_id WHERE el.id IN ({1}) """.format(db.prefix, csIdList)) for id, tagId, valueId in result: tag = tags.get(tagId) level.elements[id].tags.add(tag, db.tags.value(tag, valueId)) # flags result = db.query(""" SELECT el.id, f.flag_id FROM {0}elements AS el JOIN {0}flags AS f ON el.id = f.element_id WHERE el.id IN ({1}) """.format(db.prefix, csIdList)) for id, flagId in result: level.elements[id].flags.append(flags.get(flagId)) # stickers result = db.query(""" SELECT element_id, type, data FROM {}stickers WHERE element_id IN ({}) ORDER BY element_id, type, sort """.format(db.prefix, csIdList)) # This is a bit complicated because the stickers should be stored in tuples, not lists # Changing the lists would break undo/redo #TODO: is this really necessary? current = None buffer = [] for (id, type, sticker) in result: if current is None: current = (id, type) elif current != (id, type): level.elements[current[0]].stickers[current[1]] = tuple(buffer) current = (id, type) buffer = [] element = level.elements[id] if element.stickers is None: element.stickers = {} buffer.append(sticker) if current is not None: level.elements[current[0]].stickers[current[1]] = tuple(buffer) try: return [self.elements[id] for id in idList] except KeyError: # probably some ids were not contained in the database raise levels.ElementGetError(self, [id for id in idList if id not in self])
def __init__(self, state=None, **args): """Initialize a new Browser with the given parent.""" super().__init__(**args) self.views = [] # List of treeviews self.domain = domains.domains[0] # These three criteria determine the set of elements displayed in the browser. They are combined # using AND. self.filterCriterion = None # Used by the 'filter'-line edit in the option dialog self.flagCriterion = None # Used by the flags filter in the option dialog self.searchCriterion = None # Used by the search box # Layout layout = QtWidgets.QVBoxLayout(self) layout.setSpacing(0) layout.setContentsMargins(0, 0, 0, 0) controlLineLayout = QtWidgets.QHBoxLayout() self.searchBox = searchgui.SearchBox() self.searchBox.criterionChanged.connect(self.search) controlLineLayout.addWidget(self.searchBox) # This option button is only used when dock widget title bars are hidden (otherwise the dock widget # title bar contains an analogous button). self.optionButton = dockwidget.DockWidgetTitleButton('options') self.optionButton.clicked.connect( functools.partial(self.toggleOptionDialog, self.optionButton)) controlLineLayout.addWidget(self.optionButton) self.optionButton.setVisible( mainwindow.mainWindow.hideTitleBarsAction.isChecked()) self.filterButton = FilterButton() controlLineLayout.addWidget(self.filterButton) self.filterButton.clicked.connect(self._handleFilterButton) layout.addLayout(controlLineLayout) self.splitter = QtWidgets.QSplitter(Qt.Vertical, self) layout.addWidget(self.splitter) # Restore state layersForViews = [self.defaultLayers()] self.delegateProfile = delegate.BrowserDelegate.profileType.default() self.sortTags = {} if state is not None and isinstance(state, dict): if 'domain' in state: self.domain = domains.domainById(state['domain']) if 'instant' in state: self.searchBox.instant = bool(state['instant']) if 'showHiddenValues' in state: self.showHiddenValues = state['showHiddenValues'] if 'views' in state: layersForViews = [] for layersConfig in state['views']: layers = [] layersForViews.append(layers) for layerConfig in layersConfig: try: className, layerState = layerConfig if className in model.layerClasses: theClass = model.layerClasses[className][1] layer = theClass(state=layerState) layers.append(layer) except Exception: logging.exception( __name__, "Could not parse a layer of the browser.") if 'flags' in state: flagList = [ flags.get(name) for name in state['flags'] if flags.exists(name) ] if len(flagList) > 0: self.flagCriterion = search.criteria.FlagCriterion( flagList) if 'filter' in state: try: self.filterCriterion = search.criteria.parse( state['filter']) except search.criteria.ParseException: logging.exception( __name__, "Could not parse the browser's filter criterion.") if 'delegate' in state: from maestro import profiles self.delegateProfile = profiles.category( 'delegates').getFromStorage( state['delegate'], profiles.category('delegates').getType('browser')) application.dispatcher.connect(self._handleChangeEvent) levels.real.connect(self._handleChangeEvent) self.createViews(layersForViews) self.filterButton.setEnabled(self.getFilter() is not None) global defaultBrowser defaultBrowser = self
def __init__(self, state=None, **args): super().__init__(**args) _coverBrowsers.add(self) self.domain = domains.domains[0] self.flagCriterion = None self.filterCriterion = None self.searchCriterion = None if state is not None: if 'domain' in state: self.domain = domains.domainById(state['domain']) if 'flags' in state: flagList = [flags.get(name) for name in state['flags'] if flags.exists(name)] if len(flagList) > 0: self.flagCriterion = search.criteria.FlagCriterion(flagList) if 'filter' in state: try: self.filterCriterion = search.criteria.parse(state['filter']) except search.criteria.ParseException: logging.exception(__name__, "Could not parse the cover browser's filter criterion.") self.worker = utils.worker.Worker() self.worker.done.connect(self._loaded) self.worker.start() layout = QtWidgets.QVBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) controlLineLayout = QtWidgets.QHBoxLayout() style = self.style() controlLineLayout.setContentsMargins(style.pixelMetric(style.PM_LayoutLeftMargin), style.pixelMetric(style.PM_LayoutTopMargin), style.pixelMetric(style.PM_LayoutRightMargin), 1) self.searchBox = searchgui.SearchBox() self.searchBox.criterionChanged.connect(self.search) controlLineLayout.addWidget(self.searchBox, 1) from maestro.widgets.browser.browser import FilterButton self.filterButton = FilterButton() self.filterButton.setEnabled(self.getFilter() is not None) controlLineLayout.addWidget(self.filterButton) self.filterButton.clicked.connect(self._handleFilterButton) self._display = None self._displayWidgets = {} self._displayConfig = state['config'] if state is not None and 'config' in state else {} self.displayChooser = QtWidgets.QComboBox() controlLineLayout.addWidget(self.displayChooser) self.displayChooser.currentIndexChanged.connect(self._handleDisplayChooser) self.updateDisplayChooser() # This option button is only used when dock widget title bars are hidden (otherwise the dock widget # title bar contains an analogous button). self.optionButton = dockwidget.DockWidgetTitleButton('options') self.optionButton.clicked.connect(functools.partial(self.toggleOptionDialog, self.optionButton)) controlLineLayout.addWidget(self.optionButton) self.optionButton.setVisible(mainwindow.mainWindow.hideTitleBarsAction.isChecked()) layout.addLayout(controlLineLayout) self.stackedLayout = QtWidgets.QStackedLayout() layout.addLayout(self.stackedLayout, 1) if state is not None and 'display' in state and state['display'] in _displayClasses: self.setDisplayKey(state['display']) else: self.setDisplayKey('table')
def loadFromDb(self, idList, level=None): """Load elements specified by *idList* from the database into *level* which defaults to the real level.""" if level is None: level = self if len(idList) == 0: # queries will fail otherwise return [] csIdList = db.csList(idList) # bare elements result = db.query(""" SELECT el.domain, el.id, el.file, el.type, f.url, f.length FROM {0}elements AS el LEFT JOIN {0}files AS f ON el.id = f.element_id WHERE el.id IN ({1}) """.format(db.prefix, csIdList)) for domainId, id, file, elementType, url, length in result: _dbIds.add(id) if file: level.elements[id] = elements.File( domains.domainById(domainId), level, id, url=URL(url), length=length, type=elements.ContainerType(elementType)) else: level.elements[id] = elements.Container( domains.domainById(domainId), level, id, type=elements.ContainerType(elementType)) # contents result = db.query(""" SELECT el.id, c.position, c.element_id FROM {0}elements AS el JOIN {0}contents AS c ON el.id = c.container_id WHERE el.id IN ({1}) ORDER BY position """.format(db.prefix, csIdList)) for id, pos, contentId in result: level.elements[id].contents.insert(pos, contentId) # parents result = db.query(""" SELECT el.id, c.container_id FROM {0}elements AS el JOIN {0}contents AS c ON el.id = c.element_id WHERE el.id IN ({1}) """.format(db.prefix, csIdList)) for id, contentId in result: level.elements[id].parents.append(contentId) # tags result = db.query(""" SELECT el.id, t.tag_id, t.value_id FROM {0}elements AS el JOIN {0}tags AS t ON el.id = t.element_id WHERE el.id IN ({1}) """.format(db.prefix, csIdList)) for id, tagId, valueId in result: tag = tags.get(tagId) level.elements[id].tags.add(tag, db.tags.value(tag, valueId)) # flags result = db.query(""" SELECT el.id, f.flag_id FROM {0}elements AS el JOIN {0}flags AS f ON el.id = f.element_id WHERE el.id IN ({1}) """.format(db.prefix, csIdList)) for id, flagId in result: level.elements[id].flags.append(flags.get(flagId)) # stickers result = db.query(""" SELECT element_id, type, data FROM {}stickers WHERE element_id IN ({}) ORDER BY element_id, type, sort """.format(db.prefix, csIdList)) # This is a bit complicated because the stickers should be stored in tuples, not lists # Changing the lists would break undo/redo #TODO: is this really necessary? current = None buffer = [] for (id, type, sticker) in result: if current is None: current = (id, type) elif current != (id, type): level.elements[current[0]].stickers[current[1]] = tuple(buffer) current = (id, type) buffer = [] element = level.elements[id] if element.stickers is None: element.stickers = {} buffer.append(sticker) if current is not None: level.elements[current[0]].stickers[current[1]] = tuple(buffer) try: return [self.elements[id] for id in idList] except KeyError: # probably some ids were not contained in the database raise levels.ElementGetError( self, [id for id in idList if id not in self])
def __init__(self, state=None, **args): """Initialize a new Browser with the given parent.""" super().__init__(**args) self.views = [] # List of treeviews self.domain = domains.domains[0] # These three criteria determine the set of elements displayed in the browser. They are combined # using AND. self.filterCriterion = None # Used by the 'filter'-line edit in the option dialog self.flagCriterion = None # Used by the flags filter in the option dialog self.searchCriterion = None # Used by the search box # Layout layout = QtWidgets.QVBoxLayout(self) layout.setSpacing(0) layout.setContentsMargins(0,0,0,0) controlLineLayout = QtWidgets.QHBoxLayout() self.searchBox = searchgui.SearchBox() self.searchBox.criterionChanged.connect(self.search) controlLineLayout.addWidget(self.searchBox) # This option button is only used when dock widget title bars are hidden (otherwise the dock widget # title bar contains an analogous button). self.optionButton = dockwidget.DockWidgetTitleButton('options') self.optionButton.clicked.connect(functools.partial(self.toggleOptionDialog, self.optionButton)) controlLineLayout.addWidget(self.optionButton) self.optionButton.setVisible(mainwindow.mainWindow.hideTitleBarsAction.isChecked()) self.filterButton = FilterButton() controlLineLayout.addWidget(self.filterButton) self.filterButton.clicked.connect(self._handleFilterButton) layout.addLayout(controlLineLayout) self.splitter = QtWidgets.QSplitter(Qt.Vertical, self) layout.addWidget(self.splitter) # Restore state layersForViews = [self.defaultLayers()] self.delegateProfile = delegate.BrowserDelegate.profileType.default() self.sortTags = {} if state is not None and isinstance(state, dict): if 'domain' in state: self.domain = domains.domainById(state['domain']) if 'instant' in state: self.searchBox.instant = bool(state['instant']) if 'showHiddenValues' in state: self.showHiddenValues = state['showHiddenValues'] if 'views' in state: layersForViews = [] for layersConfig in state['views']: layers = [] layersForViews.append(layers) for layerConfig in layersConfig: try: className, layerState = layerConfig if className in model.layerClasses: theClass = model.layerClasses[className][1] layer = theClass(state=layerState) layers.append(layer) except Exception: logging.exception(__name__, "Could not parse a layer of the browser.") if 'flags' in state: flagList = [flags.get(name) for name in state['flags'] if flags.exists(name)] if len(flagList) > 0: self.flagCriterion = search.criteria.FlagCriterion(flagList) if 'filter' in state: try: self.filterCriterion = search.criteria.parse(state['filter']) except search.criteria.ParseException: logging.exception(__name__, "Could not parse the browser's filter criterion.") if 'delegate' in state: from maestro import profiles self.delegateProfile = profiles.category('delegates').getFromStorage( state['delegate'], profiles.category('delegates').getType('browser') ) application.dispatcher.connect(self._handleChangeEvent) levels.real.connect(self._handleChangeEvent) self.createViews(layersForViews) self.filterButton.setEnabled(self.getFilter() is not None) global defaultBrowser defaultBrowser = self