def parent(self, index): if not index.isValid(): return QtCore.QModelIndex() child_item = index.internalPointer() parent_item = child_item.parent() if parent_item is None or parent_item == self.root_item: return QtCore.QModelIndex() return self.createIndex(parent_item.row(), 0, parent_item)
def index(self, row, column, parent=None): if parent is None: parent = QtCore.QModelIndex() if not self.hasIndex(row, column, parent): return QtCore.QModelIndex() parentItem = self.treeItem(parent) childItem = parentItem.child(row) if childItem: return self.createIndex(row, column, childItem) else: return QtCore.QModelIndex()
def _readModelSettings(self, reset=False, show_routine_attributes=None, show_special_attributes=None): """ Reads the persistent model settings . The persistent settings (show_routine_attributes, show_special_attributes) can be \ overridden by giving it a True or False value. If reset is True and the setting is None, True is used as default. """ default_sra = True default_ssa = True if reset: logger.debug("Resetting persistent model settings") if show_routine_attributes is None: show_routine_attributes = default_sra if show_special_attributes is None: show_special_attributes = default_ssa else: logger.debug("Reading model settings for window: {:d}".format( self._instance_nr)) settings = QtCore.QSettings() settings.beginGroup(self._settings_group_name('model')) if show_routine_attributes is None: show_routine_attributes = setting_str_to_bool( settings.value("show_routine_attributes", default_sra)) if show_special_attributes is None: show_special_attributes = setting_str_to_bool( settings.value("show_special_attributes", default_ssa)) settings.endGroup() logger.debug("read show_routine_attributes: {!r}".format( show_routine_attributes)) logger.debug("read show_special_attributes: {!r}".format( show_special_attributes)) return (show_routine_attributes, show_special_attributes)
def _readViewSettings(self, reset=False): """ Reads the persistent program settings :param reset: If True, the program resets to its default settings """ pos = QtCore.QPoint(20 * self._instance_nr, 20 * self._instance_nr) window_size = QtCore.QSize(1024, 700) details_button_idx = 0 header = self.obj_tree.header() header_restored = False if reset: logger.debug("Resetting persistent view settings") else: logger.debug("Reading view settings for window: {:d}".format( self._instance_nr)) settings = QtCore.QSettings() settings.beginGroup(self._settings_group_name('view')) pos = settings.value("main_window/pos", pos) window_size = settings.value("main_window/size", window_size) details_button_idx = int( settings.value("details_button_idx", details_button_idx)) self.central_splitter.restoreState( settings.value("central_splitter/state")) header_restored = self.obj_tree.read_view_settings( 'table/header_state', settings, reset) settings.endGroup() if not header_restored: column_sizes = [col.width for col in self._attr_cols] column_visible = [col.col_visible for col in self._attr_cols] for idx, size in enumerate(column_sizes): if size > 0: # Just in case header.resizeSection(idx, size) for idx, visible in enumerate(column_visible): self.obj_tree.toggle_column_actions_group.actions( )[idx].setChecked(visible) self.resize(window_size) self.move(pos) button = self.button_group.button(details_button_idx) if button is not None: button.setChecked(True)
def write_view_settings(self, key, settings=None): """ Writes the view settings to the persistent store """ logger.debug("Writing view settings for: {}".format(key)) if settings is None: settings = QtCore.QSettings() settings.setValue(key, self._horizontal_header().saveState())
def _writeModelSettings(self): """ Writes the model settings to the persistent store """ logger.debug("Writing model settings for window: {:d}".format(self._instance_nr)) settings = QtCore.QSettings() settings.beginGroup(self._settings_group_name('model')) logger.debug("writing show_routine_attributes: {!r}".format(self._tree_model.getShowCallables())) logger.debug("wrting show_special_attributes: {!r}".format(self._tree_model.getShowSpecialAttributes())) settings.setValue("show_routine_attributes", self._tree_model.getShowCallables()) settings.setValue("show_special_attributes", self._tree_model.getShowSpecialAttributes()) settings.endGroup()
def _writeViewSettings(self): """ Writes the view settings to the persistent store """ logger.debug("Writing view settings for window: {:d}".format(self._instance_nr)) settings = QtCore.QSettings() settings.beginGroup(self._settings_group_name('view')) self.obj_tree.write_view_settings("table/header_state", settings) settings.setValue("central_splitter/state", self.central_splitter.saveState()) settings.setValue("details_button_idx", self.button_group.checkedId()) settings.setValue("main_window/pos", self.pos()) settings.setValue("main_window/size", self.size()) settings.endGroup()
def refreshcontent(self): markdownpageinstance = getattr(self.parent, 'MarkdownPage') frame = markdownpageinstance.view.page().mainFrame() mdhtml = unicode(frame.evaluateJavaScript("$('#preview').html()")) if not os.path.exists(os.sep.join([os.getcwd(), 'doc'])): os.mkdir(os.sep.join([os.getcwd(), 'doc'])) htmlfile = os.sep.join([os.getcwd(), 'doc', 'preview.html']) self.theme = "evernote" self.html = mdhtmlcomplete( mdhtml, windowsoptions['markdownthemes']['theme%s' % self.theme], htmlfile, 'templateDef_evernote') url = QtCore.QUrl('file:///' + htmlfile) self.view.load(url)
def __init__(self, parent=None): super(FaderWidget, self).__init__(parent) if parent: self.startColor = parent.palette().window().color() else: self.startColor = QtCore.Qt.white self.currentAlpha = 0 self.duration = 1000 self.timer = QtCore.QTimer(self) self.timer.timeout.connect(self.update) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.resize(parent.size())
def __init__(self, text, bg, parent=None): super(DynamicTextWidget, self).__init__(parent) self.bg = bg self.text = text newFont = self.font() newFont.setPointSize(newFont.pointSize() + 10) self.setFont(newFont) self.painter = QtGui.QPainter() self.timer = QtCore.QBasicTimer() self.step = 0 self.timer.start(60, self)
def settheme(self): theme = self.sender().objectName()[5:-6] self.theme = theme markdownpageinstance = getattr(self.parent, 'MarkdownPage') frame = markdownpageinstance.view.page().mainFrame() mdhtml = unicode(frame.evaluateJavaScript("$('#preview').html()")) if theme == "evernote": self.html = mdhtmlcomplete( mdhtml, windowsoptions['markdownthemes']['themeevernote'], template='templateDef_evernote') elif theme == "jeklyy": self.html = mdhtmlcomplete( mdhtml, windowsoptions['markdownthemes']['themejeklyy'], template='templateDef_jeklyy') else: self.html = mdhtmlcomplete( mdhtml, windowsoptions['markdownthemes']['theme%s' % theme]) self.view.setHtml(self.html, QtCore.QUrl(os.getcwd()))
def read_view_settings(self, key, settings=None, reset=False): """ Reads the persistent program settings :param reset: If True, the program resets to its default settings :returns: True if the header state was restored, otherwise returns False """ logger.debug("Reading view settings for: {}".format(key)) header_restored = False if not reset: if settings is None: settings = QtCore.QSettings() horizontal_header = self._horizontal_header() header_restored = horizontal_header.restoreState( settings.value(key)) # update actions for col, action in enumerate(horizontal_header.actions()): is_checked = not horizontal_header.isSectionHidden(col) action.setChecked(is_checked) return header_restored
def loadfromlocal(self): html = self.auto_html(templateDef_absolute) url = QtCore.QUrl('file:///' + os.sep.join( [os.getcwd(), 'webjscss', 'MaDeEditor', 'MaDeEditor.html'])) self.view.load(url) self.view.setFocus()
def loadfromlocal(self): html = self.auto_html(templateDef_absolute) self.view.setHtml(html, QtCore.QUrl(os.getcwd()))