Kruptein 15 Posting Whiz in Training

I would instead of using seperate variables for the different materials, use a dictionary

#-*- coding: cp1252 -*-
substances = {
'aluminium':0.000023,
'concrete':0.000012,
'silver':0.000019,
'gold':0.000014,
'copper':0.000017,
'glass':0.000008,
}

a = raw_input("enter substance: ")
l = float(raw_input("give original length: "))
t = float(raw_input("how much the temperature changes: "))

answer = substances[a]*l*t
print answer

be aware that it will be case sensitive and Aluminium won't be recognised whereas aluminium is

vegaseat commented: helpful +15
Kruptein 15 Posting Whiz in Training

the correct statement is:

SELECT a, b, sum(a + b) from table1

sum is an existing method that returns the sum of the passed items

Kruptein 15 Posting Whiz in Training

First: if you get an error it's always helpfull if you give the error
in this case the error can be the fact that you forgot a space between FROM and *

Kruptein 15 Posting Whiz in Training

Hm, your model is regarded as a long instead of a model, can you paste the views.py or full shell code you are trying to execute?

Kruptein 15 Posting Whiz in Training

Hey I've released the first alpha of a project of me called Minimal-D
It's meant to combine at least 3-development aspects:
-text-editing
-file browsing
-ftp uploading/downloading
(-sql)

I combine these three in a simple,lightweight and small program and I want to know what you think about it...

You can see the pictures here: http://kruptology.blogspot.com/2010/09/minimal-d-02.html

Kruptein 15 Posting Whiz in Training

Hey,

I've been not so active for the past months, but that's because I was working on a litle project called Deditor. It's a text-editor for linux. The thing that makes it special is that it is made for python and thus has some python-specific features like, syntax-highlighting, interactive interpreter, code analyzing, tool to run your code, ...
It offers the features an other text-editor also gives.

I've finished version 0.2 and wants to know whether it is good or not.
you can download a deb or a tarbal from my launchpad page

Kruptein 15 Posting Whiz in Training

I assume you use wxPython because it's python and not c++(=wxWidgets)

Add this to the set_properties function

_icon = wx.EmptyIcon()
_icon.CopyFromBitmap(wx.Bitmap("./logo.gif", wx.BITMAP_TYPE_ANY))
self.SetIcon(_icon)
Kruptein 15 Posting Whiz in Training

That means that you will have to either skip learning pygame,
or install Python 2.6 (I use it personally,
I mean IronPython's latest version is 2.6!), and use it instead.
Of course Python 2.6 is NOT outdated or obsolete, as they still update it frequently with bugfixes.

The same here

Kruptein 15 Posting Whiz in Training

Okay was the answer griswolf gave not sufficiant? or didn't you understand what he said

http://www.daniweb.com/forums/thread286224.html

Kruptein 15 Posting Whiz in Training

Sorry think I misread your post and you saw something from the past.
The first-first version of d-cm was written using wx-glade indeed, but because of the way d-cm works I had to modify a lot of code and so I didn't use wx-glade anymore for later releases. You probably saw some comment in a file where it still said something about wxglade, but I can guarantee you that I don't because of the complexity of the program :)

Kruptein 15 Posting Whiz in Training

Xp i get the same as tony.
Win-7 the same.
Ubuntu it work,diden`t test it to much.
Virtualbox it`s easy to switch between more OS for testing.

I would not use a gui-toolkit for something large.
Because i think i have more control(eaiser to test) building from botton,but if you are comfortable with wx-glade then i guess it`s ok for you.

I didn't think about that yet, will try the virtualbox definitely, building a gui from bottom, well I think that's just one step to far for me. But maybe when the project get's "successful", I will do that

Kruptein 15 Posting Whiz in Training

This is my result trying to open the program in IDLE in WindowsXP.

I already was afraid that windows would crash. With a previous release I made 2 different versions. But because this one is brand new I wasn't able to port it to windows. It has to do with some differences in the wx package for windows and the one for linux...

but thanks that you tried it

Kruptein 15 Posting Whiz in Training

I'm looking for people to test a program, I've just finished the rewrite of a program and I need people to test for bugs etc...

It's a program for developers written in python and wxpython-gui-toolkit
It's made with the aim on linux, although windows-testers are welcome as well

link: http://launchpad.net/d-cm
Please tell me if it works..

Kruptein 15 Posting Whiz in Training

matador >> Spain

Kruptein 15 Posting Whiz in Training

Yogi Bear ----> Teddy (Mr. Bean)

Didn't you notice that you just skipped more then 760 pages o.O ?

Kruptein 15 Posting Whiz in Training

I have this wx.ListCtrl and I want to get the "Variable" name and the "Value" name, but I can only get the "Variable" name, how to get the second?

def __init__(...):
    ...
    self.list_ctrl_1.InsertColumn(0, 'Variable')
    self.list_ctrl_1.InsertColumn(1, 'Value')
    self.list_ctrl_1.SetColumnWidth(0, 200)
    self.list_ctrl_1.SetColumnWidth(1, 200)
    for item in ls:
        self.list_ctrl_1.Append((item[0],item[1]))
    self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.dclick)

def dclick(self, event):
    print event.GetLabel() #I get the first column item, how do I get the second?
Kruptein 15 Posting Whiz in Training

Well like the title says, everything was alined fine, untill I added the Shell, it's the shell I want to resize, but if I pass wx.Size(100,100) of self.console.SetSize((100,100)), it doesn't work :f What am I doing wrong?

class DEDITOR(wx.Frame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: DEDITOR.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.filepath = wx.TextCtrl(self, -1, "")
        self.dce = DemoCodeEditor(self)
        #self.console=wx.TextCtrl(self, -1, style=wx.TE_MULTILINE)
        self.console = Shell(self)
        self.console.interp.locals = {}
        
        self.__set_properties()
        self.__do_layout()
        # end wxGlade

    def __set_properties(self):
        # begin wxGlade: DEDITOR.__set_properties
        self.SetTitle("DEDITOR")
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: DEDITOR.__do_layout
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        sizer_2 = wx.BoxSizer(wx.VERTICAL)
        sizer_2.Add(self.filepath, 0, wx.EXPAND, 0)
        sizer_2.Add(self.dce, 1, wx.EXPAND, 0)
        sizer_2.Add(self.console,2)
        sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
        self.SetSizer(sizer_1)
        sizer_1.Fit(self)
        self.Layout()
        self.SetSize((500, 600))
Kruptein 15 Posting Whiz in Training

Okay, what is the equivalent of ListBox.Append(item) for HtmlListBox?
I can't find it in the api reference

Kruptein 15 Posting Whiz in Training

Well with the listctrl it indeed works, but I like the listbox more in this case,
and I want to change the text colour from some items...
is that included in the demo? O.o?

Kruptein 15 Posting Whiz in Training

Excuse me but what do you mean with tagging?

Kruptein 15 Posting Whiz in Training

Well that is not what I want to do..
I want to colour a single item...

(I just see I made a typo it had to be SetItemForegroundColour)

Kruptein 15 Posting Whiz in Training

somehow this does not work: self.list_box_1.SetForegroundColour(5,"red") SetForegroundColour is though listed in the api reference

Kruptein 15 Posting Whiz in Training

Hey,

I've made a program called d-cm, it's a web-development tool.
I want to know if everything works and/or if it works on windows too.

Therefore I'm asking if some people are willing to test it...
googlecode project link

P.S. I'm posting it here because in the Show off your project their seems to be no activity

Kruptein 15 Posting Whiz in Training

Well the error code says:
you can not append a number to a string.
you can't do "hello"+5
you can though do [int(site):int(site)+6] this ofcourse assumes that site is a number..

Kruptein 15 Posting Whiz in Training

This is really odd, their happens something with the newlines which I can't get
an example:
I type:

x==False:
d

and I printed operatorless each time:

darragh@kruptools:~/d-cm/trunk$ ./deditor.py
[u'x']
[u'x', '=']
[u'x', '=', u'F']
[u'x', '=', u'Fa']
[u'x', '=', u'Fal']
[u'x', '=', u'False']
[u'x', '=', u'False']
[u'x', '=', u'False', ':']
[u'x=False:', '\n']
[u'x=False:', '\n', u'd']

So from the moment I press the enter, the x=False isn't split anymore...
what is the reason for this?

P.S.: With snippsat's solution it's just the same...

Kruptein 15 Posting Whiz in Training

Okay my syntax highlighter works very well, I only have on problem,
Sometimes GetWords() adds "\n" to operatorless although there isn't pressed an enter

I think the problem is within the GetWords() function, but I give all functions to be sure..

Main function is OnKeyUp,
colorize prints the text colored or not
getWords fetches all the words and puts them in a list

def OnKeyDown(self, event):
        keycode = event.GetKeyCode()
        controls=[wx.WXK_CONTROL,wx.WXK_ALT,wx.WXK_SHIFT]
        if keycode in controls:
            pass
        else:
            insp=self.text_ctrl_1.GetInsertionPoint()
            words=self.getWords(self.text_ctrl_1.GetValue())
            self.text_ctrl_1.SetValue("")
            wordcount=0
            print words
            for word in words:
                self.colorize(word,wordcount)
                wordcount+=1
            self.text_ctrl_1.SetInsertionPoint(insp)
        event.Skip()
        
    def colorize(self,word,wordcount):
        '''If the word is found in the syntaxlist color it, if not, return black'''
        hl=[["in","green"],["if","green"],["False","brown"],["for","green"],["self","yellow"],["elif","green"],["=","red"]]  #syntax list
        colorize=False  
        prev="" #previous words processed
        for lh in hl:
            if lh[0]==word:
                self.text_ctrl_1.BeginTextColour(lh[1])
                self.text_ctrl_1.WriteText(word)
                self.text_ctrl_1.EndTextColour()
                colorize=True
        if not colorize:
            self.text_ctrl_1.BeginTextColour("black")
            self.text_ctrl_1.WriteText(word)
            self.text_ctrl_1.EndTextColour()
    
    def getWords(self,wordlist):
        '''returns a list with all words,operators,spaces
        f.e.: "if x==5" returns ["if"," ","x","==","5"]'''
        spaceles=wordlist.split(" ")
        i=0
        spaceless=[]
        for word in spaceles:
            if i!=0:
                spaceless.append(" ")
            spaceless.append(word)
            i+=1
        operators=["\n","==","!=","<>","+","-","/","*",">=","<=","=<","=>",">","<",".","="]
        operatorless=[]
        for x in spaceless:
            opfound=False
            for operator in operators:
                if x.split(operator)[0]==x:
                    pass
                elif not opfound:
                    opfound=True
                    operatorless.append(x.split(operator)[0])
                    operatorless.append(operator)
                    operatorless.append(x.split(operator)[1])
            if not opfound:
                operatorless.append(x)
        return operatorless
Kruptein 15 Posting Whiz in Training

Okay nevermind, the people on the python irc, where able to help me...

Kruptein 15 Posting Whiz in Training

I think it might be this:

'<p>
 
<center>
{
 
if($_POST['Submit']){

php thinks the first ' of the $_POST is the closing ' from = '<p>
I do though not see what could be the closing ' for the $getpage

I think you forgot to do $getpage='<p>'

Kruptein 15 Posting Whiz in Training

I'm working on an addon system for one of my projects.
I'm able to add a new menu item, but the self.Bind(...) is causing me troubles

instead of bind the function to the menu-item, it just calls the function. and doesn't bind at all... :s

self.ID_OPEN=wx.NewId()
wxglade_tmp_menu.Append(self.ID_OPEN, eval(menucontent)[i][0], "", eval("wx.ITEM_"+eval(menucontent)[i][1]))
exec("import "+add+"."+imprts)
self.Bind(wx.EVT_MENU, eval(add+"."+imprts+"."+str(eval(menucontent)[i][2])), id=self.ID_OPEN)

with an example input:

self.ID_OPEN=wx.NewId()
wxglade_tmp_menu.Append(self.ID_OPEN, "DJANGO", "", wx.ITEM_NORMAL))
exec("import DGO.imports")
self.Bind(wx.EVT_MENU, DGO.imports.dgo(), id=self.ID_OPEN)

I really don't know why this calls the dgo() function direct on startup and not when I click on the menu-item

Kruptein 15 Posting Whiz in Training

Thanks a lot! that's exactly what I neede :)

Kruptein 15 Posting Whiz in Training

The SetValue() and GetValue() are to complicated, but it should work with WriteText()... although this always prints a newline if I press the space button...?

def OnKeyDown(self, event):
        insp=self.text_ctrl_1.GetInsertionPoint()
        words=self.text_ctrl_1.GetValue().split(" ") #get all the words
        hl=[["in","red"]]  #syntax list All words=in should become red
        prev="" #previous words processed
        wordcount=0
        for word in words:
            for lh in hl:
                if lh[0]==word:  #if word=="in"
                    if wordcount>0:  #if word is not first word
                        self.text_ctrl_1.BeginTextColour('red')
                        self.text_ctrl_1.WriteText(word)  #print "in" in red
                        self.text_ctrl_1.EndTextColour()
                        prev+=" "+word
                    elif wordcount==0:  #if word is first word (You can Ignore this part)
                        self.text_ctrl_1.SetValue("")
                        self.text_ctrl_1.BeginTextColour('red')
                        self.text_ctrl_1.WriteText(word)  #print "in" in red
                        self.text_ctrl_1.EndTextColour()
                        prev=word
                else:  #if word!="in"
                    if wordcount>0: #if word is not first word
                        self.text_ctrl_1.BeginTextColour('black')
                        self.text_ctrl_1.WriteText(word) #print word
                        self.text_ctrl_1.EndTextColour()
                        prev+=" "+word
                    elif wordcount==0: #if word is first word
                        self.text_ctrl_1.SetValue("")
                        self.text_ctrl_1.BeginTextColour('black')
                        self.text_ctrl_1.WriteText(word) #print word
                        self.text_ctrl_1.EndTextColour()
                        prev=word
            wordcount+=1
        self.text_ctrl_1.SetInsertionPoint(insp)
        event.Skip()
Kruptein 15 Posting Whiz in Training

Bull >> Red Bull

Kruptein 15 Posting Whiz in Training

This is the current function, I have commented the things that could be not clear (although I think everything should be)

The problem is that if I press a sentence , space , in
from the moment I press the n from "in", the "in" becomes red for a second and gets cut out of the sentence and is being replaced in front of the sentence..
so: test in -> intest

My question is, why is the in replaced? if I use other words, the spaces are correct

def OnKeyUp(self, event):
        insp=self.text_ctrl_1.GetInsertionPoint()
        words=self.text_ctrl_1.GetValue().split(" ") #get all the words
        hl=[["in","red"]]  #syntax list All words=in should become red
        prev="" #previous words processed
        wordcount=0
        for word in words:
            for lh in hl:
                if lh[0]==word:  #if word=="in"
                    if wordcount>0:  #if word is not first word
                        self.text_ctrl_1.SetValue(prev+" ")   #print all previous text
                        self.text_ctrl_1.BeginTextColour('red')
                        self.text_ctrl_1.WriteText(word)  #print "in" in red
                        self.text_ctrl_1.EndTextColour()
                        prev+=" "+word
                    elif wordcount==0:  #if word is first word (You can Ignore this part)
                        self.text_ctrl_1.SetValue(word)
                        prev=word
                else:  #if word!="in"
                    if wordcount>0: #if word is not first word
                        self.text_ctrl_1.SetValue(prev+" "+word) #print all previous words + space + word
                        prev+=" "+word
                    elif wordcount==0: #if word is first word
                        self.text_ctrl_1.SetValue(word) #print word
                        prev=word
            wordcount+=1
        self.text_ctrl_1.SetInsertionPoint(insp)
        event.Skip()
Kruptein 15 Posting Whiz in Training

Uhu that's possible,
but is it possible to do something like this:

wxglade_tmp_menu.Append("str", "&Open", "", wx.ITEM_NORMAL)
                self.menubar.Append(wxglade_tmp_menu, menutitle)
                self.Bind(wx.EVT_MENU, self.ttt, "str")

I want to give a variable name instead of an id... is that somehow possible?
cause the example does not work :p

Kruptein 15 Posting Whiz in Training

Milk >> Cow

Kruptein 15 Posting Whiz in Training

Happy >> cookies (with a smile)

Kruptein 15 Posting Whiz in Training

mistake >> LoL

Kruptein 15 Posting Whiz in Training

want

Kruptein 15 Posting Whiz in Training

I'm working on an add-on system, which is till now going pretty good.
no I need to assign an id to a menu item, but I don't know which are all in use (by other addons f.e.) so is there a way to either:
-get a random integer that isn't used as id yet
-get a list with integers that is already used as id

(the first would be better though)...

Kruptein 15 Posting Whiz in Training

What you are trying to do is called syntax highlighting.

That's indeed what I want to do...

Nah that is very very simple. See you get the text with the GetValue() method. If you look at the link i posted you will see that on that page it shows that the return value for the GetValue() function is a string.. sounds like what you want eh?

Next, you can give that string to any function you like, thats obvious to do.

And to put it onto the richtextctrl you will need another method, now logically think, if there was a GetValue() method, then there is probably a SetValue( value ) method, and voila! There is. All you need to do is give the method an argument of the string that you want to set the value to and you are done.

Hope that helps

lol, thanks for your help, but I already knew about the Get and Set things, I have used wxPython for a while now.

The only thing I was not sure about was if this was a good way or not.

Kruptein 15 Posting Whiz in Training

Well what I would do now is:
-on key down event: capture all text in richtextCtrl
-pass that to a function
-re-output it,
this will take though long when you have a large file :s

Is this totally the wrong way?
or am I on a good track?

Kruptein 15 Posting Whiz in Training

You can do all of that with standard Python code.

Thanks to point that out, but could you also say how?

Kruptein 15 Posting Whiz in Training

Well I already found that code snippet ;),
my problem is that I don't know what will be entered,
in your case you chose to print "you are in danger"
in my case the text depends on the user,
that's why I want to catch the input before it's outputted...

Kruptein 15 Posting Whiz in Training

Is there a way to catch the text a user types, then do some function on it and then return it to the screen?

input(text) -> function(text) -> output(text)

I want to colourize certain words, so I want the function to find those words and then colorize them..

Kruptein 15 Posting Whiz in Training

I want to fetch a page from a website, which isn't hard at all.
But to view that page you have to be logged in (I do have an account on the site). How can I log me in and then fetch the correct page?
I thought something with session_id's but I'm not sure

Kruptein 15 Posting Whiz in Training

Thanks Man , really appreciated !!

You're welcome =)

Kruptein 15 Posting Whiz in Training
if countLost == games:
            print com
            raw_input("Press Enter to exit")
            resetScores(countWin, countLost, games)
        raw_input("\n\tPress Enter to continue\n\n\n\n")

If I pressed enter with the last raw_input, nothing would have happened because their is no other command after that one.

Kruptein 15 Posting Whiz in Training

You should keep one integer trough the main loop that keeps counting till the person quits. and another integer that only adds up if the user gives a correct answer.

total=0
wins=0
main():
    ...
    total+=1
    if user wins:
        wins+=1

something like that, to see if the player wants to quit you can ask on the end of each addition, raw_input("Do you want to stop(y/n)") You get the point?

BTW: Please use code tags, from now on,it's much easier to read..

Kruptein 15 Posting Whiz in Training

Okay I followed snippsat his example and changed some things to see if I understand, and I do. (Scru's link is a good reference but to learn from it's quite heard)

I know how to colorize the text and I think I'm even capable of Syntax-highlighting a certain text. However I don't know how to colorize a text when it's been typed, cause that's how a text-editor works. you can add content which is also being colorised

somebody knows how I can capture what the user types before it is being passed to the screen?

Kruptein 15 Posting Whiz in Training

Well Syntax-highlighting actually, but in the past I had already found the wx.StyledTextCtrl but I didn't found any real documentation on how to use it :s
you know a source perhaps?