CategoryPython

Maximum Memory by Windows Services Configuration (BlackViper Settings)

There are a lot of tips and tricks on how to optimize your system memory. One of the main ways to get the most out of your system is to configure the “Windows Services”, essentially tasks and programs that windows starts and stops in the background. These services are needed by other programs, changing this configuration can result in that some programs cannot start or behave in a strange manner. If you mess around with the services, you could disable your access to the internet and its a pain to figure out which service you accidentally stopped that should have been running.

There are only two situations in which you should configure the services

  1. You are desperate and want to optimize a very old pc without having to buy new ram
  2. You are a gamer and want the speediest most lightweight computer

Service Configurations

Fortunately smart people have already played around with various configurations. BlackViper provides on his website a list of “tweaked”, “safe” and “default” settings. However the table on his website is interesting, but not very useful. If you would want to apply these settings you would have to open up “services.msc” and apply each setting manually.

Thankfully I found a way to convert the table into a powershell script.

  1. Head over to his site  http://www.blackviper.com/service-configurations/
  2. Go to your Version of Windows
  3. Use the websites Copy function and save the tap separated table into a textfile
  4. Execute following python code in the same folder

Alternatively you can download the resulting Powershell Scripts for Windows7SP1:  Win7SP1 – BlackViperPowerShell

Note: During the execution of the script errors appear for services that are not installed on your system – just ignore them.

Results

To consistently measure the memory usage I did a clean install of Win 7SP1 on a VirtualBox.

  • Default  39 Processes using  600MB Ram
  • “Safe Configuration”:  29 Processes using 500MB.

While the safe configuration ‘saves’ you 100MB of Memory. The amount of effort of testing if all your programs are still running correctly etc. Does not make a lot of sense – especially when typically you are anyway have 8GB+ RAM in Computers these days.

Image:

Google App Engine: Import CSV to Datastore

Processing CSV Data with the Google App Engine is a two step process.
First you need to upload the data and store it in the blobstore.
Then you retrieve the file and process the information and save it to the Datastore(Database).
You can process the csv data with the standard python tools from the csv module, however instead of parsing a file you must parse a BlobReader.

PySide: QPushbutton Text below Icon

Apparently using a QPushbutton with a Icon does not work. As alternative I am going to use a QToolbutton.

import sys
from PySide.QtCore import *
from PySide.QtGui import *

class Widget(QWidget):
    
    def __init__(self, parent= None):
        super(Widget, self).__init__()
        
        layout = QVBoxLayout(self)
        
        #QToolButton
        btn = QToolButton()
        btn.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        btn.setText("test")
        btn.setIcon(btn.style().standardIcon(QStyle.SP_DirIcon))
        btn.setIconSize(QSize(54,54))
        
        layout.addWidget(btn)
        
        self.setLayout(layout)
        
        
if __name__ == '__main__':
    app = QApplication(sys.argv)
    
    dialog = Widget()
    dialog.show()

    app.exec_()

PySide: QVBoxLayout with QScrollArea

Here is an example that adds Scrollbars to a QVBoxLayout. The one thing that tripped me up was that you need to explicitly create a Widget for the QScrollArea.

import sys
from PySide.QtCore import *
from PySide.QtGui import *

class Widget(QWidget):
    
    def __init__(self, parent= None):
        super(Widget, self).__init__()
        self.setFixedHeight(200)
        
        #Container Widget        
        widget = QWidget()
        #Layout of Container Widget
        layout = QVBoxLayout(self)
        for _ in range(20):
            btn = QPushButton("test")
            layout.addWidget(btn)
        widget.setLayout(layout)

        #Scroll Area Properties
        scroll = QScrollArea()
        scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
        scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        scroll.setWidgetResizable(False)
        scroll.setWidget(widget)
        
        #Scroll Area Layer add 
        vLayout = QVBoxLayout(self)
        vLayout.addWidget(scroll)
        self.setLayout(vLayout)
        
        
if __name__ == '__main__':
    app = QApplication(sys.argv)
    
    dialog = Widget()
    dialog.show()

    app.exec_()

PySide: QTreeListWidget deleting an Item, editing an Item

This example creates a QTreeListWidget to display a folder-structure.

import sys, os
from PySide.QtCore import *
from PySide.QtGui import *

class TreeTest(QTreeWidget):
    
    def __init__(self, parent = None):
        super(TreeTest, self).__init__(parent)
        self.setColumnCount(1)
        self.setHeaderLabel("Folders")
        
        actionEdit = QAction("New Folder", self)
        actionEdit.triggered.connect(self.addItemAction)
        self.setContextMenuPolicy(Qt.ActionsContextMenu)
        self.addAction(actionEdit)
        
        actionDelete = QAction("Delete", self)
        actionDelete.triggered.connect(self.deleteItem)
        self.addAction(actionDelete)
        
        self.style()
        
    def addItem(self, name, parent):
        self.expandItem(parent) 
        item = QTreeWidgetItem(parent)
        item.setText(0, name)
        #It is important to set the Flag Qt.ItemIsEditable
        item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsUserCheckable | Qt.ItemIsEnabled | Qt.ItemIsDragEnabled | Qt.ItemIsEditable)

        item.setIcon(0,self.style().standardIcon(QStyle.SP_DirIcon))
        return item
    
    def addItemAction(self):
        parent = self.currentItem()
        if parent is None:
            parent = self.invisibleRootItem()
        new_item = self.addItem("New Folder", parent)
        self.editItem(new_item)
    
    def deleteItem(self):
        root = self.invisibleRootItem()
        for item in self.selectedItems():
            (item.parent() or root).removeChild(item)
    
if __name__ == '__main__':
    app = QApplication(sys.argv)
    test = QWidget()
    treeWidget = TreeTest()
    layout = QHBoxLayout()
    layout.addWidget(treeWidget)
    
    test.setLayout(layout)
    test.show()
    
    treeWidget.addItem("top", treeWidget.invisibleRootItem())
    item = treeWidget.addItem("item", treeWidget.invisibleRootItem())
    treeWidget.addItem("subitem", item)
    
    app.exec_()

PySide: Using standard system Icons

You can add Icons to many types of QWidgets. PySide provides you with a method to access the native system icons.
A complete list of icons can be found here: PySide.QtGui.PySide.QtGui.QStyle.StandardPixmap

To apply the QIcon you need to

btn = QPushButton("Folder")
style = btn.style()
icon = style.standardIcon(QStyle.SP_DirIcon)
btn.setIcon(icon)
#or short:
btn.setIcon(btn.style().standardIcon(QStyle.SP_DirIcon))

Here a small example:

import sys
from PySide.QtCore import *
from PySide.QtGui import *

class Widget(QWidget):
    
    def __init__(self, parent= None):
        super(Widget, self).__init__()
        
        
        btn_folder = QPushButton("Folder")
        btn_folder.setIcon(self.style().standardIcon(QStyle.SP_DirIcon))
        
        btn_one = QPushButton("Play")
        btn_one.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay))
        
        btn_two = QPushButton("Stop")
        btn_two.setIcon(self.style().standardIcon(QStyle.SP_MediaStop))
        
        btn_three = QPushButton("Pause")
        btn_three.setIcon(self.style().standardIcon(QStyle.SP_MediaPause))
        
        layout = QHBoxLayout()
        layout.addWidget(btn_folder)
        layout.addWidget(btn_one)
        layout.addWidget(btn_two)
        layout.addWidget(btn_three)
        
        self.setLayout(layout)
        
if __name__ == '__main__':
    app = QApplication(sys.argv)
    
    dialog = Widget()
    dialog.show()

    app.exec_()

© 2017 Neal Bürger

Theme by Anders NorénUp ↑