Loading big files into GtkSourceView is slow - pygtk

I am trying to load 1k+ lines long files into GtkSourceView, using GTK3 in Python (PyGObject).
Whenever I set the text, it takes 2-3sec to fully appear (it is slowly scrolling and adding new lines at the bottom). I have connected a profiler and it shows 99.5% of cpu time in Gtk.main.
Basically I am using this for setting text:
txt_sourceview.get_buffer().set_text(new_text)
Am I doing something wrong here? Is there a way to speed this up?

Related

Conveniently randomize image via button from folder/slide?

I often spend hours bringing pictures into PowerPoint templates one by one and trying to customize the way a presentation whose behavior is very different.
If there were a way to randomly select an image from all of the images on a different slide or excel file or folder and have them appear based on the probable weight assigned to them, it would be a huge time saver.
I've seen various methods of having a random object appear, and some of them don't even require a macro, but importing the images is always very time consuming. If anyone knows of a better/faster way to link a folder with a group of images or something along these lines to an object that is randomized, please help.
Importantly, showing a random image from a batch group without customizing the way each image is brought in is the hard part. Adding weight helps, but it could be done by duplicating important images repeatedly.

ROIs in Digital Micrograph EELSspectra behave strangely after command "EELSSubtractPowerlawBackground()" - Bug? (GMS 2.3)

When I run the script below on a DM EELS spectrum that already contains background and signal ROIs, it is ok if I don't show any images.
ImageDocument imdoc = GetFrontImageDocument()
image i0 = ImageDocumentGetImage(imdoc,0)
image subt = eelssubtractpowerlawbackground(i0,800,900)
//image irrelevant = realimage("irrelevant",4,100,100)
//showimage(irrelevant)
But if I show any image after running the background subtraction command (activate the last 2 lines for example) the pre-existing ROIs on the initial image are changed (sig disappears and bckgd is moved to the new position).
This is despite i0 being in theory a new image, not part of the initial one.
Creating copies within the script and working on them appears in any case not to solve the problem.
More surprising is that if I first make a duplicate of the initial image and run the script on that, then close the new windows and the (modified) spectrum on which the script was run, then try and duplicate the initial image, the duplicate has the modified ROIs rather than its own. A second duplicate seems to be ok. I have no idea what's going on. Grateful for any ideas.
(The problem was initially part of a much bigger script in which I need to show images, I've reduced it to the essentials here). I'm using v2.3.2.
I have tested your script on an EELS Spectrum with ROIs in GMS 2.3.3 and in GMS 3.2.2
GMS 2.3.3:
It does not seem to happen due to the ShowImage() but rather whenever the display of the image the last Background/Signal ROI was used on is refreshing its display. You get the same behavior when you run your script without the last two lines, but then click on another image (to select it) and then the spectrum again. And you get the same if you've used the background-subtraction ROI on a completely different image and then run the script. It messes up that last images' ROIs.
GMS 3.2.2: Doesn't show this. All is fine regardless what you do.
So, from these two tests I would conclude it is a bug in GMS 2.3 which has since been fixed.
The behaviour is indeed very odd, and I see nothing wrong with your code.
The bug seems to be that the command eelssubtractpowerlawbackground() messes with the settings of the last active signal-extracting ROIs, regardless on where they are placed on. It doesn't matter what the input image is. It seems to "reuse" these last ROIs.
Unfortunately, I don't know a good workaround for it.

Issues with IntelliJ on a 4K screen

I splurged and bought one of those high definition 4K screens. More specifically, the Dell UltraSharp 4k UP3216Q 31.5", combined with a new PC running Windows 10.
When the computer occasionally reboots, it goes into a mode where when I load IntelliJ, it shows the following error message:
8:16 PM You may need to manually configure the HiDPI mode to prevent UI scaling issues. See the troubleshooting guide.
The interesting thing is that when it's running in this mode, I actually like the way IntelliJ looks. I like it because it's running in true sharp 4K mode, and at the same time, all the fonts are large enough to be legible, and not require a magnetic resonance microscope or a monocle to make out the letters.
However, other times, when the system boots up, I do not get that error, meaning everything is functioning normally, but in that case, all the fonts are so tiny as to be illegible. It literally hurts my eyes to look at it, and the only alternatives I have left at that point is to either drop down from 3840x2160 into 1920x1080, or to go into the settings, and start increasing the font sizes, which is annoying. Not to mention that if I drop down into 1920x1080 mode, then the quality of what I am looking at degrades, everything starts looking pixelated...
Is there anything that can be done to stabilize the situation on these new 4K screens so that IntelliJ looks normal?
Try this:
Help > Edit Custom VM Options:
-Dsun.java2d.uiScale.enabled=true
More information can be found here:
https://intellij-support.jetbrains.com/hc/en-us/articles/115001260010-Troubleshooting-IDE-scaling-DPI-issues-on-Windows
If that does not help create a ticket in the JetBrains issue tracker: https://youtrack.jetbrains.com/
They are usually very responsive.
Another possibility is that you have the Windows UI scaling value for the screen set to a non-integral value in display settings. This messed me up, I had the setting to 175%, while the default is 200%. Intellij (and many other applications) will not scale properly if that is set to a non-integral scaling value.
As soon as I switch this back to 200% Intellij scales perfectly.
I fix this problem after setted env variable IDEA_JDK_64 to jdk path in windows 10

Download infinitely scrolling webpage chunk by chunk (Selenium/PhantomJS)

I am using Selenium with PhantomJS to scroll to the bottom of an infinitely scrolling page of Twitter search results.
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
I manually set a number of times for it too loop (I try to estimate how many reloads the web driver can take before crashing). When done, I grab the raw html:
text_file.write(driver.page_source.encode("utf-8"))
This works ok, but I am looking for a way to keep the program going without the 'browser cache', or whatever it is called, filling up. Any ideas on how to achieve the steps below?
Run the driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")command for X times
Then dump the loaded raw html to a text file
Then run the driver for X times again
Then dump the loaded raw html into another text file, but not the content loaded in step 1, only the new content loaded in step 3
This would empty the browser/driver memory into several output text files and make it possible for the loop to practically go on forever. Any ideas?

Photoshop jsx image grid

What I am ultimately trying to do is to create a grid of images for print that are minor variations of the same thing (different text is all). Looking through online resources I was able to create a script that changes the text and exports all of the images necessary (several hundred). What I am trying to do now is to import all of these images into a new photoshop document and lay them all out in a grid and I can't seem to find any examples of this.
Can anyone point me in the right direction to place a file at a specific coordinate (I'm using CS5 and have the design suite so if there is a way in illustrator to do this quickly...)?
Also, I'm open to other ideas on how to do this (even other programs) easily. It's for labels so the positioning on the sheet has to be pretty precise...
The art layer object has a translate() method that takes delta x and y params. You'll need to open each image, copy it to the target document, get its current location (using artLayer.bounds) and do the math to find the deltas to position it where you want it. Your deltas can be in pixels so you'll get plenty of precision.
Check out your 'JavaScript Scripting Reference' pdf in your Adobe install directory for more details.
Ok I'm marking Anna's response as the answer because though I didn't fully test it, it seems like it should work and answers the original question with jsx. However I'm also leaving my final solution in case anyone else runs across this with the same issue and may prefer this method as well.
What I ended up doing instead is using InDesign. I figured out that it has a grid option that lets you import a number of files and place them all in an equal grid in a single command. This is almost exactly what I was looking for, except that it leaves a small border/margin in between the columns and grids and mine were designed to meet exactly.
I couldn't figure out how to make it not have the border (I have very little experience with InDesign, it may be possible). However I was able to select all my images and scale them uniformly to be the correct size, then I just selected each column and dragged it over to snap to the adjacent column and the same with rows...