Page 7 of 10

Aptana / Eclipse: Set up Git Repository (Github, Bitbucket)

If you code for yourself or with a team you should be using a code repository. However getting started you need a dedicated server, installation etc. or you take the more convenient route and use one of the many repository providers.

Step 1: Get a Repository

For small teams you can get free Repositories. The two most popular providers are:

  • Github.com: Allows you to host as many open source projects as you like. (private projects cost a monthly fee)
  • Bitbucket.com: Allows a small team to host private projects. (As the team gets bigger you got to pay a monthly fee)

Larger teams, hopefully have the budget to pay for these awesome services.

Step 2: Set up your SSH key

Eclipse and Aptana Studio have Git already integrated. Git uses an encrypted connection to transmit data. You need to provide a SSH keypair.

Check for existing SSH keys

  1. Go to the directory “C:\Users\<username>\.ssh”
  2. Check if the files “id_rsa” and “id_rsa.pub” exist

Generate new SSH keys

If the two files already exist, you can skip this step.

  1. Open git-bash.bat (either by using windows search or navigate to C:\Users\%USRNAME%\Documents\Aptana Studio 3 Workspace\.metadata\.plugins\com.aptana.portablegit.win32\git-bash.bat)
  2. Enter the following command using your correct email-address.
    ssh-keygen -t rsa -C "name@email.com"
  3. For the first question, just press enter.
    Generating public/private rsa key pair.
    # Enter file in which to save the key (/c/Users/you/.ssh/id_rsa):
    
  4. Now enter a passphrase for your key (Password Generator) and confirm the password

Add SSH key to Repository

  1. Go to the directory “C:\Users\<username>\.ssh”
  2. Open the file ‘id_rsa.pub’ in a texteditor
  3. Copy the entire contents to the Clipboard (Ctrl-C)
  4. Open a web browser and login to github.com or bitbucket.com
    • (Github) Click on the “Edit my profile” button on the top right
    • (Bitbucket) Click on your Avatar > “Manage Account”
  5. On the left side navigate to “SSH Keys”
  6. Click “Add SSH key”
  7. Give the key a title (like username with the computer name) and paste the key into the form

Test Connection

  1. Open git-bash.bat
  2. Use the command
    • (Github) ssh git@github.com
    • (Bitbucket) ssh git@bitbucket.com

If everything went well you will get a message like:

Hi username! You’ve successfully authenticated, but GitHub does not provide shell access.

Note: At first I had difficulties to establish a connection. If you are having problems, check if the keys are in the right directory and have the proper names id_rsa and id_rsa.pub.

Source/Further information: Github – https://help.github.com/articles/generating-ssh-keys

Step 3: Set up Aptana/Eclipse

The initial setup is now complete you can now use Eclipse/Aptana to access your Repository.

New/Existing Project

To start using git create or use an existing project.

  1. In the Project Manager, Right-click on the project and select Team > Share Project…Screenshot - 11_19_2013 , 8_43_54 AM
  2. Select the Project, click Create and then Finish.Screenshot - 11_19_2013 , 8_45_51 AM

You now have a local git repository. You now can “Push” the repository to github/bitbucket.

  1. First create a Repository on the website and copy the address of the repository
  2. In the Project Manager, Right-click on the project and select Team > Remotes > Add RemoteScreenshot - 11_19_2013 , 8_52_00 AM
  3. Give the remote a name and paste the address of the repository
  4. Finally push your initial commit with Team > Push

Retrieve from Repository

If you already have a Project stored in your repository and want to retrieve it.

  1. Go to File > Import 
  2. Select Git > Git Repository as New ProjectScreenshot - 11_19_2013 , 8_31_50 AM
  3. Enter the URI of your repository:
    • (Github) git@github.com:<username>/<repository>
    • (Bitbucket) git@bitbucket.com:<username>/<repository>

Use your Repository

Here are some tips on using the repository (well they are based on my experience using SVN, but the same principles apply):

Commit as often as possible

The beauty of subversioning is that you can figure out step by step what parts of your code created the error. When working in a team, always make sure that the entire code is correct and valid and still be compiled/executed.

Write proper commit messages

Always comment what you are currently committing. It helps to rollback to a specific point, and it is a documentation of your work.

Regular updates

When working in a team regularly check that you have the newest version of the code available by doing a “Pull”.

Best Practices

A lot of experts have articles on how to use git effectively in a team. Read up on them and see if they are suitable for your team.  Check out this article about Git Best practices.

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_()

PySide: QMessageBox with QCheckBox

The QMessageBox is very useful for creating standard filesystem dialogs (it even comes with alert sounds) and is limited to display an icon, text and standard buttons. If you want to add something extra like a checkbox for “do not ask me again”, you need to extend the base class.

© 2017 Neal Bürger

Theme by Anders NorénUp ↑