PyQt4: example of TableWidget usage

The following simple example (inspired by saltycrane example shows how to build a simple application that pops up a table with PyQt4 and its TableWidget class.

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
 
data = {'col1':['1','2','3'], 'col2':['4','5','6'], 'col3':['7','8','9']}
 
class MyTable(QTableWidget):
    def __init__(self, data, *args):
        QTableWidget.__init__(self, *args)
        self.data = data
        self.setmydata()
        self.resizeColumnsToContents()
        self.resizeRowsToContents()
 
    def setmydata(self):
 
        horHeaders = []
        for n, key in enumerate(sorted(self.data.keys())):
            horHeaders.append(key)
            for m, item in enumerate(self.data[key]):
                newitem = QTableWidgetItem(item)
                self.setItem(m, n, newitem)
        self.setHorizontalHeaderLabels(horHeaders)
 
def main(args):
    app = QApplication(args)
    table = MyTable(data, 5, 3)
    table.show()
    sys.exit(app.exec_())
 
if __name__=="__main__":
    main(sys.argv)
Posted in Python | Tagged , , | 3 Comments

proper CSS style for HTML table

When using table in HTML, you should use CSS style. Indeed, the old way that consists of setting attributes within the table (and td/tr/th) tag is deprecated.

Therefore this old code

<table width="400" border="3" cellpadding="5" cellspacing="2">
    <tr bgcolor="#DDDDDD">
        <td width="100" align="left"><b>Some text</b></td>
        <td align="right">some data</td>
    </tr>
 </table>

should be replaced by

<table id="download">
<tr>
  <td class="leftcol">Some text  </td>
  <td >Some data  </td>
</tr>
</table>

Where a CSS file would contain the information related to the id download and the class leftcol:

table#download {
    background-color:#FFFFFF;
    border: solid #000 3px;
 }
 table#download td {
    padding: 5px;
    border: solid #000 1px;
 }
 
.leftcol {
    font-weight: bold;
    text-align: left;
    background-color: #bfbfbf;
 }
Posted in Computer Science | Tagged | Leave a comment

Running SSH commands (remotely)

Consider a login on ta Host machine. To run a command (let us try a simple ls to list the current directory), just type:

ssh -X login@IPhostMachine ls

In practice, commands are longer and you would rather use double quotes around the command(s)

ssh -X login@IPhostMachine "cd temp; ls"

SSH logs you in the home directory (e.g., /home/login).

Then, you can type most of the unix commands. You need to be careful with single and double quotes.

Note also that to run a command in the background, you need this kind of syntax:

    ssh login@host "nohup myprogram > foo.out 2> foo.err < /dev/null &"

This simple one may not work:

    ssh login@host "myprogram &"

Indeed, backgrounded job can cause the shell to hang on logout.

Posted in Linux | Tagged | 1 Comment

RPM usage

In order to check which version of a RPM package is installed, type (e.g., for the motif package):

rpm -qa | egrep 'motif'
Posted in Linux | Tagged | Leave a comment

HTML: how to include another HTML file

To include another HTML document within a n HTML document, use this command:

<! --#include virtual="temp.xml"-->

the main HTML file should have a shtml extension.

Posted in Computer Science | Tagged | Leave a comment

Differences between Class and ID in CSS style

The key thing is that an ID identifies a specific element within a page and
therefore must be unique.

Classes mark elements as members of a group and can be used multiple times.

So why not always using Class over ID ? One of the main
reason may be related to javascript that intensively uses ID such as in the
function getElementById().

Another reason is that an element may have both a class and an ID

    <div class="tab" id="tab1">  Tab 1 </div>
    <div class="tab" id="tab2">  Tab 2 </div>;

Then in your CSS you can do::

    div.tab { background-color: #F00; }
    div#tab1 { text-decoration: none; }
Posted in Computer Science | Tagged , | Leave a comment

stty command and prompt issue

Under Linux, the sheel command (or prompt) may behave strangly after some unusual command. I do not have any example off hand but typically, the escape key will not work anymore, or special characters. In the worst case what you type does not appear at all.

A useful trick under linux is to use

stty sane
Posted in Linux | Leave a comment

Photos from Devon, UK

[coolEye search=Devon2011 how=album puser=cokelaer width=500 height=500 source=picasa]

Posted in photos | Leave a comment

How to add adsense in wordpress

In order to incorporate ads from adsense into your wordpress blog, you can use/install a dedicated plugin that will manage your adsense ID for you. However, you can also do it yourself, which may be more robust on the long term. Here are the different steps to follow:

  • Login to your blog as administrator
  • Step 2: Click on Appearance
  • Step 3: Select Widgets
  • Step 4: Select Text widget from the left and drag it into the the sidebar on the right
  • Step 6: Edit the text widget you’ve just created
  • Step 7: Enter a Caption.
  • Step 8: Paste the Google Adsense code in the text area (see example of adsense code below)

Example (Copy and Paste below into Widget):

<script type="text/javascript">
 <!--
 google_ad_client = "pub-9999999999999999";
 google_ad_slot = "9999999999";
 google_ad_width = 200;
 google_ad_height = 200;
 // --></script>
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js"type="text/javascript"></script>
Posted in wordpress | Tagged | Leave a comment

FEDORA: ec-incosolata font missing

Being developer of some R packages, I have to convert some R manual file using pdflatex. Under FEDORA, the conversion seems to work but some fonts are missing. It was not easy to figure out how to fix this issue. The missing font was ec-inconsolata. This font can be installed via yumex, however, pdflatex could not find it.

Trying this command for instance raise an error:

mktexpk --mfmode / --bdpi 600 --mag 0+540/600 --dpi 540 ec-inconsolata

I could not find anything in the list of packages that solve that issue. Under ubunti it is advice to install texlive-fonts-extra ut I could not found this pacakge in yumex. Finally, I found this page: http://fedoraproject.org/wiki/Features/TeXLive and follow the intructions on how to install a new texlive repository and it solved my problem:

Being under Fedora 15, I typed:

sudo rpm -i http://jnovy.fedorapeople.org/texlive/2012/packages.fc15/texlive-release.noarch.rpm
yum clean all
yum install texlive # if not already installed.
yum update

Finally, you need to install the fonts is not already done:

yum install texlive-inconsolata, texlive-inconsolata-font

For Fedora 17

sudo rpm -i http://jnovy.fedorapeople.org/texlive/2012/packages.fc17/texlive-release.noarch.rpm
yum clean all
yum install texlive # if not already installed.
yum update
yum install tex-inconsolata, tex-inconsolata-font

yum install texlive-inconsolata, texlive-inconsolata-font

Posted in Linux | Tagged , | 1 Comment