コード例 #1
0
	def __columnsShow(self):
		self.__colMenu.clear()
		reg = Registry()
		model = self.viewWidget().model()
		types = model.typeCodes().copy()
		columns = model.getColumns()
		for col in columns:
			(uti, path) = col.split(':')
			if uti != "":
				types.add(uti)
		# add stat columns
		self.__columnsShowAddEntry(self.__colMenu, columns, ":size", "Size")
		self.__columnsShowAddEntry(self.__colMenu, columns, ":mtime", "Modification time")
		self.__columnsShowAddEntry(self.__colMenu, columns, ":type", "Type code")
		self.__columnsShowAddEntry(self.__colMenu, columns, ":creator", "Creator code")
		self.__colMenu.addSeparator()
		# add meta columns
		metaSpecs = {}
		for t in types:
			metaSpecs.update(reg.searchAll(t, "meta"))
		for (uti, specs) in metaSpecs.items():
			subMenu = self.__colMenu.addMenu(reg.getDisplayString(uti))
			for spec in specs:
				key = uti+":"+reduce(lambda x,y: x+"/"+y, spec["key"])
				self.__columnsShowAddEntry(subMenu, columns, key, spec["display"])
コード例 #2
0
 def __columnsShow(self):
     self.__colMenu.clear()
     reg = Registry()
     model = self.viewWidget().model()
     types = model.typeCodes().copy()
     columns = model.getColumns()
     for col in columns:
         (uti, path) = col.split(':')
         if uti != "":
             types.add(uti)
     # add stat columns
     self.__columnsShowAddEntry(self.__colMenu, columns, ":size", "Size")
     self.__columnsShowAddEntry(self.__colMenu, columns, ":mtime",
                                "Modification time")
     self.__columnsShowAddEntry(self.__colMenu, columns, ":type",
                                "Type code")
     self.__columnsShowAddEntry(self.__colMenu, columns, ":creator",
                                "Creator code")
     self.__colMenu.addSeparator()
     # add meta columns
     metaSpecs = {}
     for t in types:
         metaSpecs.update(reg.searchAll(t, "meta"))
     for (uti, specs) in metaSpecs.items():
         subMenu = self.__colMenu.addMenu(reg.getDisplayString(uti))
         for spec in specs:
             key = uti + ":" + reduce(lambda x, y: x + "/" + y, spec["key"])
             self.__columnsShowAddEntry(subMenu, columns, key,
                                        spec["display"])
コード例 #3
0
ファイル: container.py プロジェクト: edwardt/hotchpotch
    def update(self):
        # reset everything
        self.__valid = False
        self.__icon = None
        for i in xrange(len(self.__columnDefs)):
            column = self.__columnDefs[i]
            if column.derived():
                self.__columnValues[i] = column.default()

        # determine revision
        needMerge = False
        if isinstance(self.__link, struct.DocLink):
            self.__link.update()
            revisions = self.__link.revs()
            if len(revisions) == 0:
                return
            elif len(revisions) > 1:
                needMerge = True
            # TODO: maybe sort by date
            rev = revisions[0]
        else:
            rev = self.__link.rev()
        self.__rev = rev

        # stat
        try:
            s = Connector().stat(rev)
        except IOError:
            return
        self.__uti = s.type()
        if needMerge:
            image = QtGui.QImage(Registry().getIcon(s.type()))
            painter = QtGui.QPainter()
            painter.begin(image)
            painter.drawImage(0, 0,
                              QtGui.QImage("icons/uti/merge_overlay.png"))
            painter.end()
            self.__icon = QtGui.QIcon(QtGui.QPixmap.fromImage(image))
        else:
            self.__icon = QtGui.QIcon(Registry().getIcon(s.type()))

        # overwritable by external files?
        self.__replacable = (not needMerge) and (not Registry().conformes(
            self.__uti, "org.hotchpotch.container"))

        self.__valid = True
        self.__updateColumns()
コード例 #4
0
ファイル: container.py プロジェクト: edwardt/hotchpotch
 def __addCreateActions(self, menu):
     newMenu = menu.addMenu(QtGui.QIcon("icons/filenew.png"),
                            "New document")
     sysStore = struct.Container(
         struct.DocLink(Connector().enum().sysStore()))
     templatesDict = struct.Container(sysStore.get("templates:"))
     items = templatesDict.items()
     items.sort(key=lambda item: item[0])
     for (name, link) in items:
         rev = link.rev()
         icon = QtGui.QIcon(Registry().getIcon(
             Connector().stat(rev).type()))
         action = newMenu.addAction(icon, name)
         action.triggered.connect(lambda x, r=rev: self.__doCreate(r))
コード例 #5
0
ファイル: container.py プロジェクト: edwardt/hotchpotch
def _columnFactory(key):
    if key == NameColumnInfo.KEY:
        return NameColumnInfo()
    else:
        (uti, path) = key.split(':')
        if uti == "":
            return StatColumnInfo(key)
        else:
            for meta in Registry().search(uti,
                                          "meta",
                                          recursive=False,
                                          default=[]):
                if path == reduce(lambda x, y: x + "/" + y, meta["key"]):
                    return MetaColumnInfo(key, meta)
    return None
コード例 #6
0
ファイル: container.py プロジェクト: edwardt/hotchpotch
 def __doubleClicked(self, index):
     link = self.model().getItemLinkUser(self.modelMapIndex(index))
     if link:
         executables = []
         revs = link.revs()
         for rev in revs:
             try:
                 uti = Connector().stat(rev).type()
                 executables = Registry().getExecutables(uti)
                 break
             except IOError:
                 pass
         self.itemOpen.emit(
             link, None, "org.hotchpotch.containerbrowser.py"
             in executables)
コード例 #7
0
	def __setViewHandler(self, link):
		link.update()
		executables = []
		for rev in link.revs():
			try:
				type = Connector().stat(rev).type()
				executables = Registry().getExecutables(type)
				if executables:
					break
			except IOError:
				pass
		for executable in executables:
			if executable in BrowserWindow.TYPES:
				break
		handler = BrowserWindow.TYPES[executable]
		if self.__viewHandler:
			if isinstance(self.__viewHandler, handler):
				return
			self.__viewHandler.delete()
		self.__viewHandler = handler(self)
		self.setCentralWidget(self.__viewHandler.getView())
コード例 #8
0
ファイル: properties.py プロジェクト: edwardt/hotchpotch
    def __init__(self, revs, parent=None):
        super(RevisionTab, self).__init__(parent)

        layout = QtGui.QGridLayout()
        layout.addWidget(QtGui.QLabel("Type:"), 1, 0)
        layout.addWidget(QtGui.QLabel("Modification time:"), 2, 0)
        layout.addWidget(QtGui.QLabel("Size:"), 3, 0)
        layout.addWidget(QtGui.QLabel("Stores:"), 4, 0)

        col = 1
        for rev in revs:
            stat = Connector().stat(rev)

            layout.addWidget(RevButton(rev, True), 0, col)
            layout.addWidget(
                QtGui.QLabel(Registry().getDisplayString(stat.type())), 1, col)
            layout.addWidget(QtGui.QLabel(str(stat.mtime())), 2, col)
            size = 0
            for part in stat.parts():
                size += stat.size(part)
            for unit in ['Bytes', 'KiB', 'MiB', 'GiB']:
                if size < (1 << 10):
                    break
                else:
                    size = size >> 10
            sizeText = "%d %s (%d parts)" % (size, unit, len(stat.parts()))
            layout.addWidget(QtGui.QLabel(sizeText), 3, col)

            storeLayout = QtGui.QVBoxLayout()
            for store in Connector().lookup_rev(rev):
                storeLayout.addWidget(DocButton(store, True))
            layout.addLayout(storeLayout, 4, col)

            col += 1

        self.setLayout(layout)
コード例 #9
0
ファイル: container.py プロジェクト: edwardt/hotchpotch
    def __addOpenActions(self, menu, link, isDoc):
        executables = []
        revs = link.revs()
        for rev in revs:
            try:
                uti = Connector().stat(rev).type()
                executables = Registry().getExecutables(uti)
                break
            except IOError:
                pass

        prefix = "Open"
        browseHint = False
        browsePreferred = False
        if "org.hotchpotch.containerbrowser.py" in executables:
            browsePreferred = True
        for e in executables:
            if e in self.__browseTypes:
                browseHint = True
                prefix = "Browse"
                break

        if isDoc:
            if browseHint:
                action = menu.addAction("&Browse")
                action.triggered.connect(
                    lambda x, l=link: self.itemOpen.emit(l, None, True))
                if browsePreferred:
                    menu.setDefaultAction(action)
                action = menu.addAction("&Open")
                action.triggered.connect(
                    lambda x, l=link: self.itemOpen.emit(l, None, False))
                if not browsePreferred:
                    menu.setDefaultAction(action)
            else:
                action = menu.addAction("&Open")
                action.triggered.connect(
                    lambda x, l=link: self.itemOpen.emit(l, None, False))
                menu.setDefaultAction(action)
            if len(executables) > 1:
                openWith = menu.addMenu("Open with")
                for e in executables:
                    action = openWith.addAction(e)
                    action.triggered.connect(
                        lambda x, l=link, e=e: self.itemOpen.emit(l, e, False))
            if isinstance(link, struct.DocLink):
                links = [struct.RevLink(rev) for rev in link.revs()]
                if len(links) == 1:
                    action = menu.addAction("Open revision (read only)")
                    action.triggered.connect(lambda x, l=links[0]: self.
                                             itemOpen.emit(l, None, False))
                elif len(links) > 1:
                    revMenu = menu.addMenu("Open revision (read only)")
                    for link in links:
                        date = str(Connector().stat(link.rev()).mtime())
                        action = revMenu.addAction(date)
                        action.triggered.connect(lambda x, l=link: self.
                                                 itemOpen.emit(l, None, False))
        else:
            links = [struct.RevLink(rev) for rev in link.revs()]
            if len(links) == 1:
                action = menu.addAction(prefix)
                action.triggered.connect(lambda x, l=link, h=browseHint: self.
                                         itemOpen.emit(l, None, h))
            elif len(links) > 1:
                for link in links:
                    date = prefix + " " + str(Connector().stat(
                        link.rev()).mtime())
                    action = menu.addAction(date)
                    action.triggered.connect(lambda x, l=link, h=browseHint:
                                             self.itemOpen.emit(l, None, h))