id int64 0 25.6k | text stringlengths 0 4.59k |
|---|---|
19,100 | graphic objects are used for specific conceptsfor example filing cabinets for disks or waste bin for file disposal (these could be regarded as desk accessories)various application programs are displayed on the screenthese stand for tools that you might use on your desktop in order to interact with this displaythe wimp ... |
19,101 | graphical user interfaces developers of python guis have taken one of two approaches to handle thisone approach is to write wrapper that abstracts the underlying gui facilities so that the developer works at level above specific windowing system' facilities the python library then maps (as best it canthe facilities to ... |
19,102 | online resources there are numerous online references that support the development of guis and of python guis in particularincludingdevelopment library macos cocoa library bridge pythonwin |
19,103 | the wxpython gui library the wxpython library the wxpython library is cross platform gui library (or toolkitfor python it allows programmers to develop highly graphical user interfaces for their programs using common concepts such as menu barsmenusbuttonsfieldspanels and frames in wxpython all the elements of gui are c... |
19,104 | the wxpython gui library windows such as frames and dialogs have component hierarchy that is used (amongst other thingsto determine how and when elements of the window are drawn and redrawn the component hierarchy is rooted with the framewithin which components and containers can be added the above figure illustrates c... |
19,105 | windows as objects in wxpythonframes and dialogs as well as their contents are instances of appropriate classes (such as framedialogpanelbutton or statictextthus when you create windowyou create an object that knows how to display itself on the computer screen you must tell it what to display and then tell it to show i... |
19,106 | the wxpython gui library to use the wxpython library it is necessary to import the wx module import wx create the application object app wx app(now create frame (representing the windowframe wx frame(parent=nonetitle=simple hello world'and add text label to it text wx statictext(parent=framelabel'hello python'display t... |
19,107 | every wxpython application must have single wx app instance the creation of all of the ui objects should be delayed until after the wx app object has been created in order to ensure that the gui platform and wxwidgets have been fully initialised it is common to subclass the wx app class and override methods such as onp... |
19,108 | the wxpython gui library window classes the window or widget container classes that are commonly used within wxpython application arewx dialog dialog is top level window used for popups where the user has limited ability to interact with the window in many cases the user can only input some data and/or accept or declin... |
19,109 | the program that generated this gui is given belowimport wx class sampleframe(wx frame)def __init__(self)super(__init__(parent=nonetitle='sample app'size=( )set up the first panel to be at position (the defaultand of size by with blue background self panel wx panel(selfself panel setsize( self panel setbackgroundcolour... |
19,110 | the wxpython gui library the sampleframe is subclass of the wx frame classit thus inherits all of the functionality of top level frame (windowwithin the __init__(method of the sampleframe the super classes __init__(method is called this is used to set the size of the frame and to give the frame title note that the fram... |
19,111 | whenever widget is created it is necessary to provide the container window class that will hold itsuch as frame or panelfor exampleenter_button wx button(panellabel='enter'in this code snippet wx button is being created that will have label 'enterand will be displayed within the given panel dialogs the generic wx dialo... |
19,112 | the wxpython gui library most of the dialogs that return value follow the same pattern this pattern returns value from the showmodel(method that indicates if the user selected ok or cancel (using the return value wx id_ok or wx id_cancelthe selected/entered value can then be obtained from suitable get method such as ge... |
19,113 | wx gridbagsizer is the most flexible sizer it allows widgets to be positioned relative to the grid and also allows widgets to span multiple rows and/or columns to use sizer it must first be instantiated when widgets are created they should be added to the sizer and then the sizer should be set on the container for exam... |
19,114 | the wxpython gui library drawing graphics in earlier we looked at the turtle graphics api for generating vector and raster graphics in python the wxpython library provides its own facilities for generating cross platform graphic displays using linessquarescirclestext etc this is provided via the device context device c... |
19,115 | this method can be used to draw whatever the contents of the window should be if you do not redraw the contents of the device context in such method than whatever you previously drew will display when the window is refreshed the following simple program illustrates the use of some of the draw methods listed above and h... |
19,116 | the wxpython gui library online resources there are numerous online references that support the development of guis and of python guis in particularincludingcross platform gui library exercises simple gui application in this exercise you will implement your own simple gui application the application should generate the... |
19,117 | events in wxpython user interfaces event handling events are an integral part of any guithey represent user interactions with the interface such as clicking on buttonentering text into fieldselecting menu option etc the main event loop listens for an eventwhen one occurs it processes that event (which usually results i... |
19,118 | events in wxpython user interfaces event loop the main processing loop of the gui that waits for an event to occur when an event occurs the associated event handler is called event handlers these are methods (or functionsthat are called when an event occurs event binders associate type of event with an event handler th... |
19,119 | wx keyevent this event contains information relating to key press or release wx maximizeevent this event is generated when top level window is maximised wx menuevent this event is used for menu oriented actions such as the menu being opened or closedhowever it should be noted that this event is not used when menu item ... |
19,120 | events in wxpython user interfaces to illustrate this we will use simple example we will write very simple event handling application this application will have frame containing panel the panel will contain label using the wx statictext class we will define an event handler called on_mouse_click(that will move the stat... |
19,121 | import wx class welcomeframe(wx frame)""the main window frame of the application ""def __init__(self)super(__init__(parent=nonetitle='sample app'size=( )set up panel within the frame and text label self panel wx panel(selfself text wx statictext(self panellabel='hello'bind the on_mouse_click method to the mouse event v... |
19,122 | events in wxpython user interfaces when this program is runthe window is displayed with the 'hellostatictext label in the top left hand corner of the frame (actually it is added to the panelhowever the panel fills the frame in this exampleif the user then clicks the left mouse button anywhere within the frame then the ... |
19,123 | the code used to implement this gui application is given belowimport wx class helloframe(wx frame)def __init__(selftitle)super(__init__(nonetitle=titlesize=( )self name 'create the boxsizer to use for the frame vertical_box_sizer wx boxsizer(wx verticalself setsizer(vertical_box_sizercreate the panel to contain the wid... |
19,124 | events in wxpython user interfaces now configure the enter button enter_button wx button(panellabel='enter'enter_button bind(wx evt_buttonself set_namenext set up the text label self label wx statictext(panellabel='welcome'style=wx align_leftnow configure the show message button message_button wx button(panellabel='sho... |
19,125 | class mainapp(wx app)def oninit(self)""initialise the gui display""frame helloframe(title='sample app'frame show(indicate whether processing should continue or not return true def onexit(self)""executes when the gui application shuts down""print('goodbye'need to indicate success or failure return true run the gui appli... |
19,126 | events in wxpython user interfaces online resources there are numerous online references that support the development of guis and of python guis in particularincludingcross platform gui library exercises simple gui application this exercise builds on the gui you created in the last the application should allow user to ... |
19,127 | button should be provided labelled 'birthday'when clicked it should increment the age by one and display happy birthday message the age should be updated within the gui an example of the user interface you created in the last is given belowas an examplethe user might enter their name and age as shown belowwhen the user... |
19,128 | events in wxpython user interfaces gui interface to tic tac toe game the aim of this exercise is to implement simple tic tac toe game the game should allow two users to play interactive using the same mouse the first user will have play as the 'xplayer and the second user as the ' player when each user selects button y... |
19,129 | pydraw wxpython example application introduction this builds on the gui library presented in the last two to illustrate how larger application can be built it presents case study of drawing tool akin to tool such as visio etc the pydraw application the pydraw application allows user to draw diagrams using squarescircle... |
19,130 | pydraw wxpython example application the operating system it has menu bar across the top (on mac this menu bar is at the top of the mac display) tool bar below the menu bar and scrollable drawing area below that the first button on the tool bar clears the drawing area the second and third buttons are only implemented so... |
19,131 | the structure of the application it is important to visualize this as the majority of wxpython interfaces are built up in this wayusing containers and sizers the inheritance structure between the classes used in the pydraw application is illustrated below this class hierarchy is typical of an application which incorpor... |
19,132 | pydraw wxpython example application there are number of reasons why this separation is usefulreusability of application and/or user interface componentsability to develop the application and user interface separatelyability to inherit from different parts of the class hierarchy ability to define control style classes w... |
19,133 | the structure of the application the drawingmodeldrawingpanel and drawingcontroller classes exhibit the classic mvc structure the view and the controller classes (drawingpanel and drawingcontrollerknow about each other and the drawing modelwhereas the drawingmodel knows nothing about the view or the controller the view... |
19,134 | pydraw wxpython example application the final class is the pydrawapp class that extends the wx app class object relationships howeverthe inheritance hierarchy is only part of the story for any object oriented application the following figure illustrates how the objects relate to one another within the working applicati... |
19,135 | the structure of the application the drawingpanel is responsible le for displaying any figures held by the drawingmodel the drawingcontroller manages all user interactions with the drawingpanel including adding figures and clearing all figures from the model the drawingmodel holds list of figures to be displayed the in... |
19,136 | pydraw wxpython example application the pydrawframe constructor the pydrawframe constructor method sets up the main display of the ui application and also initialises the controllers and drawing elements this is shown below using collaboration diagramthe pydrawframe constructor sets up the environment for the applicati... |
19,137 | the interactions between objects when the user selects one of the menu items the command_menu_handler (method of the pydrawcontroller is invoked this method determines which menu item has been selectedit then calls an appropriate setter method (such as set_circle_mode(or set_line_mode(etc these methods set the mode att... |
19,138 | pydraw wxpython example application the above illustrates what happens when the user presses and releases mouse button over the drawing panelto create new figure when the user presses the mouse buttona mouse clicked message is sent to the drawingcontrollerwhich decides what action to perform in response (see abovein py... |
19,139 | the classes the pydrawframe class the pydrawframe class provides the main window for the application note that due to the separation of concerns introduced via the mvc architecturethe view class is only concerned with the layout of the componentsclass pydrawframe(wx frame)""main frame responsible for the layout of the ... |
19,140 | pydraw wxpython example application the pydrawmenubar class the pydrawmenubar class is subclass of the wx menubar class which defines the contents of the menu bar for the pydraw application it does this by creating two wx menu objects and adding them to the menu bar each wx menu implements drop down menu from the menu ... |
19,141 | the classes pydraw_constants circle_idtext="circle"kind=wx item_normaldrawingmenu append(circlemenuitemtextmenuitem wx menuitem(drawingmenupydraw_constants text_idtext="text"kind=wx item_normaldrawingmenu append(textmenuitemself append(drawingmenu'&drawing'the pydrawtoolbar class the drawtoolbar class is subclass of wx... |
19,142 | pydraw wxpython example application class pydrawcontrollerdef __init__(selfview)self view view set the initial mode self mode pydrawconstants square_mode def set_circle_mode(self)self mode pydrawconstants circle_mode def set_line_mode(self)self mode pydrawconstants line_mode def set_square_mode(self)self mode pydrawcon... |
19,143 | the classes the drawingmodel class the drawingmodel class has contents attribute that is used to hold all the figures in the drawing it also provides some convenience methods to reset the contents and to add figure to the contents class drawingmodeldef __init__(self)self contents [def clear_figures(self)self contents [... |
19,144 | pydraw wxpython example application def on_paint(selfevent)"""set up the device context (dcfor painting""dc wx paintdc(selffor figure in self model contentsfigure on_paint(dcthe drawingcontroller class the drawingcontroller class provides the control class for the top level mvc architecture used with the drawingmodel (... |
19,145 | the classes the figure class the figure class (an abstract superclass of the figure class hierarchycaptures the elements which are common to graphic objects displayed within drawing the point defines the position of the figurewhile the size attribute defines the size of the figure note that the figure is subclass of wx... |
19,146 | pydraw wxpython example application the circle class this is another subclass of figure it implements the on_paint(method by drawing circle note that the shape will be drawn within the panel size defined via the figure class (using the call to superit is therefore necessary to see the circle to fit within these bounds ... |
19,147 | the classes the text class this is also subclass of figure default value is used for the text to displayhowever dialog could be presented to the user allowing them to input the text they wish to displayclass text(figure)def __init__(selfparentpossize)super(__init__(parent=parentpos=possize=wx size(sizesize)def on_paint... |
19,148 | computer games |
19,149 | introduction to games programming introduction games programming is performed by developers/coders who implement the logic that drives game historically games developers did everythingthey wrote the codedesigned the sprites and iconshandled the game playdealt with sounds and musicgenerated any animations required etc h... |
19,150 | introduction to games programming one example is the unity framework that can be used with the cprogramming language another such framework is the unreal engine used with the +programming language python has also been used for games development with several well known games titles depending on it in one way or another ... |
19,151 | python games development types (circlepolygonthin line segmentsas well as number of joint types (revoluteprismaticwheeletc blender this is open-source computer graphics software toolset used for creating animated filmsvisual effectsart printed modelsinteractive applications and video games blender' features include mod... |
19,152 | building games with pygame introduction pygame is cross-platformfree and open source python library designed to make building multimedia applications such as games easy development of pygame started back in october with pygame version being released six months later the version of pygame discussed in this is version if... |
19,153 | building games with pygame the display surface the display surface (aka the displayis the most important part of pygame game it is the main window display of your game and can be of any sizehowever you can only have one display surface in many ways the display surface is like blank piece of paper on which you can draw ... |
19,154 | the display surface to aid in performance any changes you make to the display surface actually happen in the background and will not be rendered onto the actual display that the user sees until you call the update(or flip(methods on the surface for examplepygame display update(pygame display flip(the update(method will... |
19,155 | building games with pygame using joystick can generate several different types of event including joyaxismotionjoyballmotionjoybuttondown and joybu ttonup these event types tell you what occurred to generate the event this means that you can choose which types of events you want to deal with and ignore other events eve... |
19,156 | events k_tabk_spacek_plusk_ k_ k_atk_ak_bk_zk_deltek_downk_leftk_rightk_left etc further keyboard constants are provided for modifier states that can be combined with the above such as kmod_shiftkmod_capskmod_ctrl and kmod_alt the event queue events are supplied to pygame application via the event queue the event queue... |
19,157 | building games with pygame in the above code snippet an eventlist is obtained from the event queue containing the current set of events the for loop then processes each event in turn checking the type and printing an appropriate message you can use this approach to trigger appropriate behaviour such as moving an image ... |
19,158 | first pygame application the simple helloworld game is given belowimport pygame def main()print('starting game'print('initialising pygame'pygame init(required by every pygame application print('initialising helloworldgame'pygame display set_mode(( )pygame display set_caption('hello world'print('update display'pygame di... |
19,159 | building games with pygame method check to see that you have called pygame init(note that you can initialise individual pygame modules (for example the pygame font module can be initialised using pygame font init()if required however pygame init(is the most commonly used approach to setting up pygame set up the display... |
19,160 | first pygame application start of our program we will therefore need to call pygame quit(at the end of the program to ensure everything is tidied up appropriately the output generated from sample run of this program is given belowpygame hello from the pygame community starting game initialising pygame initialising hell... |
19,161 | building games with pygame rectangles (or rectsthe pygame rect class is an object used to represent rectangular coordinates rect can be created from combination of the top left corner coordinates plus width and height for flexibility many functions that expect rect object can also be given rectlike listthis is list tha... |
19,162 | further concepts images the pygame image module contains functions for loadingsaving and transforming images when an image is loaded into pygameit is represented by surface object this means that it is possible to drawmanipulate and process an image in exactly the same way as any other surface which provides great deal... |
19,163 | building games with pygame the games refresh rate is slower then the the given ticks per second this can be used to help limit the runtime speed of game by calling clock tick ( once per framethe program will never run at more than frames per second more interactive pygame application the first pygame application we loo... |
19,164 | more interactive pygame application print('initialising box game'display_surface pygame display set_mode(( )pygame display set_caption('box game'print('update display'pygame display update(print('setup the clock'clock pygame time clock(clear the screen of current contents display_surface fill(backgroundprint('starting ... |
19,165 | building games with pygame alternative approach to processing input devices there are actually two ways in which inputs from device such as mousejoystick or the keyboard can be processed one approach is the event based model described earlier the other approach is the state based approach although the event based appro... |
19,166 | pygame modules pygame event this module manages events and the event queue for example pygame event get(retrieves events from the event queuepygame event poll(gets single event from the queue and pygame event peek(tests to see if there are any event types on the queue pygame draw the draw module is used to draw simple ... |
19,167 | starshipmeteors pygame creating spaceship game in this we will create game in which you pilot starship through field of meteors the longer you play the game the larger the number of meteors you will encounter typical display from the game is shown below for apple mac and windows pcwe will implement several classes to r... |
19,168 | starshipmeteors pygame the classes and their relationships are shown belowthis diagram shows that the starship and meteor classes will extend class called gameobject in turn it also shows that the game has : relationship with the starship class that is the game holds reference to one starship and in turn the starship h... |
19,169 | the main game class import pygame set up global 'constantsframe_refresh_rate display_width display_height class game""represents the game itself and game playing loop ""def __init__(self)print('initialising pygame'pygame init(set up the display self display_surface pygame display set_mode((display_widthdisplay_height)p... |
19,170 | starshipmeteors pygame the main play(method of the game class has loop that will continue until the user selects to quit the game they can do this in one of two wayseither by pressing the 'qkey (represented by the event key k_qor by clicking on the window close button in either case these events are picked up in the ma... |
19,171 | the gameobject class return pygame rect(self xself yself widthself heightdef draw(self)""draw the game object at the current xy coordinates ""self game display_surface blit(self image(self xself )the gameobject class is directly extended by the starship class and the meteor class currently there are only two types of g... |
19,172 | starshipmeteors pygame in the game class we will now add line to the __init__(method to initialise the starship object this line isset up the starship self starship starship(selfwe will also add line to the main while loop within the play(method just before we refresh the display this line will call the draw(method on ... |
19,173 | moving the spaceship the updated starship class is shown belowthis version of the starship class defines the various move methods these methods use new global value starship_speed to determine how far and how fast the starship moves if you want to change the speed that the starship moves then you can change this global... |
19,174 | starshipmeteors pygame but if it moves down the screen then the coordinate is increased by starship_speed of course we do not want our starship to fly off the edge of the screen and so test must be made to see if it has reached the boundaries of the screen thus tests are made to see if the or values have gone below zer... |
19,175 | moving the spaceship the problem is that we are redrawing the starship at different positionbut the previous image is still present we now have two choices one is to merely fill the whole screen with blackeffectively hiding anything that has been drawn so faror alternatively we could just draw over the area used by the... |
19,176 | starshipmeteors pygame define default rgb colours background ( if you want to use different background colour then change this global value adding meteor class the meteor class will also be subclass of the gameobject class howeverit will only provide move_down(method rather than the variety of move methods of the stars... |
19,177 | adding meteor class the __init__(method for the meteor class has the same steps as the starshipthe difference is that the coordinate and the speed are randomly generated the image used for the meteor is also different as it is 'meteor pngwe have also implemented move_down(method this is essentially the same as the star... |
19,178 | starshipmeteors pygame moving the meteors we now want to be able to move the meteors down the screen so that the starship has some objects to avoid we can do this very easily as we have already implemented move_down(method in the meteor class we therefore only need to add for loop to the main game playing while loop th... |
19,179 | identifying collision the gameobject class already provides method rect(that will return rect object representing the objectscurrent rectangle with respect to the drawing surface (essentially the box around the object representing its location on the screenthus we can write collision detection method for the game class... |
19,180 | starshipmeteors pygame identifying win we currently have way to loose the game but we don' have way to win the gamehoweverwe want the player to be able to win the game by surviving for specified period of time we could represent this with timer of some sort howeverin our case we will represent it as specific number of ... |
19,181 | increasing the number of meteors now every new_meteor_cycle_interval another meteor will be added at random coordinate to the game pausing the game another feature that many games have is the ability to pause the game this can be easily added by monitoring for pause key (this could be the letter represented by the even... |
19,182 | starshipmeteors pygame displaying the game over message pygame does not come with an easy way of creating popup dialog box to display messages such as 'you won'or 'you lostwhich is why we have used print statements so far howeverwe could use gui framework such as wxpython to do this or we could display message on the d... |
19,183 | displaying the game over message the result of the above code being run when collision occurs is shown below the starshipmeteors game the complete listing for the final version of the starshipmeteors game is given belowimport pygamerandomtime frame_refresh_rate display_width display_height white ( background ( initial_... |
19,184 | starshipmeteors pygame class gameobjectdef load_image(selffilename)self image pygame image load(filenameconvert(self width self image get_width(self height self image get_height(def rect(self)""generates rectangle representing the objects location and dimensions ""return pygame rect(self xself yself widthself heightdef... |
19,185 | the starshipmeteors game self display_height self height def __str__(self)return 'starship(str(self 'str(self ')class meteor(gameobject)""represents meteor in the game ""def __init__(selfgame)self game game self random randint( display_widthself initial_meteor_y_location self speed random randint( max_meteor_speedself ... |
19,186 | starshipmeteors pygame break return result def _display_message(selfmessage)""displays message to the user on the screen ""text_font pygame font font('freesansbold ttf' text_surface text_font render(messagetruebluewhitetext_rectangle text_surface get_rect(text_rectangle center (display_width display_height self display... |
19,187 | the starshipmeteors game move the player left self starship move_left(elif event key =pygame k_upself starship move_up(elif event key =pygame k_downself starship move_down(elif event key =pygame k_pself _pause(elif event key =pygame k_qis_running false move the meteors for meteor in self meteorsmeteor move_down(clear t... |
19,188 | starshipmeteors pygame online resources there is great deal of information available on pygame includingcode exercises using the example presented in this add the followingprovide score counter this could be based on the number of cycles the player survives or the number of meteors that restart from the top of the scre... |
19,189 | introduction to testing introduction this considers the different types of tests that you might want to perform with the systems you develop in python it also introduces test driven development types of testing there are at least two ways of thinking about testing it is the process of executing program with the intent ... |
19,190 | introduction to testing development timeit forms major part of quality assurance (qaand user acceptance testing it should be noted that with the advent of test-driven developmentthe emphasis on testing against requirements during development has become significantly higher there are of course many other aspects to test... |
19,191 | what should be tested test planning should also look at all aspects of the software under test for functionalityusabilitylegal complianceconformance to regulatory constraintssecurityperformanceavailabilityresilienceetc testing should be driven by the need to identify and reduce risk testing software systems as indicate... |
19,192 | introduction to testing security testing ensures that access to the system is controlled appropriately given the requirements for examplefor an online shopping system there may be different security requirements depending upon whether you are browsing the storepurchasing some products or maintaining the product catalog... |
19,193 | testing software systems create data driven tests for maximum flexibility and repeatabilityrely on mock objects that represent elements outside the unit that it must interact with having the tests automated means that they can be run frequentlyat the very least after initial development and after each change that affec... |
19,194 | introduction to testing installation/upgrade testing installation testing is the testing of fullpartial or upgrade install processes it also validates that the installation and transition software needed to move to the new release for the product is functioning properly typicallyit verifies that the software may be com... |
19,195 | automating testing they are run in the same way each time in additiononce an automated test is set up it will typically be quicker to re-run that automated test than to manually repeat series of tests howevernot all of the features of system can be easily tested via an automated test tool and in some cases the physical... |
19,196 | introduction to testing the tdd cycle there is cycle to development when working in tdd manner the shortest form of this cycle is the tdd mantrared green refactor which relates to the unit testing suite of tools where it is possible to write unit test within tools such as pycharmwhen you run pyunit or pytest test test ... |
19,197 | test driven development test complexity the aim is to strive for simplicity in all that you do within tdd thusyou write test that failsthen do just enough to make that test pass (but no morethen you refactor the implementation code (that is change the internals of the unit under testto improve the code base you continu... |
19,198 | introduction to testing online resources see the following online resources for more information on testing and test driven development (tddintroduction to software testing introduction to software testing wiki book simple introduction to tdd with python game kata which presents worked example of how tdd can be used to... |
19,199 | pytest testing framework introduction there are several testing frameworks available for pythonalthough only oneunittest comes as part of the typical python installation typical libraries include unit test(which is available within the python distribution by defaultand pytest in this we will look at pytest and how it c... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.