This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
notes:projects:python [2010/02/20 01:59] – mcooper6 | notes:projects:python [2010/03/25 15:09] (current) – jcardina | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | <WRAP left 40%> | ||
+ | ~~TOC~~ | ||
+ | </ | ||
+ | // | ||
+ | // | ||
+ | <WRAP centeralign 90% bigger> | ||
+ | <WRAP bigger fgred> | ||
+ | <WRAP muchbigger> | ||
+ | Notes & Documentation | ||
+ | </ | ||
+ | <WRAP left 50%> | ||
+ | |||
+ | {{map>: | ||
+ | [[.python# | ||
+ | [[.python# | ||
+ | [[.python# | ||
+ | [[.python# | ||
+ | {{<map}} | ||
+ | |||
+ | </ | ||
+ | <WRAP clear></ | ||
+ | |||
+ | =====The Story===== | ||
+ | Small history: | ||
+ | * Python is an open source language which means anyone can edit it and anyone one can use it for free. | ||
+ | * Python is not named after the snake but after Monty Python, and has been around since 1992 i believe. | ||
+ | * Python is an easier language that is higher level which means that you can write a security system but not an operating system. | ||
+ | * Python is great for first time programmers but not so great for big programs that you would need C++ or C for. | ||
+ | |||
+ | =====Grammar===== | ||
+ | Backus–Naur Form (BNF)? | ||
+ | |||
+ | =====Learning===== | ||
+ | Python is arguably one of the easier programming languages to master. | ||
+ | |||
+ | ====Installing Python==== | ||
+ | First, Visit http:// | ||
+ | |||
+ | Once there, choose the installer of your liking. If you're taking this step, chances are pretty good that you're looking for the Windows Installer, since Python comes pre-installed on most Linux and Mac distributions. | ||
+ | |||
+ | At the time of writing, the most widely supported version of Python is 2.6.4. | ||
+ | |||
+ | Clicking the installer link at Python.org will present you with a prompt. Choose the option 'Save File'. You will then need to choose a directory where you would like to place the installer. Once the installer is downloaded, navigate to the folder where you placed the it and double click it. Click ' | ||
+ | |||
+ | Run the Installer: | ||
+ | |||
+ | * 1. Choose whether you'd like to install Python for all users, or just your own user account. Make your decision and click ' | ||
+ | |||
+ | * 2. Choose the Python working directory. This is the folder where the Python installer will unpack all its files. For Python version 2.6.4, this prompt will be pre-populated with ' | ||
+ | |||
+ | * 3. Choose your installation features. | ||
+ | * Default Features - install the interpreter proper, plus the core libraries | ||
+ | * Extensions - register extensions (.py, .pyc, etc) | ||
+ | * TclTk - install Tkinter, and IDLE | ||
+ | * Documentation - install documentation | ||
+ | * Tools - install the Tools/ directory | ||
+ | * Testsuite - install Lib/ | ||
+ | |||
+ | ** The Python installer has a button labeled ' | ||
+ | |||
+ | Choose your features and click ' | ||
+ | |||
+ | * 4. Read the thank you message, because someone thought it was important enough to write. | ||
+ | |||
+ | * 5. Click ' | ||
+ | |||
+ | After installation click your Windows Start button. | ||
+ | |||
+ | * IDLE | ||
+ | * Module Docs | ||
+ | * Python Command Line | ||
+ | * Python Manuals | ||
+ | * Uninstall Python | ||
+ | |||
+ | The ' | ||
+ | |||
+ | The ' | ||
+ | |||
+ | The Python Manuals are different from pydoc in that it provides more tutorials, API references, in depth docs on specific topics and other information regarding the Python language. The Python Manuals provide a local version of much of Python' | ||
+ | |||
+ | The Python command line tool is just that, a command line for interpreting Python statements. The Python interpreter can be invoked from the Windows command line, however this link in the Start menu provides a nice shortcut that doesn' | ||
+ | |||
+ | IDLE is Pyhton' | ||
+ | |||
+ | * [[http:// | ||
+ | |||
+ | ====Starting Python==== | ||
+ | |||
+ | Starting the Python interpreter on Windows is not quite as easy as with Unix, Linux, BSD or Mac OS. If you're using any of the Unix-y systems, simply type the word '' | ||
+ | |||
+ | <cli> | ||
+ | :~$ python | ||
+ | Python 2.4.4 (#2, Jan 24 2010, 11:19:18) | ||
+ | [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2 | ||
+ | Type " | ||
+ | >>> | ||
+ | </ | ||
+ | |||
+ | <WRAP info bgwhite> | ||
+ | To stop your Python interpreter on Linux, type ctrl+d | ||
+ | </ | ||
+ | |||
+ | From Windows however, you have to do a little more detective work to find the location of your interpreter. | ||
+ | ==Method One== | ||
+ | <cli> | ||
+ | C: | ||
+ | </ | ||
+ | With most flavors of Windows, you'll see something like the following: (where $USER is your user name on the system) | ||
+ | ==Method Two== | ||
+ | <cli> | ||
+ | C: | ||
+ | </ | ||
+ | |||
+ | This is known as the prompt. | ||
+ | |||
+ | <cli> | ||
+ | C: | ||
+ | ' | ||
+ | operable program or batch file. | ||
+ | </ | ||
+ | |||
+ | Didn't we just install it? Yes, but Windows just doesn' | ||
+ | |||
+ | <cli> | ||
+ | C: | ||
+ | </ | ||
+ | |||
+ | You should notice that your prompt looks a bit different. | ||
+ | |||
+ | <cli> | ||
+ | C:\> | ||
+ | </ | ||
+ | |||
+ | Now, from the root directory type '' | ||
+ | |||
+ | <cli> | ||
+ | C:\> cd Python26 | ||
+ | </ | ||
+ | <cli> | ||
+ | C: | ||
+ | Python 2.6.4 (r2.6.4.75708, | ||
+ | Type " | ||
+ | >>> | ||
+ | </ | ||
+ | <WRAP info bgwhite> | ||
+ | To stop your Python interpreter on Windows, type ctrl+Z+ENTER | ||
+ | </ | ||
+ | |||
+ | ====Beginning Python==== | ||
+ | For those who haven' | ||
+ | |||
+ | To get started: | ||
+ | First open your geany program and click new then click document then find python under file type. first type this... | ||
+ | |||
+ | ##Python is easy to learn | ||
+ | then press enter | ||
+ | now this | ||
+ | |||
+ | print "cscs is cool" | ||
+ | press enter again | ||
+ | you should have this | ||
+ | |||
+ | ##Python is easy to learn | ||
+ | |||
+ | print "cscs is cool!" | ||
+ | which will output this | ||
+ | |||
+ | "cscs is cool!" | ||
+ | |||
+ | the reason "## python is easy to learn" didn't show up is because it was behind the comment tag and the " | ||
+ | |||
+ | ---- | ||
+ | now you have praticed.... prepare to learn little more. | ||
+ | |||
+ | type as follows and try to understand what you have typed. | ||
+ | |||
+ | code: | ||
+ | |||
+ | ## variables | ||
+ | |||
+ | press enter than type in | ||
+ | |||
+ | code: | ||
+ | |||
+ | print " | ||
+ | |||
+ | enter again | ||
+ | |||
+ | code: | ||
+ | |||
+ | name = raw_input (" | ||
+ | |||
+ | " | ||
+ | raw_input means the user inputs after the text. | ||
+ | ("" | ||
+ | |||
+ | followed by | ||
+ | |||
+ | code: | ||
+ | |||
+ | print " | ||
+ | |||
+ | ", | ||
+ | |||
+ | or you could have put it like this | ||
+ | |||
+ | code: | ||
+ | |||
+ | print " | ||
+ | |||
+ | save compile then run and see if it works. | ||
+ | |||
+ | ---- | ||
+ | I m just going to give you the code for the speed then I will explain it afterwards. | ||
+ | |||
+ | code: | ||
+ | < | ||
+ | a = 0 | ||
+ | a = input (" | ||
+ | if a == 4: | ||
+ | print "you are a noob with python" | ||
+ | if a == 5: | ||
+ | print "you May understand some python" | ||
+ | if a > 5: | ||
+ | print "you are elite with python" | ||
+ | if a < 4: | ||
+ | print "you are elite with python" | ||
+ | </ | ||
+ | this is our next program it will tell you if it thinks your a noob/xpert with python, i think i spelled it wrong | ||
+ | |||
+ | if a == 4 | ||
+ | 4 is the month if is saying well if this is this or if this is not this then this does this. | ||
+ | you must indent to have a working program every thing that needs if for it to work must have an indention form if but things that do not depend on if to work correctly must not be indented. | ||
+ | a = 0 | ||
+ | a starts out as 0 and when you input it changes b to that number. and that all you need to have this program to work | ||
+ | |||
+ | remember......it save what it remembered...for example you type in a=1 and type in a it will show " | ||
+ | ---- | ||
+ | try it understand what it means.... | ||
+ | |||
+ | code: | ||
+ | < | ||
+ | a = 0 | ||
+ | print "press 1 for addition" | ||
+ | print "press 2 for subtraction" | ||
+ | print "press 3 for multiplication" | ||
+ | print "press 4 for divsion" | ||
+ | a = input (" | ||
+ | if a == 1: | ||
+ | n = input(" | ||
+ | b = input(" | ||
+ | y = n + b | ||
+ | print n, " | ||
+ | if a == 2: | ||
+ | n = input(" | ||
+ | b = input(" | ||
+ | y = n - b | ||
+ | print n, " | ||
+ | if a == 3: | ||
+ | n = input(" | ||
+ | b = input(" | ||
+ | y = n * b | ||
+ | print n, " | ||
+ | if a == 4: | ||
+ | n = input(" | ||
+ | b = input(" | ||
+ | y = n / b | ||
+ | print n, "/", | ||
+ | |||
+ | here is another one below | ||
+ | |||
+ | code: | ||
+ | |||
+ | print " | ||
+ | c = input (" | ||
+ | b = raw_input (" | ||
+ | a = input (" | ||
+ | p = " | ||
+ | r = " | ||
+ | t = " | ||
+ | y = "/" | ||
+ | if b == y: | ||
+ | print c, b, a, " | ||
+ | if b == t: | ||
+ | print c, b, a, " | ||
+ | if b == r: | ||
+ | print c, b, a, " | ||
+ | if b == p: | ||
+ | print c, b, a, " | ||
+ | |||
+ | computer equalvlents (another spelling error) | ||
+ | |||
+ | == means = to | ||
+ | <= greater than or = to | ||
+ | >= less than or = to | ||
+ | != not = to | ||
+ | < greater than | ||
+ | > less than | ||
+ | </ | ||
+ | ====Gui Programming with tkinter==== | ||
+ | The Tkinter module ("Tk interface" | ||
+ | Tkinter includes a number of Python modules. The two most important modules are the Tkinter module itself and a module called Tkconstants. The former automatically imports the latter so to use Tkinter, all you need to do is to import one module | ||
+ | \\ | ||
+ | so lets start this off first off you need your import statement in python to have access to Tkinter Functions | ||
+ | < | ||
+ | from Tkinter import * | ||
+ | </ | ||
+ | so here ill start off with the simple hello world program and then explain how it all works | ||
+ | < | ||
+ | from Tkinter import * | ||
+ | |||
+ | |||
+ | mainWindow = Tk() | ||
+ | |||
+ | w = Label(mainWindow, | ||
+ | w.pack() | ||
+ | |||
+ | mainWindow.mainloop() | ||
+ | |||
+ | </ | ||
+ | so ive explained the import lets move to the next line \\ | ||
+ | (mainWindow = Tk()) - this is the root widget you must have one obviously.. its the main window \\ | ||
+ | |||
+ | w = Label(mainWindow, | ||
+ | |||
+ | w.pack() - this tells our widget in this case the " | ||
+ | |||
+ | mainWindow.mainloop() - this gives controll over to Tkinter it starts the main loop this is when everything will actually happen you could say.. The event loop doesn' | ||
+ | |||
+ | \\ | ||
+ | Here is code to generate two buttons One button will print hello to the console the other button will add a label in the root window (main window) | ||
+ | < | ||
+ | #import Tk | ||
+ | from Tkinter import * | ||
+ | |||
+ | #create a function that the buttonOne can call on | ||
+ | def button1(): | ||
+ | print "Hello on console" | ||
+ | |||
+ | #create function for ButtonTwo to call on this one prints Label to window | ||
+ | def button2(): | ||
+ | w = Label(mainWindow, | ||
+ | w.pack() | ||
+ | |||
+ | #create main window | ||
+ | mainWindow = Tk() | ||
+ | |||
+ | #create button one. assign it to main window add text and add function to execute | ||
+ | buttonOne = Button(mainWindow, | ||
+ | buttonOne.pack() | ||
+ | |||
+ | |||
+ | buttonTwo = Button(mainWindow, | ||
+ | buttonTwo.pack() | ||
+ | |||
+ | mainWindow.mainloop() | ||
+ | |||
+ | </ | ||
+ | ok so as some of you may no ive been working on a keylogger.. ive actually been trying to construct the gui that would drive it heres my progress somthing to note im not trying to make it look all pretty yet as im just trying to sketch out the logic i have another version that has much more in it but i hit a brick wall with it.. | ||
+ | |||
+ | < | ||
+ | from Tkinter import * | ||
+ | import socket | ||
+ | |||
+ | password = ' | ||
+ | |||
+ | |||
+ | |||
+ | def pwdin(): | ||
+ | key = ent.get() | ||
+ | if key != password: | ||
+ | print 'Need to replace with window error or label error' | ||
+ | else: | ||
+ | pwdcheck.destroy() | ||
+ | instructions() | ||
+ | |||
+ | def instructions(): | ||
+ | greeting = Label(root, text = ' | ||
+ | greeting.pack() | ||
+ | connectButton.pack() | ||
+ | getLogButton.pack() | ||
+ | #################################################### | ||
+ | #Create Main Window | ||
+ | #Create Password Window | ||
+ | #Create label promt password text # | ||
+ | #Create Entry Box for password window backrnd white# | ||
+ | #Pack all three widgits | ||
+ | #################################################### | ||
+ | root = Tk() | ||
+ | pwdcheck = Toplevel() | ||
+ | passtxt = Label(pwdcheck, | ||
+ | ent = Entry(pwdcheck, | ||
+ | button = Button(pwdcheck, | ||
+ | ent.focus() | ||
+ | passtxt.pack() | ||
+ | ent.pack() | ||
+ | button.pack() | ||
+ | #################################################### | ||
+ | #here i am creating buttons for the root window | ||
+ | #they will not display untill the password is ture # | ||
+ | #if you look at the if statement the buttons below # | ||
+ | #get packed when the password is correct | ||
+ | #################################################### | ||
+ | connectButton = Button(root, | ||
+ | getLogButton = Button(root, | ||
+ | |||
+ | root.mainloop() | ||
+ | |||
+ | </ | ||
+ | Here is a bit more to add to the LOGGER_GUI | ||
+ | |||
+ | < | ||
+ | from Tkinter import * | ||
+ | import socket | ||
+ | |||
+ | password = ' | ||
+ | |||
+ | |||
+ | |||
+ | def pwdin(): | ||
+ | key = ent.get() | ||
+ | if key != password: | ||
+ | print 'Need to replace with window error or label error' | ||
+ | else: | ||
+ | pwdcheck.destroy() | ||
+ | instructions() | ||
+ | |||
+ | def instructions(): | ||
+ | greeting = Label(root, text = ' | ||
+ | greeting.pack() | ||
+ | connectButton.pack() | ||
+ | getLogButton.pack() | ||
+ | ##################################################### | ||
+ | #added this function to get ip address and port from# | ||
+ | #user to explain starting at line 1 # | ||
+ | #create new window assign it to ipAddrWindow | ||
+ | #create text label so user knows what to do # | ||
+ | #create entry for ip address | ||
+ | #text for port # | ||
+ | #entry box for port # | ||
+ | #create ok button giving it the command socket have # | ||
+ | #not created this function yet # | ||
+ | #pack everything so it shows up # | ||
+ | ##################################################### | ||
+ | def ip_grab(): | ||
+ | ipAddrWindow = Toplevel() | ||
+ | prompt = Label(ipAddrWindow, | ||
+ | iptext = Entry(ipAddrWindow, | ||
+ | portpromt = Label(ipAddrWindow, | ||
+ | porttext = Entry(ipAddrWindow, | ||
+ | okbut = Button(ipAddrWindow, | ||
+ | prompt.pack() | ||
+ | iptext.pack() | ||
+ | portpromt.pack() | ||
+ | porttext.pack() | ||
+ | okbut.pack() | ||
+ | | ||
+ | #################################################### | ||
+ | #Create Main Window | ||
+ | #Create Password Window | ||
+ | #Create label promt password text # | ||
+ | #Create Entry Box for password window backrnd white# | ||
+ | #Pack all three widgits | ||
+ | #################################################### | ||
+ | root = Tk() | ||
+ | pwdcheck = Toplevel() | ||
+ | passtxt = Label(pwdcheck, | ||
+ | ent = Entry(pwdcheck, | ||
+ | button = Button(pwdcheck, | ||
+ | ent.focus() | ||
+ | passtxt.pack() | ||
+ | ent.pack() | ||
+ | button.pack() | ||
+ | |||
+ | connectButton = Button(root, | ||
+ | getLogButton = Button(root, | ||
+ | root.mainloop() | ||
+ | |||
+ | </ | ||
+ | |||
+ | here is another version with a bit more added the socket function now i just need to figure out how come the ip variable is being read as a string.. | ||
+ | < | ||
+ | import socket | ||
+ | from Tkinter import * | ||
+ | password = ' | ||
+ | |||
+ | |||
+ | |||
+ | def pwdin(): | ||
+ | key = ent.get() | ||
+ | if key != password: | ||
+ | print 'Need to replace with window error or label error' | ||
+ | else: | ||
+ | pwdcheck.destroy() | ||
+ | instructions() | ||
+ | |||
+ | def instructions(): | ||
+ | greeting = Label(root, text = ' | ||
+ | greeting.pack() | ||
+ | connectButton.pack() | ||
+ | getLogButton.pack() | ||
+ | |||
+ | |||
+ | | ||
+ | ##################################################### | ||
+ | #added this function to get ip address and port from# | ||
+ | #user to explain starting at line 1 # | ||
+ | #create new window assign it to ipAddrWindow | ||
+ | #create text label so user knows what to do # | ||
+ | #create entry for ip address | ||
+ | #text for port # | ||
+ | #entry box for port # | ||
+ | #create ok button giving it the command socket have # | ||
+ | #not created this function yet # | ||
+ | #pack everything so it shows up # | ||
+ | ##################################################### | ||
+ | def ip_grab(): | ||
+ | global iptext | ||
+ | global porttext | ||
+ | global ipAddrWindow | ||
+ | | ||
+ | ipAddrWindow = Toplevel() | ||
+ | prompt = Label(ipAddrWindow, | ||
+ | iptext = Entry(ipAddrWindow, | ||
+ | portpromt = Label(ipAddrWindow, | ||
+ | porttext = Entry(ipAddrWindow, | ||
+ | okbut = Button(ipAddrWindow, | ||
+ | prompt.pack() | ||
+ | iptext.pack() | ||
+ | portpromt.pack() | ||
+ | porttext.pack() | ||
+ | okbut.pack() | ||
+ | | ||
+ | def socket(): | ||
+ | import socket | ||
+ | global ip, port, client_socket | ||
+ | ip = iptext.get() | ||
+ | port = porttext.get() | ||
+ | ipAddrWindow.destroy() | ||
+ | client_socket = socket.socket(socket.AF_INET, | ||
+ | client_socket.connect((ip, | ||
+ | | ||
+ | #################################################### | ||
+ | #Create Main Window | ||
+ | #Create Password Window | ||
+ | #Create label promt password text # | ||
+ | #Create Entry Box for password window backrnd white# | ||
+ | #Pack all three widgits | ||
+ | #################################################### | ||
+ | root = Tk() | ||
+ | pwdcheck = Toplevel() | ||
+ | passtxt = Label(pwdcheck, | ||
+ | ent = Entry(pwdcheck, | ||
+ | button = Button(pwdcheck, | ||
+ | ent.focus() | ||
+ | passtxt.pack() | ||
+ | ent.pack() | ||
+ | button.pack() | ||
+ | |||
+ | connectButton = Button(root, | ||
+ | getLogButton = Button(root, | ||
+ | root.mainloop() | ||
+ | </ | ||
+ | \\ | ||
+ | \\ | ||
+ | Ok so here is the same code.. ive come across some good points to mention first off | ||
+ | | ||
+ | -also after a long long long time reading and searching i figured out my problem with the socket function i was having issues with a string error on the client_socket.connect((ip, | ||
+ | -on top of all that i added a little window for an error msg if the password was input wrong.. that can be found in the pwdin function | ||
+ | -and then their are various changes to some of the windows different options to some of the widgets like i think i found the setup i want for the password window and widgets thinking about changing the root windows font though.. | ||
+ | | ||
+ | | ||
+ | -i would also like to see the get log button start to work Basically create another function that sends a flag to the server saying hey do this and then listens for the response or in this case file to be sent then read the file save to variable then write the file.. | ||
+ | | ||
+ | \\ | ||
+ | ok so here is the code will replace this version with a more commented version of same code shortly.. | ||
+ | < | ||
+ | import socket | ||
+ | from Tkinter import * | ||
+ | password = ' | ||
+ | |||
+ | def errorWindowKill(error_window): | ||
+ | error_window.destroy() | ||
+ | |||
+ | def pwdin(): | ||
+ | key = ent.get() | ||
+ | if key != password: | ||
+ | print 'Need to replace with window error or label error' | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | else: | ||
+ | pwdcheck.destroy() | ||
+ | instructions() | ||
+ | |||
+ | def instructions(): | ||
+ | greeting = Label(root, text = ' | ||
+ | greeting.pack() | ||
+ | connectButton.pack() | ||
+ | getLogButton.pack() | ||
+ | |||
+ | |||
+ | |||
+ | ##################################################### | ||
+ | #added this function to get ip address and port from# | ||
+ | #user to explain starting at line 1 # | ||
+ | #create new window assign it to ipAddrWindow | ||
+ | #create text label so user knows what to do # | ||
+ | #create entry for ip address | ||
+ | #text for port # | ||
+ | #entry box for port # | ||
+ | #create ok button giving it the command socket have # | ||
+ | #not created this function yet # | ||
+ | #pack everything so it shows up # | ||
+ | ##################################################### | ||
+ | def ip_grab(): | ||
+ | global iptext | ||
+ | global porttext | ||
+ | global ipAddrWindow | ||
+ | |||
+ | ipAddrWindow = Toplevel() | ||
+ | prompt = Label(ipAddrWindow, | ||
+ | iptext = Entry(ipAddrWindow, | ||
+ | portpromt = Label(ipAddrWindow, | ||
+ | porttext = Entry(ipAddrWindow, | ||
+ | okbut = Button(ipAddrWindow, | ||
+ | prompt.pack() | ||
+ | iptext.pack() | ||
+ | portpromt.pack() | ||
+ | porttext.pack() | ||
+ | okbut.pack() | ||
+ | |||
+ | def socket(): | ||
+ | import socket | ||
+ | global ip, port, client_socket | ||
+ | ip = iptext.get() | ||
+ | port = porttext.get() | ||
+ | ipAddrWindow.destroy() | ||
+ | client_socket = socket.socket(socket.AF_INET, | ||
+ | client_socket.connect((ip, | ||
+ | |||
+ | #################################################### | ||
+ | #Create Main Window | ||
+ | #Create Password Window | ||
+ | #Create label promt password text # | ||
+ | #Create Entry Box for password window backrnd white# | ||
+ | #Pack all three widgits | ||
+ | #################################################### | ||
+ | |||
+ | root = Tk() | ||
+ | root.title(' | ||
+ | pwdcheck = Toplevel(bd = 10, takefocus =1, relief = ' | ||
+ | pwdcheck.geometry(" | ||
+ | pwdcheck.resizable(width = 0, height = 0) | ||
+ | passtxt = Label(pwdcheck, | ||
+ | ent = Entry(pwdcheck, | ||
+ | button = Button(pwdcheck, | ||
+ | ent.focus() | ||
+ | passtxt.pack() | ||
+ | ent.pack() | ||
+ | button.pack() | ||
+ | |||
+ | connectButton = Button(root, | ||
+ | getLogButton = Button(root, | ||
+ | root.mainloop() | ||
+ | |||
+ | </ | ||
+ | Test Tomorrow through in the log_grab function dunno if it works yet will have to test tomorrow... | ||
+ | < | ||
+ | import socket | ||
+ | from Tkinter import * | ||
+ | password = ' | ||
+ | |||
+ | def errorWindowKill(error_window): | ||
+ | error_window.destroy() | ||
+ | |||
+ | def pwdin(): | ||
+ | key = ent.get() | ||
+ | if key != password: | ||
+ | print 'Need to replace with window error or label error' | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | else: | ||
+ | pwdcheck.destroy() | ||
+ | instructions() | ||
+ | |||
+ | def instructions(): | ||
+ | greeting = Label(root, text = ' | ||
+ | greeting.pack() | ||
+ | connectButton.pack(side = " | ||
+ | getLogButton.pack(side = " | ||
+ | # | ||
+ | # | ||
+ | |||
+ | |||
+ | ##################################################### | ||
+ | #added this function to get ip address and port from# | ||
+ | #user to explain starting at line 1 # | ||
+ | #create new window assign it to ipAddrWindow | ||
+ | #create text label so user knows what to do # | ||
+ | #create entry for ip address | ||
+ | #text for port # | ||
+ | #entry box for port # | ||
+ | #create ok button giving it the command socket have # | ||
+ | #not created this function yet # | ||
+ | #pack everything so it shows up # | ||
+ | ##################################################### | ||
+ | def ip_grab(): | ||
+ | global iptext | ||
+ | global porttext | ||
+ | global ipAddrWindow | ||
+ | |||
+ | ipAddrWindow = Toplevel() | ||
+ | prompt = Label(ipAddrWindow, | ||
+ | iptext = Entry(ipAddrWindow, | ||
+ | portpromt = Label(ipAddrWindow, | ||
+ | porttext = Entry(ipAddrWindow, | ||
+ | okbut = Button(ipAddrWindow, | ||
+ | prompt.pack() | ||
+ | iptext.pack() | ||
+ | portpromt.pack() | ||
+ | porttext.pack() | ||
+ | okbut.pack() | ||
+ | |||
+ | def socket(): | ||
+ | import socket | ||
+ | global ip, port, client_socket | ||
+ | ip = iptext.get() | ||
+ | port = porttext.get() | ||
+ | ipAddrWindow.destroy() | ||
+ | client_socket = socket.socket(socket.AF_INET, | ||
+ | client_socket.connect((ip, | ||
+ | |||
+ | def log_grab(): | ||
+ | #filename = | ||
+ | BUFSIZE = 1024 | ||
+ | flag = 1 | ||
+ | client_socket.send(flag) | ||
+ | while flag == 1: | ||
+ | data = client_socket.recv(BUFSIZE) | ||
+ | if data: | ||
+ | file = open(filename, | ||
+ | file.write(data) | ||
+ | else: | ||
+ | file.write(data) | ||
+ | flag = 0 | ||
+ | break | ||
+ | file.close() | ||
+ | #################################################### | ||
+ | #Create Main Window | ||
+ | #Create Password Window | ||
+ | #Create label promt password text # | ||
+ | #Create Entry Box for password window backrnd white# | ||
+ | #Pack all three widgits | ||
+ | #################################################### | ||
+ | |||
+ | root = Tk() | ||
+ | root.title(' | ||
+ | pwdcheck = Toplevel(bd = 10, takefocus =1, relief = ' | ||
+ | pwdcheck.geometry(" | ||
+ | pwdcheck.resizable(width = 0, height = 0) | ||
+ | passtxt = Label(pwdcheck, | ||
+ | ent = Entry(pwdcheck, | ||
+ | button = Button(pwdcheck, | ||
+ | ent.focus() | ||
+ | passtxt.pack() | ||
+ | ent.pack() | ||
+ | button.pack() | ||
+ | |||
+ | connectButton = Button(root, | ||
+ | getLogButton = Button(root, | ||
+ | root.mainloop() | ||
+ | </ | ||
+ | |||
+ | =====and Blender===== | ||
+ | While reading some things on blender/ | ||
+ | |||
+ | -getting into the interpreter in blender | ||
+ | -Imports | ||
+ | -simple commands | ||
+ | to start you must have blender installed.. | ||
+ | open blender and click the " | ||
+ | im guessing its called bottom left corner. From their | ||
+ | you should see options like "3D View", " | ||
+ | Window", | ||
+ | Normally ive been going to the text button and | ||
+ | creating new files their and running them but i | ||
+ | found a way to access the interpreter directly.. | ||
+ | so click the scripts button and you will see a white | ||
+ | window | ||
+ | from their hit the | ||
+ | scripts>> | ||
+ | |||
+ | IMPORTS | ||
+ | ok so mine automatically did this for me but to be | ||
+ | safe ill add it in | ||
+ | you must first start off in your console with these | ||
+ | import statements | ||
+ | |||
+ | Import Blender | ||
+ | #you can find reference to the blender module at | ||
+ | the #bottom of post. | ||
+ | |||
+ | Import bpy | ||
+ | #bpy is an experimental version of blender | ||
+ | #supposed to replace the blender module someday | ||
+ | |||
+ | #my interpreter also loads | ||
+ | from Blender import * | ||
+ | #witch im unsure as of why as ive already imported | ||
+ | Blender.. i dont have to #type blender.get() now | ||
+ | though instead just get() | ||
+ | |||
+ | Simple Things | ||
+ | |||
+ | #first command | ||
+ | list(bpy.data.objects) | ||
+ | |||
+ | #with no changes to blender like adding a new | ||
+ | object after you started then #you should see the | ||
+ | following output | ||
+ | |||
+ | #[[Object " | ||
+ | #the first thing " | ||
+ | through " | ||
+ | #bpy means to use a function from the bpy module | ||
+ | in this case " | ||
+ | your objects sub module of bpy.data | ||
+ | |||
+ | OK so now we can list all the objects Lets store | ||
+ | them to Variables | ||
+ | |||
+ | camera = bpy.data.objects[" | ||
+ | #stores object Camera to variable | ||
+ | cube = bpy.data.objects[" | ||
+ | lamp = bpy.data.objects[" | ||
+ | |||
+ | #so now you can type | ||
+ | print camera | ||
+ | # | ||
+ | [Object " | ||
+ | #ive also tried pythons dir() out on it | ||
+ | #from looking at it their are alot of functions inside of it | ||
+ | #not really sure on all of this yet! | ||
+ | #take a look and let me know if you do! | ||
+ | #save me some reading | ||
+ | #anyway that would look something like this | ||
+ | dir(camera) | ||
+ | |||
+ | #moving on | ||
+ | cube.type | ||
+ | #will give you the type of the object in this case a | ||
+ | cube is considered a mesh object | ||
+ | |||
+ | #get more information about the cube mesh | ||
+ | mesh = cube.getData(mesh=1) | ||
+ | #list functions and properties | ||
+ | dir(mesh) | ||
+ | |||
+ | that will give you a start im going to keep messing | ||
+ | around with it and ill keep adding to post " | ||
+ | --------------------------------------------------------------------------------------- | ||
+ | \\ | ||
+ | ==Moving Objects With python script== | ||
+ | \\ | ||
+ | Did some more reading as far as blender python go got a few little enhancements | ||
+ | |||
+ | < | ||
+ | import Blender | ||
+ | import bpy | ||
+ | |||
+ | #put object in variable in this case the default Cube | ||
+ | |||
+ | cube = bpy.data.objects[" | ||
+ | |||
+ | #move the cube | ||
+ | |||
+ | cube.LocX += 2 | ||
+ | |||
+ | #can use X, Y, or Z Loc is Location | ||
+ | |||
+ | #Rotate the cube | ||
+ | |||
+ | cube.RotX += 2 | ||
+ | |||
+ | #again you can use X, Y, or Z Rot stands for Rotation | ||
+ | </ | ||
+ | So for example rotate the cube in a loop | ||
+ | < | ||
+ | import Blender | ||
+ | import bpy | ||
+ | |||
+ | c = bpy.data.objects[" | ||
+ | while True: | ||
+ | c.RotX += 2 | ||
+ | Blender.Redraw() | ||
+ | | ||
+ | </ | ||
+ | This will make the cube keep rotating forever.. this would be pretty neat and handy to people that were trying to render planets and such things being able to rotate objects and then move their locations to certain positions | ||