Plasma 5.15.90 (Plasma 5.16 Beta) Available for Testing

Planet KDE - Sat, 2019-05-18 12:44

Are you using Kubuntu 19.04, our current Stable release? Or are you already running our daily development builds?

We currently have Plasma 5.15.90 (Plasma 5.16 Beta)  available in our Beta PPA for Kubuntu 19.04, and in our 19.10 development release daily live ISO images.

For 19.04 Disco Dingo, add the PPA and then upgrade

sudo add-apt-repository ppa:kubuntu-ppa/beta && sudo apt update && sudo apt full-upgrade -y

Then reboot. If you cannot reboot from the application launcher,

systemctl reboot

from the terminal.

For already installed 19.10 Eoan Ermine development release systems, simply upgrade your system.

Update directly from Discover, or use the command line:

sudo apt update && sudo apt full-upgrade -y

And reboot. If you cannot reboot from the application launcher,

systemctl reboot

from the terminal.

Otherwise, to test or install the live image grab an ISO build from the daily live ISO images link.

Kubuntu is part of the KDE community, so this testing will benefit both Kubuntu as well as upstream KDE Plasma software, which is used by many other distributions too.

  • If you believe you might have found a packaging bug, you can use your launchpad.net account is required to post testing feedback to the Kubuntu team. 
  • If you believe you have found a bug in the underlying software, then bugs.kde.org is the best place to file your bug report.

Please review the changelog.

[Test Case]

* General tests:
– Does plasma desktop start as normal with no apparent regressions over 5.15.5?
– General workflow – testers should carry out their normal tasks, using the plasma features they normally do, and test common subsystems such as audio, settings changes, compositing, desktop affects, suspend etc.

* Specific tests:
– Check the changelog:
– Identify items with front/user facing changes capable of specific testing. e.g. “clock combobox instead of tri-state checkbox for 12/24 hour display.”
– Test the ‘fixed’ functionality.

Testing involves some technical set up to do, so while you do not need to be a highly advanced K/Ubuntu user, some proficiently in apt-based package management is advisable.

Testing is very important to the quality of the software Ubuntu and Kubuntu developers package and release.

We need your help to get this important beta release in shape for Kubuntu 19.10 as well as added to our backports.

Thanks! Please stop by the Kubuntu-devel IRC channel or Telegram group if you need clarification of any of the steps to follow.

Categories: FLOSS Project Planets

Python Software Foundation: Amber Brown: Batteries Included, But They're Leaking

Planet Python - Sat, 2019-05-18 09:42

Amber Brown of the Twisted project shared her criticisms of the Python standard library. This proved to be the day’s most controversial talk; Guido van Rossum stormed from the room during Q & A.

Read more 2019 Python Language Summit coverage.

Applications Need More Than The Standard Library Python claims to ship with batteries included, but according to Brown, without external packages it is only “marginally useful.” For example, asyncio requires external libraries to connect to a database or to speak HTTP. Brown asserted that there were many such dependencies from the standard library to PyPI: typing works best with mypy, the ssl module requires a monkeypatch to connect to non-ASCII domain names, datetime needs pytz, and six is non-optional for writing code for Python 2 and 3.

Other standard library modules are simply inferior to alternatives on PyPI. The http.client documentation advises readers to use Requests, and the datetime module is confusing compared to its competitors such as arrow, dateutil, and moment.

Poor Quality, Lagging Features, And Obsolete Code

“Python's batteries are leaking,” said Brown. She thinks that some bugs in the standard library will never be fixed. And even when bugs are fixed, PyPI libraries like Twisted cannot assume they run on the latest Python, so they must preserve their bug workarounds forever.

There are many modules that few applications use, but there is no method to install a subset of the standard library. Brown called out the XML parser and tkinter in particular for making the standard library larger and harder to build, burdening all programmers for the sake of a few. As Russell Keith-Magee had described earlier in the day, the size of the standard library makes it difficult for PyBee to run Python on constrained devices. Brown also noted that some standard library modules were optimized in C for Python 3, but had to be reimplemented in pure Python for PyPy to support them.

Brown identified new standard library features that were “too little, too late,” leaving users to depend on backports to use those features in Python 2. For example, socket.sendmsg was added only recently, meaning Twisted must ship its own C extension to use sendmsg in Python 2. Although Python 2 is nearly at its end of life, this only holds for the core developers, according to Brown, and for users, Red Hat and other distributors will keep Python 2 alive “until the goddam end of time.” Brown also mentioned that some itertools code is shown as examples in the documentation instead of shipped as functions in the itertools module.

Guido van Rossum, sitting at the back of the room, interrupted at this moment, “Can you keep to one topic? I'm sorry but this is just one long winding rant. What is your point?” Brown responded that her point was that there are a multitude of problems in the standard library.

Standard Library Modules Crowd Out Innovation
Brown’s most controversial opinion, in her own estimation, is that adding modules to the standard library stifles innovation, by discouraging programmers from using or contributing to competing PyPI packages. Ever since asyncio was announced she has had to explain why Twisted is still worthwhile, and now that data classes are in the standard library Hynek Schlawack must defend his attrs package. Even as standard library modules crowd out other projects, they lag behind them. According to Brown, “the standard library is where code sometimes goes to die,” because it is difficult and slow to contribute code there. She acknowledged recent improvements, from Mariatta Wijaya’s efforts in particular, but Python is still harder to contribute to than PyPI packages.

“So I know a lot of this is essentially a rant,” she concluded, “but it's fully intended to be.”

Nick Coghlan interpreted Brown’s proposal as generalizing the “ensurepip” model to ensure some packages are always available but can upgraded separately from the standard library, and he thought this was reasonable.

Van Rossum was less convinced. He asked again, “Amber, what is your point?” Brown said her point was to move asyncio to PyPI, along with most new feature development. “We should embrace PyPI,” she exhorted. Some ecosystems such as Javascript rely too much on packages, she conceded, but there are others like Rust that have small standard libraries and high-quality package repositories. She thinks that Python should move farther in that direction.

Van Rossum argued instead that if the Twisted team wants the ecosystem to evolve, they should stop supporting older Python versions and force users to upgrade. Brown acknowledged this point, but said half of Twisted users are still on Python 2 and it is difficult to abandon them. The debate at this point became personal for Van Rossum, and he left angrily.

Nathaniel Smith commented, “I'm noticing some tension here.” He guessed that Brown and the core team were talking past each other because the core team had different concerns from other Python programmers. Brown went further adding that because few Python core developers are also major library maintainers, library authors’ complaints are devalued or ignored.

The remaining core developers continued the technical discussion. Barry Warsaw said that the core team had discussed deprecating modules in the standard library, or creating slim distributions with a subset of it, but that it required a careful design. Others objected that slimming down the standard library risked breaking downstream code, or making work for programmers in enterprises that trust the standard library but not PyPI.

Pablo Galindo Salgado was concerned that moving modules from the standard library to PyPI would create an explosion of configurations to test, but in Brown’s opinion, “We are already living that life.” Some Linux and Python distributions have selectively backported features and fixes, leading to a much more complex set of configurations than the core team realizes.
Categories: FLOSS Project Planets

Clemens Tolboom: Working on a Drupal module using composer

Planet Drupal - Sat, 2019-05-18 05:10

Altering Drupals composer.json to fetch a particular Drupal module git checkout.

Categories: FLOSS Project Planets

Abhijeet Pal: Python Program To Print Numbers From 1 to 10 Using While Loop

Planet Python - Sat, 2019-05-18 03:48
Problem Definition

Create a Python program to print numbers from 1 to 10 using a while loop.


In programming, Loops are used to repeat a block of code until a specific condition is met. The While loop loops through a block of code as long as a specified condition is true.

To Learn more about working of While Loops read:

Program i = 1 while(i<=10): print(i) i += 1 Output 1 2 3 4 5 6 7 8 9 10

The post Python Program To Print Numbers From 1 to 10 Using While Loop appeared first on Django Central.

Categories: FLOSS Project Planets

Abhijeet Pal: Python Program To Print Numbers From 1 to 10 Using For Loop

Planet Python - Sat, 2019-05-18 03:28
Problem Definition

Create a Python program to print numbers from 1 to 10 using a for loop.


In programming, Loops are used to repeat a block of code until a specific condition is met. A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times.

Also, we are going to use one of Python’s built-in function range(). This function is extensively used in loops to control the number of types loop have to run. In simple words range is used to generate a sequence between the given values.

For a better understanding of these Python, concepts it is recommended to read the following articles.

Program for i in range(1, 11): print(i) Output 1 2 3 4 5 6 7 8 9 10 Explanation

The for loop prints the number from 1 to 10 using the range() function here i is a temporary variable which is iterating over numbers from 1 to 10.

It’s worth mentioning that similar to list indexing in range starts from 0 which means range( j )will print sequence till ( j-1) hence the output doesn’t include 6.

The post Python Program To Print Numbers From 1 to 10 Using For Loop appeared first on Django Central.

Categories: FLOSS Project Planets

Programming Ideas With Jake: Better Unbound Python Descriptors

Planet Python - Sat, 2019-05-18 01:00
I've been making unbound attributes be way more complicated that need be. Let's look at how to simplify it.
Categories: FLOSS Project Planets

Abhijeet Pal: Python Program to Find the Smallest Among Three Numbers

Planet Python - Fri, 2019-05-17 23:51
Problem Definition

Create a Python program to find the smallest among the three given numbers, taking runtime inputs from the user.

  1. Take inputs from the user and store them in variables
  2. Compare the numbers
  3. Print the final result
  4. End

To understand the program you need to have an understanding of following Python concept.

Program num1 = float(input("Enter first number: ")) num2 = float(input("Enter second number: ")) num3 = float(input("Enter third number: ")) smallest = num1 if (num2 < num1) and (num2 < num3): smallest = num2 elif (num3 < num1): smallest = num3 print("The smallest number is", smallest) Runtime Test Cases Enter first number: 90 Enter second number: 34 Enter third number: 69 The smallest number is 34.0 Explanation

First, the program is taking input from the keyboard using the built-in input() function. Although we do need to change the datatype of the inputs to either integer or float, we are converting the input to float for more accuracy.

Next, there are 3 conditional statements which will store the smallest number into the variable smallest which later gets printed out.

The post Python Program to Find the Smallest Among Three Numbers appeared first on Django Central.

Categories: FLOSS Project Planets

Abhijeet Pal: Python Program to Swap Two Numbers

Planet Python - Fri, 2019-05-17 23:40
Problem Definition

Create a Python program to swap two numbers taking runtime inputs. Swapping means interchanging, for instance, say we have two variables holding the following values a = 10 & b = 20 after swapping they will interchange the values so now a = 20 & b = 10.


Generally, a third variable is used for swapping where first we store the value of the first variable to a temporary variable say temp, then store the value of the second variable to the first variable and finally, store the value of the temporary variable to the second variable.

Fortunately, Python comes with a simple built-in method to swap two numbers without using any third variable.

a,b = b,a

This one-liner can swap values of two variable without using any additional variable, let’s see this in action in the program below.

  1. Take input from the user and store them in variables
  2. Print the values before swapping
  3. Print the values after swapping
  4. End
Program num1 = input('Enter First Number: ') num2 = input('Enter Second Number: ') print("Value of num1 before swapping: ", num1) print("Value of num2 before swapping: ", num2) num1, num2 = num2, num1 print("Value of num1 after swapping: ", num1) print("Value of num2 after swapping: ", num2) Runtime Test Cases Enter First Number: 2 Enter Second Number: 3 Value of num1 before swapping: 2 Value of num2 before swapping: 3 Value of num1 after swapping: 3 Value of num2 after swapping: 2

The values inside the variables are interchanged; hence we swapped two numbers without using any third variable in Python.

The post Python Program to Swap Two Numbers appeared first on Django Central.

Categories: FLOSS Project Planets

Abhijeet Pal: Python Program to Add Two Numbers

Planet Python - Fri, 2019-05-17 23:21
Problem Definition

Create a Python program to add two numbers and print the result, taking runtime input from the user.

  1. Take input from the user save them in variables
  2. Add the numbers and print the result
  3. End
Program num1 = int(input("Enter first number: ")) num2 = int(input("Enter second number: ")) sum = num1 + num2 print("The Sum is", sum) Runtime Test Cases Enter first number: 2 Enter second number: 4 The Sum is 6 Explanation

The input() function takes the input from the user however we need to convert the input to an integer using int() method to perform mathematical operation i.e. addition(+).

This program simply takes two arbitrary input from the keyboard store them in two different variables later these numbers are added and stored in another variable sum which at the end gets printed out.

The post Python Program to Add Two Numbers appeared first on Django Central.

Categories: FLOSS Project Planets

Kushal Das: My talk at PyCon US 2019

Planet Python - Fri, 2019-05-17 23:04

A couple of weeks back, I gave a talk at PyCon US 2019, “Building reproducible Python applications for secured environments”.

The main idea behind the talk is about the different kind of threats in an application which has dependencies (with regular updates) coming from various upstream projects, and also the final deployable artifact (Debian package in this case) needs to audit-able, and reproducible.

Before my talk on Saturday, I went through the whole idea and different steps we are following, with many of the PyPA (Python Packaging Authority) and other security leads in various organizations.

You can view the talk on Youtube. Feel free to give any feedback over email or Twitter.

Categories: FLOSS Project Planets

Debian XMPP Team: Debian XMPP Team Starts a Blog

Planet Debian - Fri, 2019-05-17 19:30

The Debian XMPP Team, the people who package Dino, Gajim, Mcabber, Movim, Profanity, Prosody, Psi+, Salut à Toi, Taningia, and a couple of other packages related to XMPP a.k.a. Jabber for Debian, have this blog now. We will try to post interesting stuff here — when it's ready!

Categories: FLOSS Project Planets

Palantir: 10 Tips for Publishing Accessible Content

Planet Drupal - Fri, 2019-05-17 19:00
10 Tips for Publishing Accessible Content brandt Fri, 05/17/2019 - 18:00 Alex Brandt May 20, 2019

Content editors can help make the web a more accessible place, one published moment at a time.

Although web accessibility begins on a foundation built by content strategists, designers, and engineers, the buck does not stop there (or at site launch). Content marketers play a huge role in maintaining web accessibility standards as they publish new content over time.

“Web accessibility means that people with disabilities can perceive, understand, navigate, and interact with the Web, and that they can contribute to the Web.” - W3

Why Accessibility Standards are Important to Marketers

Web accessibility standards are often thought to assist audiences who are affected by common disabilities like low vision/blindness, deafness, or limited dexterity. In addition to these audiences, web accessibility also benefits those with a temporary or situational disability. This could include someone who is nursing an injury, someone who is working from a coffee shop with slow wifi, or someone who is in a public space and doesn’t want to become a nuisance to others by playing audio out loud.

Accessibility relies on empathy and understanding of a wide range of user experiences. People perceive your content through different senses depending on their own needs and preferences. If someone isn’t physically seeing the blog post you wrote or can’t hear the audio of the podcast you published, that doesn’t mean you as a marketer don’t care about providing that information to that audience, it just means you need to adapt in the way you are delivering that information to that audience.

10 Tips for Publishing Accessible Content

These tips have been curated and compiled from a handful of different resources including the WCAG standards set forth by W3C, and our team of accessibility gurus at Palantir. All of the informing resources are linked in a handy list at the end of this post. 

1. Consider the type of content and provide meaningful text alternatives.

Text alternatives should help your audience understand the content and context of each image, video, or audio file. It also makes that information accessible to technology that cannot see or hear your content, like search engines (which translates to better SEO).

Types of text alternatives you can provide:

  • Images - Provide alternative text.
  • Audio - Provide transcripts.
  • Video - Provide captions and video descriptions in action.

This tip affects those situational use cases mentioned above as well. Think about the last time you sent out an email newsletter. If someone has images turned off on their email to preserve cellular data, you want to make sure your email still makes sense. Providing a text alternative means your reader still has all of the context they need to understand your email, even without that image.

2. Write proper alt text.

Alternative text or alt text is a brief text description that can be attributed to the HTML tag for an image on a web page. Alt text enables users who cannot see the images on a page to better understand your content. Screen readers and other assistive technology can’t interpret the meaning of an image without alt text.

With the addition of required alternative text, Drupal 8 has made it easier to build accessibility into your publishing workflow. However, content creators still need to be able to write effective alt text. Below I’ve listed a handful of things to consider when writing alt text for your content.

  • Be as descriptive and accurate as possible. Provide context. Especially if your image is serving a specific function, people who don’t see the image should have the same understanding as if they had.
  • If you’re sharing a chart or other data visualization, include that data in the alt text so people have all of the important information.
  • Avoid using “image of,” “picture of,” or something similar. It’s already assumed that the alt text is referencing an image, and you are losing precious character space (most screen readers cut off alt text at around 125 characters). The caveat to this is if you are describing a work of art, like a painting or illustration.
  • No spammy keyword stuffing. Alt text does help with SEO, but that’s not it’s primary purpose, so don’t abuse it. Find that happy medium between including all of the vital information and also including maybe one or two of those keywords you’re trying to target.
Example of good alt text: “Red car in the sky.”
Example of better alt text: “Illustration of red car with flames shooting out of the back, flying over line of cars on sunny roadway.”3. Establish a hierarchy.

Accessibility is more than just making everything on a page available as text. It also affects the way you structure your content, and how you guide your users through a page. When drafting content, put the most important information first. Group similar content, and clearly separate different topics with headings. You want to make sure your ideas are organized in a logical way to improve scannability and encourage better understanding amongst your readers.

4. Use headings, lists, sections, and other structural elements to support your content hierarchy.

Users should be able to quickly assess what information is on a page and how it is organized. Using headings, subheadings and other structural elements helps establish hierarchy and makes web pages easily understandable by both the human eye and a screen reader. Also, when possible, opt for using lists over tables. Tables are ultimately more difficult for screen reader users to navigate.

If you’re curious to see how structured your content is, scan the URL using WAVE, an accessibility tool that allows you to see an outline of the structural elements on any web page. Using WAVE can help you better visualize how someone who is using assistive technologies might be viewing your page.

5. Write a descriptive title for every page.

This one is pretty straight forward. Users should be able to quickly assess the purpose of each page. Screen readers announce the page title when they load a web page, so writing a descriptive title helps those users make more informed page selections.

Page titles impact:

  • Users with low vision who need to be able to easily distinguish between pages
  • Users with cognitive disabilities, limited short-term memory, and reading disabilities.
6. Be intentional with your link text.

Write link text that makes each link’s purpose clear to the user. Links should provide info on where you will end up or what will happen if you click on that link. If someone is using a screen reader to tab through 3 links on a page that all read “click here,” that doesn’t really help them figure out what each link’s purpose is and ultimately decide which link they should click on.

Additional tips:

  • Any contextual information should directly precede links.
  • Don’t use urls as link text; they aren’t informative. A
  • void writing long paragraphs with multiple links. If you have multiple links to share on one topic, it’s better to write a short piece of text followed by a list of bulleted links.

EX: Use "Learn more about our new Federated Search application" not "Learn more".

7. Avoid using images of text in place of actual text.

The exact guideline set forth by W3 here is “Make it easier for users to see and hear content including separating foreground from background.” 

There are many reasons why this is a good practice that reach beyond accessibility implications. Using actual text helps with SEO, allows for on-page search ability for users, and creates the ability to highlight for copy/pasting. There are some exceptions that can be made if the image is essential to include (like a logo). Providing alt text also may be a solution for certain use cases.

8. Avoid idioms, jargon, abbreviations, and other nonliteral words.

The guideline set forth by W3 is to “make text content readable and understandable.” Accessibility aside, this is important for us marketers In the Drupal-world, because it’s really easy to include a plethora of jargon that your client audience might not be familiar with. So be accessible AND client-friendly, and if you have to use jargon or abbreviations, make sure you provide a definition of the word, link to the definition, or include an explanation of any abbreviations on first reference.

Think about it this way: if you are writing in terms people aren’t familiar with, how will they know to search for them? Plain language = better SEO.

9. Create clear content for your audience’s reading level.

For most Americans, the average reading level is a lower secondary education level. Even if you are marketing to a group of savvy individuals who are capable of understanding pretty complicated material, the truth is, most people are pressed for time and might become stressed if they have to read super complicated marketing materials. This is also important to keep in mind for people with cognitive disabilities, or reading disabilities, like dyslexia.

I know what you’re thinking, “but I am selling a complicated service.” If you need to include technical or complicated material to get your point across, then provide supplemental content such as an infographic or illustration, or a bulleted list of key points.

There are a number of tools online that you can use to determine the readability of your content, and WebAIM has a really great resource for guidelines on writing clearly.

10. Clearly label form input elements.

If you are in content marketing, chances are you have built a form or two in your time. No matter whether you’re creating those in Drupal or an external tool like Hubspot, you want to make sure you are labeling form fields clearly so that the user can understand how to complete the form. For example, expected data formats (such as day, month, year) are helpful. Also, required fields should be clearly marked. This is important for accessibility, but also then you as a marketer end up with better data.

Helpful Resources

Here are a few guides I've found useful in the quest to publish accessible content:

Accessibility Tools People
Categories: FLOSS Project Planets

[Some] KDE Applications 19.04.1 also available in flathub

Planet KDE - Fri, 2019-05-17 16:30

Thanks to Nick Richards we've been able to convince flathub to momentarily accept our old appdata files as still valid, it's a stopgap workaround, but at least gives us some breathing time. So the updates are coming in as we speak.

Categories: FLOSS Project Planets

Lullabot: Introducing Support & Maintenance at Lullabot

Planet Drupal - Fri, 2019-05-17 14:33

In our booth during DrupalCon Seattle this year, we had the pleasure of speaking with people in the Drupal community about our new Support & Maintenance offering. The response we heard most often was, “Doesn’t Lullabot already do support and maintenance?” The short answer is yes.

Categories: FLOSS Project Planets

Andre Roberge: Idle hacking - part 1

Planet Python - Fri, 2019-05-17 14:02

  1. File test_py.pyfr.  The pyfr extension indicates that this is written in the "French Python" dialect. Since this is the main file we'll run, it will also automatically set the language to French. This is all done by AvantPy.
  2. "afficher" is the French version of "print"
  3. "import" is the normal Python keyword; we can mix and match keywords from a given dialect with the normal Python ones.  Here, we are importing a module whose base name is "upper".
  4. The constant "a" is defined.
  5. File "upper.pyupper"; the only file whose base name is "upper" - thus, the one that will be imported. The "pyupper" extension indicates that the dialect is an "upper case" version of Python - designed for testing.
  6. The code that will be run when the file is imported.
  7. Output from both files.
  8. "a" is defined.
  9. We made a syntax mistake. However, Friendly-traceback is there to help us understand what went wrong ... picking up the default language to use (French) from that first file that was run.

All this was run with a crudely hacked version of Idle. I'm still confused with the communications done with the RPCServer and the TPCServer, having never looked at similar code before.  So, I haven't been able to make it do all that I wanted in this first hacking session. Hopefully, there will be more to come ...
Categories: FLOSS Project Planets

Hook 42: Drupaldelphia: The Jawn That Never Disappoints

Planet Drupal - Fri, 2019-05-17 09:49
Drupaldelphia: The Jawn That Never Disappoints Lindsey Gemmill Fri, 05/17/2019 - 13:49
Categories: FLOSS Project Planets

myDropWizard.com: Experimental Composer repository with CKEditor plugins

Planet Drupal - Fri, 2019-05-17 09:49

In my experience, a big part of making a Drupal 8 site usable for content editors is customizing the WYSIWYG, which usually includes adding a couple additional CKEditor plugins.

Of course, you can simply download the plugins into the 'libraries' folder, and that's fine. But these days, it's becoming best practice to pull in all of your site's dependencies using Composer.

Adding 'package' repositories to your composer.json for the CKEditor plugins (the current best practice) works fine - but only for your individual site.

It doesn't work so well if you want to install:

  • A Drupal "Feature" (like with the Features module) that configures the WYSIWYG, including adding some CKEditor plugins, or
  • A Drupal distribution (like Panopoly or Lightning)

In those cases, you can't depend on what the individual site may have in its top-level composer.json, and asking the user to manually copy-paste a bunch of 'package' repositories in there may create enough confusion or problems that potential users will just give up.

Well, I've got an possible solution to this problem: an experimental Composer repository which includes CKEditor plugins for use on a Drupal site.

It works better for Feature modules and distributions, but can also make life easier for individual sites too.

Read more to find out how it works and how to use it!

Categories: FLOSS Project Planets

Stack Abuse: Brief Introduction to OpenGL in Python with PyOpenGL

Planet Python - Fri, 2019-05-17 09:36

In this tutorial, we're going to learn how to use PyOpenGL library in Python. OpenGL is a graphics library which is supported by multiple platforms including Windows, Linux, and MacOS, and is available for use in multiple other languages as well; however, the scope of this post will be limited to its usage in the Python programming language.

OpenGL, as compared to other similar graphics libraries, is fairly simple. We'll start with setting it up on our system, followed by writing a simple example demonstrating the usage of the library.


The easiest way to install OpenGL using Python is through the pip package manager. If you have pip installed in your system, run the following command to download and install OpenGL:

$ pip install PyOpenGL PyOpenGL_accelerate

I'd recommend copying the above command to help avoid typos.

Once this command finishes execution, if the installation is successful, you should get the following output at the end:

Successfully installed PyOpenGL-3.1.0 PyOpenGL-accelerate-3.1.0

If this doesn't work, you can also download it manually. For that, this link, scroll down to the 'downloading and installation' heading, and download all the files over there. After that, navigate to the folder where you downloaded those files, and run the following command in the terminal or command prompt:

$ python setup.py

It is pertinent to mention that you require Visual C++ 14.0 build tools installed on your system in order to work with OpenGL libraries in Python.

Now that we have successfully installed OpenGL on our system, let's get our hands dirty with it.

Coding Exercise

The first thing we need to do to use OpenGL in our code is to import it. To do that, run the following command:

import OpenGL

Before we proceed, there are a few other libraries that you need to import whenever you intend to use this library in your program. Below is the code for those imports:

import OpenGL.GL import OpenGL.GLUT import OpenGL.GLU print("Imports successful!") # If you see this printed to the console then installation was successful

Now that we are done with the necessary imports, let's first create a window in which our graphics will be shown. The code for that is given below, along with its explanation in the comments:

def showScreen(): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # Remove everything from screen (i.e. displays all white) glutInit() # Initialize a glut instance which will allow us to customize our window glutInitDisplayMode(GLUT_RGBA) # Set the display mode to be colored glutInitWindowSize(500, 500) # Set the width and height of your window glutInitWindowPosition(0, 0) # Set the position at which this windows should appear wind = glutCreateWindow("OpenGL Coding Practice") # Give your window a title glutDisplayFunc(showScreen) # Tell OpenGL to call the showScreen method continuously glutIdleFunc(showScreen) # Draw any graphics or shapes in the showScreen function at all times glutMainLoop() # Keeps the window created above displaying/running in a loop

Copy the imports above, as well as this code in a single python (.py) file, and execute it. You should see a white square dimension screen pop up. Now, if we wish to draw any shapes or make any other kind of graphics, we need to do that in our "showScreen" function.

Let's now try to make a square using OpenGL, but before we do we need to understand the coordinate system that OpenGL follows.

The (0,0) point is the bottom left of your window, if you go up from there, you're moving along the y-axis, and if you go right from there, you're moving along the x-axis. So, the top left point of your window would be (0, 500), top right would be (500, 500), bottom right would be (500, 0).

Note: We're talking about the window we created above, which had a dimension of 500 x 500 in our example, and not your computer's full screen.

Now that we've got that out of the way, lets code a square. The explanation to the code can be found in the comments.

from OpenGL.GL import * from OpenGL.GLUT import * from OpenGL.GLU import * w, h = 500,500 # ---Section 1--- def square(): # We have to declare the points in this sequence: bottom left, bottom right, top right, top left glBegin(GL_QUADS) # Begin the sketch glVertex2f(100, 100) # Coordinates for the bottom left point glVertex2f(200, 100) # Coordinates for the bottom right point glVertex2f(200, 200) # Coordinates for the top right point glVertex2f(100, 200) # Coordinates for the top left point glEnd() # Mark the end of drawing # This alone isn't enough to draw our square # ---Section 2--- def showScreen(): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # Remove everything from screen (i.e. displays all white) glLoadIdentity() # Reset all graphic/shape's position square() # Draw a square using our function glutSwapBuffers() #---Section 3--- glutInit() glutInitDisplayMode(GLUT_RGBA) # Set the display mode to be colored glutInitWindowSize(500, 500) # Set the w and h of your window glutInitWindowPosition(0, 0) # Set the position at which this windows should appear wind = glutCreateWindow("OpenGL Coding Practice") # Set a window title glutDisplayFunc(showScreen) glutIdleFunc(showScreen) # Keeps the window open glutMainLoop() # Keeps the above created window displaying/running in a loop

Running the code above would draw a square, but that square would not be visible since it's color would be the same as the color of our window, so we need to assign it a different color as well, for that we will make some changes in "Section 2" of the code above i.e. the showScreen function. Add the following line below the glLoadIdentity statement and above the square() statement:

glColor3f(1.0, 0.0, 3.0) # Set the color to pink

However, our code is still not complete. What it currently does is draw the square once, and then clear the screen again. We don't want that. Actually, we won't even be able to spot the moment when it actually draws the square because it would appear and disappear in a split second. Lets write another function to avoid this.

# Add this function before Section 2 of the code above i.e. the showScreen function def iterate(): glViewport(0, 0, 500,500) glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho(0.0, 500, 0.0, 500, 0.0, 1.0) glMatrixMode (GL_MODELVIEW) glLoadIdentity()

Call this iterate function in "Section 2" of the code above. Add it below glLoadIdentity and above the glColor3d statement in the showScreen function.

Let's now compile all this into a single code file so that there are no ambiguities:

from OpenGL.GL import * from OpenGL.GLUT import * from OpenGL.GLU import * w,h= 500,500 def square(): glBegin(GL_QUADS) glVertex2f(100, 100) glVertex2f(200, 100) glVertex2f(200, 200) glVertex2f(100, 200) glEnd() def iterate(): glViewport(0, 0, 500, 500) glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho(0.0, 500, 0.0, 500, 0.0, 1.0) glMatrixMode (GL_MODELVIEW) glLoadIdentity() def showScreen(): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity() iterate() glColor3f(1.0, 0.0, 3.0) square() glutSwapBuffers() glutInit() glutInitDisplayMode(GLUT_RGBA) glutInitWindowSize(500, 500) glutInitWindowPosition(0, 0) wind = glutCreateWindow("OpenGL Coding Practice") glutDisplayFunc(showScreen) glutIdleFunc(showScreen) glutMainLoop()

When you run this, a window should appear with a pink colored square box in it.



In this tutorial, we learned about OpenGL, how to download and install it, followed by using it an a short example program. In this example we also practiced making a basic shape using OpenGL, which gave us an insight into some complex function calls that need to be made whenever we need to draw something using this library. To conclude, OpenGL is very resourceful and gets more and more complex as we dive deeper into it.

Categories: FLOSS Project Planets

Abhijeet Pal: Python Program to Find the Largest Among Three Numbers

Planet Python - Fri, 2019-05-17 09:09
Problem Definition

Create a Python program to find the largest among the three given numbers.

  1. Take inputs from the user and store them in variables
  2. Compare the numbers
  3. Print the final result
  4. End

To understand the program you need to have an understanding of following Python concept.

Program num1 = float(input("Enter first number: ")) num2 = float(input("Enter second number: ")) num3 = float(input("Enter third number: ")) if (num1 > num2) and (num1 > num3): largest = num1 elif (num2 > num1) and (num2 > num3): largest = num2 else: largest = num3 print("The largest number is",largest) Runtime Test Cases Enter first number: 1 Enter second number: 2 Enter third number: 3 The largest number is 3.0

The post Python Program to Find the Largest Among Three Numbers appeared first on Django Central.

Categories: FLOSS Project Planets

Abhijeet Pal: Python program to check if a string is palindrome or not

Planet Python - Fri, 2019-05-17 08:51
Problem Definition

Make a Python program to check if the given string is palindrome or not. A string is a palindrome if it reads same from forward as well as backward for example madam.

  1. Take the input string from the user and store it in a variable
  2. Reverse the string and compare it to the base string
  3. Print the result
  4. End
Program word = input("Enter a number : ") word = word.casefold() if(word == word[: : -1]): print("Palindrome") else: print("Not Palindrome") Runtime Test Cases Enter a number : madam Palindrome Additional Explanation

The casefold() method is used to implement caseless string matching. It is similar to lower() string method but case removes all the case distinctions present in a string. i.e ignore cases when comparing hence this program will work for both the following strings Madam and madam.

The post Python program to check if a string is palindrome or not appeared first on Django Central.

Categories: FLOSS Project Planets