I am new to Xcos. Is there a way for a block to read or write to a variable that other blocks could also access? or if there is a work around to achieving the same. Thanks
Did you try to right-click in diagram window and select "Set Context" ? You should be able to define global variables there.
Related
In my application I have multiple variables that need to be accessed globally from the different functions of my script:
var a=1,b=2,c, ...;
Where "c" undefined at the beginning and takes value produced by some of the functions during scripts execution.
In order to declare them from within my "main" function I'm trying to use window object:
window.a=1;
window.b=2;
window.c;
This works, however I'm not sure if such approach is correct.
And is there is a way to avoid creation multiple window objects for each variable and combine them into more compact structure? Something like:
window.a=1,.b=2,.c;//---of course-this doesn't work
I was asking this question today too. It used to be the way when I last wrote javascript (mid-90s) and still seems to be the case see this resource
I'm looking for a way to change the QTextCharFormat of a QTextEdit's QTextBlock without triggering the addition of an undo command. Let me explain:
The QTextCharFormat of a QTextBlock can be easily changed by using the QTextCursor::setBlockCharFormat() method. Assuming we have a QTextEdit called myTextEdit whose visible cursor is within the text block we want to change, we can change the textblock's QTextCharFormat like so:
text_cursor = myTextEdit.textCursor()
text_cursor.setBlockCharFormat(someNewCharFormat)
The above code works fine, but it will also add an undo command to the myTextEdit undo stack. For my own purposes, I would like to be able to change the QTextCharFormat of a QTextBlock without adding an undo command to the QTextEdit's undo stack.
I considered temporarily disabling the undo/redo system with the QTextDocument::setUndoRedoEnabled() method, but that method also clears the undo stack, which I don't want to do. I've also looked for other ways to change how the undo/redo system behaves, but I haven't found a way to get it to temporarily ignore changes. I simply want to make a change to a QTextEdit without the undo/redo system registering the change at all.
Any tips or suggestions are appreciated. Thanks!
You have to group this with previous modification. It is simple you have to surround code which does this modification with: beginEditBlock and endEditBlock. See documentation.
text_cursor = myTextEdit.textCursor()
text_cursor.beginEditBlock()
text_cursor.setCharFormat(someOtherCharFormat) # some previous modification
text_cursor.setBlockCharFormat(someNewCharFormat)
text_cursor.endEditBlock()
this way you will make a single commit for undo stack for any complex modification.
joinPreviousBlock() should do the trick:
cursor = self.textCursor()
cursor.joinPreviousEditBlock()
cursor.setPosition(start, QTextCursor.MoveAnchor)
cursor.setPosition(end, QTextCursor.KeepAnchor)
cursor.setCharFormat(fmt)
cursor.endEditBlock()
You should use QSyntaxHighlighter. Extends it and implement highlightBlock func, and call setFormat in it to change format without making undo/redo stack. See documentation for more detail.
If you feel QSyntaxHighlighter is not what you want, you can use QTextLayout. It is low level api and its setAdditionalFormats func doesn't make any undo stack.
range1 = QTextLayout.FormatRange()
range1.start = 0
range1.length = 10
range1.format = QTextCharFormat()
# additional ranges here...
textBlock.layout().setAdditionalFormats([range1, ...])
This is also used in the inside of QSyntaxHighlighter.
I don’t understand the difference between let mapleader="," and let g:mapleader=",". I know that g: means that it’s a global variable, but I don’t clearly understand the difference. Which one should I use in my .vimrc file?
If the aforementioned statements are both located outside of function
definitions, they have the identical effect of setting a global variable. However, if the first statement, without the g: prefix, is used in
a function body, it defines a variable local to that function.
See :help internal-variables and especially :helpg In a function:.
Hence, outside function definitions one can access the global map-leader
variable simply as mapleader.
let mapleader=","
as stated in the doc.
Why would you want to use g:mapleader? g: is mostly used in plugins to let global variables in order to expose settings to other plugins or for you to play with in your .vimrc.
I have a flat data array that comes form a remoteobject, I want to group whatever is to be grouped, but leave single items (the ones with no common data with anything else) alone and without grouping, it's annoying to open each node only to find there's just one item inside, so there was no need to put it inside that group anyway.
Is this something anyone has done? I can't find any reference and I don't know if getting the hierarchicaldata out of the groupingcollection and then iterate thru it would be any good, sounds like a lot of duplicate work.
I ended up doing what shaunhusain said, I created my own copy of groupingcollection and monkeypatched the way it creates the groups, not clean enough for posting or general use yet, but working on it.
can also be accomplished by using a groupitemrenderer and hiding the disclosure icon based
on the number of children.
<mx:AdvancedDataGrid id="adg"
groupItemRenderer="my.namespace.GroupedItemRenderer"
</mx:AdvancedDataGrid>
GroupedItemRenderer is a subclass of AdvancedDataGridGroupItemRenderer
In updateDisplayList :
if (data && data.hasOwnProperty("children")) {
disclosureIcon.visible = (data.children.length > 0);
}
Is there any easy way to open the Qt dialogs in the same position as they were the last time the application was open ?
i.e. preserve position of dialogs between application sessions ?
By easy way I mean not to have manually write the window position in file, and then read :)
You can use the QSettings class to achieve this. It's an abstraction class that allow your applications to store its settings in order to retrieve them at next launch.
Save settings:
QSettings settings("ValueName", "Value");
Read settings:
QString v = settings.value("ValueName");
Use QSettings along with QWidget::restoreGeometry() and QWidget::saveGeometry().
Better to save dialog->pos(), dialog->size(), dialog->isMaximized(), cause dialog->saveGeometry() doesn't maximize the window.
QSettings is the preffered way to save configuration