tag:blogger.com,1999:blog-45798008901324414832024-03-18T20:44:26.882-07:00Programmers TrickMohit Patelhttp://www.blogger.com/profile/08269675484730515993noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-4579800890132441483.post-83728200098175995092015-06-28T10:37:00.001-07:002015-06-28T10:42:08.558-07:00How to upload a new template for your blog ?<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<a href="https://www.blogger.com/blogger.g?blogID=4579800890132441483" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="https://www.blogger.com/blogger.g?blogID=4579800890132441483" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="https://www.blogger.com/blogger.g?blogID=4579800890132441483" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><b style="outline: 0px;"><span style="border: none windowtext 1.0pt; mso-border-alt: none windowtext 0in; padding: 0in;">Instructions for how to install them!</span></b><span style="font-size: 12pt; line-height: 115%;"><br />
<a href="https://www.blogger.com/blogger.g?blogID=4579800890132441483" name="more"></a><br />
<span style="background: white;">Up
until fairly recently there was a problem with uploading a template through the
new interface. It seems that what was happening was that if you had widgets
installed in your site, that weren't in the template that you were uploading,
the interface didn't quite know what to do with them so it threw an error
message. It seems as if this issue has been fixed, but if you run into this
problem, the way to get around it is by switching to the old interface by
clicking on the gear icon in the top right corner. You can always switch back,
but this seems to be a good workaround.</span><br />
<br /><b style="outline: 0px;"><span style="background: white; border: none windowtext 1.0pt; mso-border-alt: none windowtext 0in; padding: 0in;">1: Download your new
template</span></b><br />
<br />
<span style="background: white;">You
can download templates from anywhere, they just need to be written for Blogger,
have the necessary elements, and be valid/strict XML format. Download the
provided XML file and save it to your desktop (or other easy-to-find location).</span><br />
<br /><b style="outline: 0px;"><span style="background: white; border: none windowtext 1.0pt; mso-border-alt: none windowtext 0in; padding: 0in;">2: Make a backup!<o:p></o:p></span></b></span></div>
<div class="MsoNormal">
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<span style="font-size: 12pt; line-height: 115%;"><b style="outline: 0px;"><span style="background: white; border: none windowtext 1.0pt; mso-border-alt: none windowtext 0in; padding: 0in;"><br /></span></b></span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-size: 12pt; line-height: 115%; margin-left: 1em; margin-right: 1em;"><!--[if gte vml 1]><v:shapetype id="_x0000_t75"
coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe"
filled="f" stroked="f">
<v:stroke joinstyle="miter"/>
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0"/>
<v:f eqn="sum @0 1 0"/>
<v:f eqn="sum 0 0 @1"/>
<v:f eqn="prod @2 1 2"/>
<v:f eqn="prod @3 21600 pixelWidth"/>
<v:f eqn="prod @3 21600 pixelHeight"/>
<v:f eqn="sum @0 0 1"/>
<v:f eqn="prod @6 1 2"/>
<v:f eqn="prod @7 21600 pixelWidth"/>
<v:f eqn="sum @8 21600 0"/>
<v:f eqn="prod @7 21600 pixelHeight"/>
<v:f eqn="sum @10 21600 0"/>
</v:formulas>
<v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/>
<o:lock v:ext="edit" aspectratio="t"/>
</v:shapetype><v:shape id="Picture_x0020_3" o:spid="_x0000_i1026" type="#_x0000_t75"
alt="Description: L:\Blog\Image\ProgrammersTrick.blogspot.com - upload template.png"
style='width:300pt;height:83.25pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\RAIYAR~1\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png"
o:title="ProgrammersTrick.blogspot.com - upload template"/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--></span></div>
<div class="MsoNormal">
<span style="font-size: 12.0pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfUppI6QGcm0pmfrUGyAr5T6g1x7dw6yi_8B1CMbz9sTAdPRs5JmgI4KMq0SovqCQjEpQ3F_CBD0mQRiSCPuID_OYiqPlrOFB9ymHWoLaR4buQUtPtvKAQ26BZwn0zC2wb3InXX8YAh-ph/s1600/ProgrammersTrick.blogspot.com+-+upload+template.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="110" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfUppI6QGcm0pmfrUGyAr5T6g1x7dw6yi_8B1CMbz9sTAdPRs5JmgI4KMq0SovqCQjEpQ3F_CBD0mQRiSCPuID_OYiqPlrOFB9ymHWoLaR4buQUtPtvKAQ26BZwn0zC2wb3InXX8YAh-ph/s400/ProgrammersTrick.blogspot.com+-+upload+template.png" width="400" /></a></div>
<br /></div>
<div class="MsoNormal">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-size: 12pt; line-height: 115%;">Head to your Blogger dashboard page and click on<span class="apple-converted-space"> </span></span><u>Template</u><span class="apple-converted-space"> in
the navigation column. In the top right you'll see a button that says
"Backup / Restore"; click on that button. An overlay window will show
up with two options, one for downloading a backup and one for uploading a
template. See that big orange button that says "download full
template"?<span class="apple-converted-space"> </span></span><b style="outline: 0px;"><i style="background-position: initial initial; background-repeat: initial initial; outline: 0px;"><span style="border: 1pt none windowtext; font-size: 12pt; line-height: 115%; padding: 0in;">Click on it!</span></i></b><span style="font-size: 12pt; line-height: 115%;"><br />
<br />
<span style="background: white;">Save
the provided XML file somewhere on your computer. You will need this if it
turns out you don't like the new template and want to revert back; there is no
other way to revert back! I also recommend adding the date into your template
file's name so that you can revert back to a version of your template if you
need to (this is assuming you're not using any kind of version/source control,
if so don't worry about this). You might save the file with a name such as
template-2012-09-08.xml as an example.<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-size: 12pt; line-height: 115%;"><span style="background: white;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="background-color: white; font-size: 12pt; line-height: 115%; margin-left: 1em; margin-right: 1em;"><!--[if gte vml 1]><v:shape
id="Picture_x0020_4" o:spid="_x0000_i1025" type="#_x0000_t75" alt="Description: L:\Blog\Image\ProgrammersTrick.blogspot.com - upload template 2.png"
style='width:300pt;height:130.5pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\RAIYAR~1\AppData\Local\Temp\msohtmlclip1\01\clip_image002.png"
o:title="ProgrammersTrick.blogspot.com - upload template 2"/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--></span><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpAz-M3mHXJNszhzN636-5ShHxQemJ_6S9UipHV_lmy6u9jHrRuoHCCIVz_1hbZcNdVMy0UCiuPJ5JkoZ4OylMLl8YTIXScKTJXyfvLuvT18AUQKiPfLodCI5DK13q28K8CGOpgkmVG7lU/s1600/ProgrammersTrick.blogspot.com+-+upload+template+2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="173" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpAz-M3mHXJNszhzN636-5ShHxQemJ_6S9UipHV_lmy6u9jHrRuoHCCIVz_1hbZcNdVMy0UCiuPJ5JkoZ4OylMLl8YTIXScKTJXyfvLuvT18AUQKiPfLodCI5DK13q28K8CGOpgkmVG7lU/s400/ProgrammersTrick.blogspot.com+-+upload+template+2.png" width="400" /></a></div>
<div class="MsoNormal">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-size: 12pt; line-height: 115%;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal">
<b><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; border: 1pt none windowtext; font-size: 12pt; line-height: 115%; padding: 0in;"><br />3: Install the template</span></b><span style="font-size: 12pt; line-height: 115%;"><br />
<br />
<span style="background: white;">Once
you've saved a copy of your existing template, use the second option in that
overlay window by clicking on the "browse" button. Use the finder to
select the new template from your desktop (or wherever you saved it in Step
#1), then click on the orange "Upload" button.</span><br />
<br /><span style="background: white;">Your new template should be installed!<span class="apple-converted-space"> </span><o:p></o:p></span></span></div>
</div>
Mohit Patelhttp://www.blogger.com/profile/08269675484730515993noreply@blogger.com0tag:blogger.com,1999:blog-4579800890132441483.post-87194288955699805442015-06-28T10:23:00.001-07:002015-06-28T10:24:56.037-07:00How to converting your blog Posts in to a book ?<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="margin-bottom: .0001pt; margin: 0in;">
<span style="font-family: Calibri, sans-serif;">I
am always up for a new challenge. This post is posted by me (<span class="apple-converted-space"> </span><a href="https://www.facebook.com/RaiyarajOfficial" target="_blank"><span style="color: #3d85c6;">Mohit Raiyani</span></a><span class="apple-converted-space"> </span>) and i am wanted to transform my blog
into a book.<o:p></o:p></span></div>
<div style="margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="margin: 0in 0in 0.0001pt;">
<b><span style="font-family: Calibri, sans-serif;">1 Getting an export of your blog's
contants :</span></b><span style="font-family: Calibri, sans-serif;"><o:p></o:p></span></div>
<div style="margin: 0in 0in 0.0001pt;">
<span style="font-family: Calibri, sans-serif;">
→ <span style="background: white;">The best way to get
all of your content out of Blogger is by using a site called the </span><span style="background: white; color: #3d85c6; text-decoration: none; text-underline: none;"><a href="http://www.dataliberation.org/home" target="_blank">Data
Liberation Front</a>. </span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; text-decoration: none;">Now you</span></span><span style="font-family: Calibri, sans-serif;"><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; color: #3d85c6;"> </span><span style="background: white;"> </span></span><span style="color: #558ed5; font-family: Calibri, sans-serif;"><a href="https://www.google.com/takeout/#custom:blogger" target="_blank"><span style="background: white; color: #558ed5; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #558ED5; mso-style-textfill-fill-colortransforms: "lumm=60000 lumo=40000"; mso-style-textfill-fill-themecolor: text2; mso-themecolor: text2; mso-themetint: 153; text-decoration: none; text-underline: none;">Go here</span></a></span><span style="background-color: white; font-family: Calibri, sans-serif;"> to grab
your content out of one of your blogs (by clicking on Configure then Create
Archive). You will receive a ZIP file from this export which contains a file
inside such as YourBlogName.atom.</span></div>
<div style="margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="margin: 0in 0in 0.0001pt;">
<b style="outline: 0px;"><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; border: 1pt none windowtext; font-family: Calibri, sans-serif; padding: 0in;">2 Rename the file</span></b><span style="font-family: Calibri, sans-serif;"><br />
→ <span style="background: white;">Open up the
ZIP file and drag the YourBlogName.atom file into a folder on your desktop. Rename
the file from YourBlogName.atom to YourBlogName.xml</span><br />
<br />
<b style="outline: 0px;"><span style="background: white; border: none windowtext 1.0pt; mso-border-alt: none windowtext 0in; padding: 0in;">3 Download the style sheet and xsl template</span></b><br />
→ <span style="background: white;">Download </span></span><span style="color: #558ed5; font-family: "Calibri","sans-serif"; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #558ED5; mso-style-textfill-fill-colortransforms: "lumm=60000 lumo=40000"; mso-style-textfill-fill-themecolor: text2; mso-themecolor: text2; mso-themetint: 153;"><a href="https://www.dropbox.com/s/z0e95c3c089ribr/style.css" target="_blank"><span style="background: white; color: #558ed5; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #558ED5; mso-style-textfill-fill-colortransforms: "lumm=60000 lumo=40000"; mso-style-textfill-fill-themecolor: text2; mso-themecolor: text2; mso-themetint: 153; text-decoration: none; text-underline: none;">this style sheet</span></a></span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Calibri, sans-serif;"> and </span><span style="color: #558ed5; font-family: "Calibri","sans-serif"; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #558ED5; mso-style-textfill-fill-colortransforms: "lumm=60000 lumo=40000"; mso-style-textfill-fill-themecolor: text2; mso-themecolor: text2; mso-themetint: 153;"><a href="https://www.dropbox.com/s/15nncww2zp2spdv/transform.xsl" target="_blank"><span style="background: white; color: #558ed5; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #558ED5; mso-style-textfill-fill-colortransforms: "lumm=60000 lumo=40000"; mso-style-textfill-fill-themecolor: text2; mso-themecolor: text2; mso-themetint: 153; text-decoration: none; text-underline: none;">this XSL template</span></a></span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Calibri, sans-serif;"> and save
them in the same directory with your new YourBlogName.xml file.</span><span style="font-family: Calibri, sans-serif;"><br />
<br />
<b style="outline: 0px;"><span style="background: white; border: none windowtext 1.0pt; mso-border-alt: none windowtext 0in; padding: 0in;">4 Edit
one line in the XML file in a text editor</span></b><br />
→ <span style="background: white;">Open the XML
file in a text editor and change:</span><br />
<span style="background: white; border: none windowtext 1.0pt; mso-border-alt: none windowtext 0in; padding: 0in;"> <span style="outline: 0px;"><?xml-stylesheet
href="http://www.blogger.com/styles/atom.css"
type="text/css"?></span></span><br />
<span style="background: white;"> to
be</span><br />
<span style="background: white; border: none windowtext 1.0pt; mso-border-alt: none windowtext 0in; padding: 0in;"> <span style="outline: 0px;"><?xml-stylesheet href="transform.xsl"
type="text/xsl"?></span></span><br />
<br />
<b style="outline: 0px;"><span style="background: white; border: none windowtext 1.0pt; mso-border-alt: none windowtext 0in; padding: 0in;">5 Drag
the XML file into either the Safari or Internet Explorer browsers</span></b><br />
→ <span style="background: white;">Yes, Safari
browser or Internet Explorer browser. Chrome and Firefox might try to apply
their own default styling to the XML file, so it works beset in these other two
browsers.</span><br />
<br />
<br />
→ <span style="background: white;">The XSL file
we've set up is set to do the following transformation:</span><br />
<span style="background: white;"> <h1>Post
title</h1></span><br />
<span style="background: white;"> <h2>Post
author</h2></span><br />
<span style="background: white;"> <h3>Post
date</h3></span><br />
<span style="background: white;"> Blog
post content</span><br />
<br />
→ <span style="background: white;">It does this
in reverse order, so it's going from Oldest to Newest posts. If you'd like you
can change this to be ascending in the XSL file, and you can add more to the
XSL file if you'd like to bring in comments, but we figure this is enough for
most. It will also load in external images for the blog posts.</span><br />
<br />
<br />
<b style="outline: 0px;"><span style="background: white; border: none windowtext 1.0pt; mso-border-alt: none windowtext 0in; padding: 0in;">6 Select
all and copy paste into Word</span></b><br />
→ <span style="background: white;">This might be
a bit tough depending on how big your blog is, but we were able to do a 12 meg
blog archive pretty easily. Simply select all, copy, then open a new Word
document and hit paste. You might need to wait a bit, but it will work.</span><br />
<br />
<b style="outline: 0px;"><span style="background: white; border: none windowtext 1.0pt; mso-border-alt: none windowtext 0in; padding: 0in;">7 Save
the Word document</span></b><br />
→ <span style="background: white;">Save the
document before you start working on it! Once saved, you can edit to your
heart's content, resizing images, moving them around, reformatting...
everything. Links and images are all preserved as well as much of the
formatting.</span><o:p></o:p></span></div>
<div style="margin-bottom: .0001pt; margin: 0in;">
</div>
<div class="MsoNormal">
<br /></div>
</div>
Mohit Patelhttp://www.blogger.com/profile/08269675484730515993noreply@blogger.com0tag:blogger.com,1999:blog-4579800890132441483.post-74168174903473217122015-06-28T09:31:00.001-07:002015-06-28T09:47:10.757-07:00Responsive JS / CSS Animated Menu for Responsive Website<div dir="ltr" style="text-align: left;" trbidi="on">
We working on a website and developing toggle menu for Responsive website design only.<br />
<br />
<span style="background-color: white; font-family: kulturista-web, georgia, serif; font-size: 14px; line-height: 18px;">Demo here.</span><br />
<div id="toggle" style="background-color: white; border: 0px; cursor: pointer; font-family: kulturista-web, georgia, serif; font-size: 14px; height: 45px; line-height: 18px; margin: 0px; outline: 0px; padding: 0px; position: absolute; vertical-align: baseline; width: 45px;">
<span class="ham-bar ham-bar-one" style="-webkit-transform: translateY(0px) rotateZ(0deg); -webkit-transition: all 0.4s; background-clip: padding-box; background-color: #74c3f0; background-position: initial initial; background-repeat: initial initial; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; border: 0px; height: 4px; left: 0px; letter-spacing: 0px; margin: 0px; outline: 0px; padding: 0px; position: absolute; top: 12px; transition: all 0.4s; vertical-align: baseline; width: 39px;"></span><br />
<span class="ham-bar ham-bar-two" style="-webkit-transition: all 0.4s; background-clip: padding-box; background-color: #74c3f0; background-position: initial initial; background-repeat: initial initial; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; border: 0px; display: inline; height: 4px; left: 0px; letter-spacing: 0px; margin: 0px; opacity: 1; outline: 0px; padding: 0px; position: absolute; top: 21px; transition: all 0.4s; vertical-align: baseline; width: 39px;"></span><br />
<span class="ham-bar ham-bar-three" style="-webkit-transform: translateY(0px) rotateZ(0deg); -webkit-transition: all 0.4s; background-clip: padding-box; background-color: #74c3f0; background-position: initial initial; background-repeat: initial initial; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; border: 0px; height: 4px; left: 0px; letter-spacing: 0px; margin: 0px; outline: 0px; padding: 0px; position: absolute; top: 30px; transition: all 0.4s; vertical-align: baseline; width: 39px;"></span></div>
<br style="background-color: white; font-family: kulturista-web, georgia, serif; font-size: 14px; line-height: 18px;" />
<br />
<br />
Source Code || <a href="http://pastie.org/pastes/10263204/download" target="_blank">Download Here</a><br />
<br />
<div class="allcode" style="background-color: white; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; overflow: auto; width: 645.96875px;">
<table border="0" cellpadding="0" cellspacing="0" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; position: relative; z-index: 100;"><tbody>
<tr><td style="vertical-align: top;"><pre class="textmate-source" style="font-family: 'Bitstream Vera Sans Mono', Monaco, Consolas, 'Courier New', monospace; font-size: 9pt; line-height: 1.3em; margin-top: 0em;"><pre class="sunburst" style="font-family: 'Bitstream Vera Sans Mono', Monaco, Consolas, 'Courier New', monospace; font-size: 9pt; line-height: 1.3em; margin-top: 0em;"><span class="source source_css source_css_embedded source_css_embedded_html"><<span class="entity entity_name entity_name_tag entity_name_tag_style entity_name_tag_style_html" style="color: #880000;">style</span>>
<span class="meta meta_selector meta_selector_css"><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_id entity_other_attribute-name_id_css" style="color: #880000;">#toggle</span> </span><span class="source source_smarty source_smarty_embedded source_smarty_embedded_html">{
position: absolute;
height: 45px;
width: 45px;
cursor: pointer;
}</span><span class="meta meta_selector meta_selector_css"> <span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_id entity_other_attribute-name_id_css" style="color: #880000;">#toggle</span> <span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css" style="color: #880000;">.ham-bar</span> </span><span class="source source_smarty source_smarty_embedded source_smarty_embedded_html">{
position: absolute;
left: 0;
height: 4px;
width: 39px;
margin: 0;
background-color: #74c3f0;
border-radius: 0;
background-clip: padding-box;
-webkit-transition: all 0.4s;
-moz-transition: all 0.4s;
-o-transition: all 0.4s;
transition: all 0.4s;
}</span><span class="meta meta_selector meta_selector_css"> <span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_id entity_other_attribute-name_id_css" style="color: #880000;">#toggle</span> <span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css" style="color: #880000;">.ham-bar</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css" style="color: #880000;">.ham-bar-one</span> </span><span class="source source_smarty source_smarty_embedded source_smarty_embedded_html">{
top: 12px;
transform: translateY(0px) rotateZ(0deg);
-ms-transform: translateY(0px) rotateZ(0deg);
-webkit-transform: translateY(0px) rotateZ(0deg);
-moz-transform: translateY(0px) rotateZ(0deg);
-o-transform: translateY(0px) rotateZ(0deg);
}</span><span class="meta meta_selector meta_selector_css"> <span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_id entity_other_attribute-name_id_css" style="color: #880000;">#toggle</span> <span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css" style="color: #880000;">.ham-bar</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css" style="color: #880000;">.ham-bar-two</span> </span><span class="source source_smarty source_smarty_embedded source_smarty_embedded_html">{
top: 21px;
opacity: 1;
display: inline;
}</span><span class="meta meta_selector meta_selector_css"> <span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_id entity_other_attribute-name_id_css" style="color: #880000;">#toggle</span> <span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css" style="color: #880000;">.ham-bar</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css" style="color: #880000;">.ham-bar-three</span> </span><span class="source source_smarty source_smarty_embedded source_smarty_embedded_html">{
top: 30px;
transform: translateY(0px) rotateZ(0deg);
-ms-transform: translateY(0px) rotateZ(0deg);
-webkit-transform: translateY(0px) rotateZ(0deg);
-moz-transform: translateY(0px) rotateZ(0deg);
-o-transform: translateY(0px) rotateZ(0deg);
}</span><span class="meta meta_selector meta_selector_css"> <span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_id entity_other_attribute-name_id_css" style="color: #880000;">#toggle</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css" style="color: #880000;">.crisscross</span> <span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css" style="color: #880000;">.ham-bar</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css" style="color: #880000;">.ham-bar-one</span> </span><span class="source source_smarty source_smarty_embedded source_smarty_embedded_html">{
transform: translateY(9px) rotateZ(45deg);
-ms-transform: translateY(9px) rotateZ(45deg);
-webkit-transform: translateY(9px) rotateZ(45deg);
-moz-transform: translateY(9px) rotateZ(45deg);
-o-transform: translateY(9px) rotateZ(45deg);
}</span><span class="meta meta_selector meta_selector_css"> <span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_id entity_other_attribute-name_id_css" style="color: #880000;">#toggle</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css" style="color: #880000;">.crisscross</span> <span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css" style="color: #880000;">.ham-bar</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css" style="color: #880000;">.ham-bar-two</span> </span><span class="source source_smarty source_smarty_embedded source_smarty_embedded_html">{
opacity: 0;
display: none;
}</span><span class="meta meta_selector meta_selector_css"> <span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_id entity_other_attribute-name_id_css" style="color: #880000;">#toggle</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css" style="color: #880000;">.crisscross</span> <span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css" style="color: #880000;">.ham-bar</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css" style="color: #880000;">.ham-bar-three</span> </span><span class="source source_smarty source_smarty_embedded source_smarty_embedded_html">{
transform: translateY(-9px) rotateZ(-45deg);
-ms-transform: translateY(-9px) rotateZ(-45deg);
-webkit-transform: translateY(-9px) rotateZ(-45deg);
-moz-transform: translateY(-9px) rotateZ(-45deg);
-o-transform: translateY(-9px) rotateZ(-45deg);
}</span>
</<span class="entity entity_name entity_name_tag entity_name_tag_style entity_name_tag_style_html" style="color: #880000;">style</span>></span>
<span class="source source_js source_js_embedded source_js_embedded_html"><<span class="entity entity_name entity_name_tag entity_name_tag_script entity_name_tag_script_html" style="color: #880000;">script</span> <span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_html" style="color: #880000;">type</span>=<span class="string string_quoted string_quoted_single string_quoted_single_html">'text/javascript'</span>><span class="comment comment_line comment_line_double-slash comment_line_double-slash_js" style="color: #777777;">//<![CDATA[</span>
<span class="comment comment_line comment_line_double-slash comment_line_double-slash_js" style="color: #777777;">
</span></span></pre>
<pre class="sunburst" style="font-family: 'Bitstream Vera Sans Mono', Monaco, Consolas, 'Courier New', monospace; font-size: 9pt; line-height: 1.3em; margin-top: 0em;"><span class="source source_js source_js_embedded source_js_embedded_html"><span class="comment comment_line comment_line_double-slash comment_line_double-slash_js" style="color: #777777;">// this uses JQuery since we're assuming most sites use it, </span></span></pre>
<pre class="sunburst" style="font-family: 'Bitstream Vera Sans Mono', Monaco, Consolas, 'Courier New', monospace; font-size: 9pt; line-height: 1.3em; margin-top: 0em;"><span class="source source_js source_js_embedded source_js_embedded_html"><span class="comment comment_line comment_line_double-slash comment_line_double-slash_js" style="color: #777777;">//but can easily be changed to use any other identifier</span></span></pre>
<pre class="sunburst" style="font-family: 'Bitstream Vera Sans Mono', Monaco, Consolas, 'Courier New', monospace; font-size: 9pt; line-height: 1.3em; margin-top: 0em;"><span class="source source_js source_js_embedded source_js_embedded_html">
<span class="keyword keyword_operator keyword_operator_js" style="color: #008800;">$</span><span class="meta meta_brace meta_brace_round meta_brace_round_js">(</span><span class="string string_quoted string_quoted_single string_quoted_single_js">'#toggle'</span><span class="meta meta_brace meta_brace_round meta_brace_round_js">)</span><span class="meta meta_delimiter meta_delimiter_method meta_delimiter_method_period meta_delimiter_method_period_js">.</span><span class="support support_function support_function_dom support_function_dom_js">click</span><span class="meta meta_brace meta_brace_round meta_brace_round_js">(</span><span class="storage storage_type storage_type_js">function</span><span class="meta meta_brace meta_brace_round meta_brace_round_js">(</span><span class="meta meta_brace meta_brace_round meta_brace_round_js">)</span> <span class="meta meta_brace meta_brace_curly meta_brace_curly_js">{</span>
<span class="keyword keyword_operator keyword_operator_js" style="color: #008800;">$</span><span class="meta meta_brace meta_brace_round meta_brace_round_js">(</span><span class="string string_quoted string_quoted_single string_quoted_single_js">'#toggle'</span><span class="meta meta_brace meta_brace_round meta_brace_round_js">)</span><span class="meta meta_delimiter meta_delimiter_method meta_delimiter_method_period meta_delimiter_method_period_js">.</span>toggleClass<span class="meta meta_brace meta_brace_round meta_brace_round_js">(</span><span class="string string_quoted string_quoted_double string_quoted_double_js">"crisscross"</span><span class="meta meta_brace meta_brace_round meta_brace_round_js">)</span>;
<span class="meta meta_brace meta_brace_curly meta_brace_curly_js">}</span><span class="meta meta_brace meta_brace_round meta_brace_round_js">)</span>;
<span class="comment comment_line comment_line_double-slash comment_line_double-slash_js" style="color: #777777;">//]]></span></<span class="entity entity_name entity_name_tag entity_name_tag_script entity_name_tag_script_html" style="color: #880000;">script</span>></span>
<span class="meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html"><<span class="entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html" style="color: #880000;">div</span> <span class="meta meta_attribute-with-value meta_attribute-with-value_id meta_attribute-with-value_id_html"><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_id entity_other_attribute-name_id_html" style="color: #880000;">id</span>=<span class="string string_quoted string_quoted_double string_quoted_double_html">"<span class="meta meta_toc-list meta_toc-list_id meta_toc-list_id_html">toggle</span>"</span></span>></span>
<span class="meta meta_tag meta_tag_any meta_tag_any_html"><<span class="entity entity_name entity_name_tag entity_name_tag_html" style="color: #880000;">span</span> <span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_html" style="color: #880000;">class</span>=<span class="string string_quoted string_quoted_double string_quoted_double_html">"ham-bar ham-bar-one"</span>><span class="meta meta_scope meta_scope_between-tag-pair meta_scope_between-tag-pair_html"><</span>/<span class="entity entity_name entity_name_tag entity_name_tag_html" style="color: #880000;">span</span>></span>
<span class="meta meta_tag meta_tag_any meta_tag_any_html"><<span class="entity entity_name entity_name_tag entity_name_tag_html" style="color: #880000;">span</span> <span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_html" style="color: #880000;">class</span>=<span class="string string_quoted string_quoted_double string_quoted_double_html">"ham-bar ham-bar-two"</span>><span class="meta meta_scope meta_scope_between-tag-pair meta_scope_between-tag-pair_html"><</span>/<span class="entity entity_name entity_name_tag entity_name_tag_html" style="color: #880000;">span</span>></span>
<span class="meta meta_tag meta_tag_any meta_tag_any_html"><<span class="entity entity_name entity_name_tag entity_name_tag_html" style="color: #880000;">span</span> <span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_html" style="color: #880000;">class</span>=<span class="string string_quoted string_quoted_double string_quoted_double_html">"ham-bar ham-bar-three"</span>><span class="meta meta_scope meta_scope_between-tag-pair meta_scope_between-tag-pair_html"><</span>/<span class="entity entity_name entity_name_tag entity_name_tag_html" style="color: #880000;">span</span>></span>
<span class="meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html"></<span class="entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html" style="color: #880000;">div</span>></span>
</pre>
<div>
<span class="meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html">
</span></div>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
<br />
<br />
<br />
<br />
<br /></div>
Mohit Patelhttp://www.blogger.com/profile/08269675484730515993noreply@blogger.com0tag:blogger.com,1999:blog-4579800890132441483.post-1534284290701285752015-06-26T01:12:00.002-07:002015-06-28T10:47:18.179-07:00Python : A Calculator<div dir="ltr" style="text-align: left;" trbidi="on">
<div>
<ul style="text-align: left;">
<li>How to Make a Calculator in Python ?</li>
<li>Calculator Application in Python ?</li>
<li>Source code of Calculator</li>
</ul>
</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div style="margin-left: 1em; margin-right: 1em;">
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlp8owrvifQM3f09rJ-Cw44TUHPU2IB26PcHoZ0CAq3_NayLY_06J97TP-AjFy9A7peOQrmHBqerWW5G8xLDK92Rq-hLiZS-UiIDKqlGTRwONJEaV6BcmYW3dOWWCxhEQuLAfqBsTXADRf/s1600/ProgrammersTrick.blogspot.com+-+Python+calculator.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlp8owrvifQM3f09rJ-Cw44TUHPU2IB26PcHoZ0CAq3_NayLY_06J97TP-AjFy9A7peOQrmHBqerWW5G8xLDK92Rq-hLiZS-UiIDKqlGTRwONJEaV6BcmYW3dOWWCxhEQuLAfqBsTXADRf/s400/ProgrammersTrick.blogspot.com+-+Python+calculator.png" width="187" /></a></div>
</div>
<a href="https://www.blogger.com/blogger.g?blogID=4579800890132441483" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="https://www.blogger.com/blogger.g?blogID=4579800890132441483" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="https://www.blogger.com/blogger.g?blogID=4579800890132441483" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<br />
<br />
Python Calculator Source Code :<br />
<br />
<pre style="background-color: whitesmoke; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgb(204, 204, 204); box-sizing: border-box; color: #333333; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; line-height: 1.42857143; margin-bottom: 10px; overflow: auto; padding: 9.5px; word-break: break-all; word-wrap: break-word;">from Tkinter <span style="box-sizing: border-box; color: #7f0055;"><span style="box-sizing: border-box; font-weight: 700;">import</span></span> *
<span style="box-sizing: border-box; color: #7f0055;"><span style="box-sizing: border-box; font-weight: 700;">import</span></span> Pmw, string
<span style="box-sizing: border-box; color: #7f0055;"><span style="box-sizing: border-box; font-weight: 700;">class</span></span> SLabel(Frame):
<span style="box-sizing: border-box; color: #2a00ff;">""</span>" SLabel defines a 2-sided label within a Frame. The
left hand label has blue letters the right has white letters <span style="box-sizing: border-box; color: #2a00ff;">""</span>"
def __init__(self, master, leftl, rightl):
Frame.__init__(self, master, bg=<span style="box-sizing: border-box; color: #2a00ff;">'gray40'</span>)
self.pack(side=LEFT, expand=YES, fill=BOTH)
Label(self, text=leftl, fg=<span style="box-sizing: border-box; color: #2a00ff;">'steelblue1'</span>,
font=(<span style="box-sizing: border-box; color: #2a00ff;">"arial"</span>, 6, <span style="box-sizing: border-box; color: #2a00ff;">"bold"</span>), width=5, bg=<span style="box-sizing: border-box; color: #2a00ff;">'gray40'</span>).pack(
side=LEFT, expand=YES, fill=BOTH)
Label(self, text=rightl, fg=<span style="box-sizing: border-box; color: #2a00ff;">'white'</span>,
font=(<span style="box-sizing: border-box; color: #2a00ff;">"arial"</span>, 6, <span style="box-sizing: border-box; color: #2a00ff;">"bold"</span>), width=1, bg=<span style="box-sizing: border-box; color: #2a00ff;">'gray40'</span>).pack(
side=RIGHT, expand=YES, fill=BOTH)
<span style="box-sizing: border-box; color: #7f0055;"><span style="box-sizing: border-box; font-weight: 700;">class</span></span> Key(Button):
def __init__(self, master, font=(<span style="box-sizing: border-box; color: #2a00ff;">'arial'</span>, 8, <span style="box-sizing: border-box; color: #2a00ff;">'bold'</span>),
fg=<span style="box-sizing: border-box; color: #2a00ff;">'white'</span>,width=5, borderwidth=5, **kw):
kw[<span style="box-sizing: border-box; color: #2a00ff;">'font'</span>] = font
kw[<span style="box-sizing: border-box; color: #2a00ff;">'fg'</span>] = fg
kw[<span style="box-sizing: border-box; color: #2a00ff;">'width'</span>] = width
kw[<span style="box-sizing: border-box; color: #2a00ff;">'borderwidth'</span>] = borderwidth
apply(Button.__init__, (self, master), kw)
self.pack(side=LEFT, expand=NO, fill=NONE)
<span style="box-sizing: border-box; color: #7f0055;"><span style="box-sizing: border-box; font-weight: 700;">class</span></span> Calculator(Frame):
def __init__(self, parent=None):
Frame.__init__(self, bg=<span style="box-sizing: border-box; color: #2a00ff;">'gray40'</span>)
self.pack(expand=YES, fill=BOTH)
self.master.title(<span style="box-sizing: border-box; color: #2a00ff;">'Tkinter Toolkit TT-42'</span>)
self.master.iconname(<span style="box-sizing: border-box; color: #2a00ff;">'Tk-42'</span>)
self.calc = Evaluator() # This is our evaluator
self.buildCalculator() # Build the widgets
# This is an incomplete dictionary - a good exercise!
self.actionDict = {<span style="box-sizing: border-box; color: #2a00ff;">'second'</span>: self.doThis, <span style="box-sizing: border-box; color: #2a00ff;">'mode'</span>: self.doThis,
<span style="box-sizing: border-box; color: #2a00ff;">'delete'</span>: self.doThis, <span style="box-sizing: border-box; color: #2a00ff;">'alpha'</span>: self.doThis,
<span style="box-sizing: border-box; color: #2a00ff;">'stat'</span>: self.doThis, <span style="box-sizing: border-box; color: #2a00ff;">'math'</span>: self.doThis,
<span style="box-sizing: border-box; color: #2a00ff;">'matrix'</span>: self.doThis, <span style="box-sizing: border-box; color: #2a00ff;">'program'</span>: self.doThis,
<span style="box-sizing: border-box; color: #2a00ff;">'vars'</span>: self.doThis, <span style="box-sizing: border-box; color: #2a00ff;">'clear'</span>: self.clearall,
<span style="box-sizing: border-box; color: #2a00ff;">'sin'</span>: self.doThis, <span style="box-sizing: border-box; color: #2a00ff;">'cos'</span>: self.doThis,
<span style="box-sizing: border-box; color: #2a00ff;">'tan'</span>: self.doThis, <span style="box-sizing: border-box; color: #2a00ff;">'up'</span>: self.doThis,
<span style="box-sizing: border-box; color: #2a00ff;">'X1'</span>: self.doThis, <span style="box-sizing: border-box; color: #2a00ff;">'X2'</span>: self.doThis,
<span style="box-sizing: border-box; color: #2a00ff;">'log'</span>: self.doThis, <span style="box-sizing: border-box; color: #2a00ff;">'ln'</span>: self.doThis,
<span style="box-sizing: border-box; color: #2a00ff;">'store'</span>: self.doThis, <span style="box-sizing: border-box; color: #2a00ff;">'off'</span>: self.turnoff,
<span style="box-sizing: border-box; color: #2a00ff;">'neg'</span>: self.doThis, <span style="box-sizing: border-box; color: #2a00ff;">'enter'</span>: self.doEnter,
}
self.current = <span style="box-sizing: border-box; color: #2a00ff;">""</span>
def doThis(self,action):
print <span style="box-sizing: border-box; color: #2a00ff;">'"%s" has not been implemented'</span> % action
def turnoff(self, *args):
self.quit()
def clearall(self, *args):
self.current = <span style="box-sizing: border-box; color: #2a00ff;">""</span>
self.display.component(<span style="box-sizing: border-box; color: #2a00ff;">'text'</span>).delete(1.0, END)
def doEnter(self, *args):
result = self.calc.runpython(self.current)
<span style="box-sizing: border-box; color: #7f0055;"><span style="box-sizing: border-box; font-weight: 700;">if</span></span> result:
self.display.insert(END, <span style="box-sizing: border-box; color: #2a00ff;">'\n'</span>)
self.display.insert(END, <span style="box-sizing: border-box; color: #2a00ff;">'%s\n'</span> % result, <span style="box-sizing: border-box; color: #2a00ff;">'ans'</span>)
self.current = <span style="box-sizing: border-box; color: #2a00ff;">""</span>
def doKeypress(self, event):
key = event.char
<span style="box-sizing: border-box; color: #7f0055;"><span style="box-sizing: border-box; font-weight: 700;">if</span></span> not key in [<span style="box-sizing: border-box; color: #2a00ff;">'\b'</span>]:
self.current = self.current + event.char
<span style="box-sizing: border-box; color: #7f0055;"><span style="box-sizing: border-box; font-weight: 700;">if</span></span> key == <span style="box-sizing: border-box; color: #2a00ff;">'\b'</span>:
self.current = self.current[:-1]
def keyAction(self, key):
self.display.insert(END, key)
self.current = self.current + key
def evalAction(self, action):
<span style="box-sizing: border-box; color: #7f0055;"><span style="box-sizing: border-box; font-weight: 700;">try</span></span>:
self.actionDict[action](action)
except KeyError:
pass
def buildCalculator(self):
FUN = 1 # Designates a Function
KEY = 0 # Designates a Key
KC1 = <span style="box-sizing: border-box; color: #2a00ff;">'gray30'</span> # Dark Keys
KC2 = <span style="box-sizing: border-box; color: #2a00ff;">'gray50'</span> # Light Keys
KC3 = <span style="box-sizing: border-box; color: #2a00ff;">'steelblue1'</span> # Light Blue Key
KC4 = <span style="box-sizing: border-box; color: #2a00ff;">'steelblue'</span> # Dark Blue Key
keys = [
[(<span style="box-sizing: border-box; color: #2a00ff;">'2nd'</span>, <span style="box-sizing: border-box; color: #2a00ff;">''</span>, <span style="box-sizing: border-box; color: #2a00ff;">''</span>, KC3, FUN, <span style="box-sizing: border-box; color: #2a00ff;">'second'</span>), # Row 1
(<span style="box-sizing: border-box; color: #2a00ff;">'Mode'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'Quit'</span>, <span style="box-sizing: border-box; color: #2a00ff;">''</span>, KC1, FUN, <span style="box-sizing: border-box; color: #2a00ff;">'mode'</span>),
(<span style="box-sizing: border-box; color: #2a00ff;">'Del'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'Ins'</span>, <span style="box-sizing: border-box; color: #2a00ff;">''</span>, KC1, FUN, <span style="box-sizing: border-box; color: #2a00ff;">'delete'</span>),
(<span style="box-sizing: border-box; color: #2a00ff;">'Alpha'</span>,<span style="box-sizing: border-box; color: #2a00ff;">'Lock'</span>, <span style="box-sizing: border-box; color: #2a00ff;">''</span>, KC2, FUN, <span style="box-sizing: border-box; color: #2a00ff;">'alpha'</span>),
(<span style="box-sizing: border-box; color: #2a00ff;">'Stat'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'List'</span>, <span style="box-sizing: border-box; color: #2a00ff;">''</span>, KC1, FUN, <span style="box-sizing: border-box; color: #2a00ff;">'stat'</span>)],
[(<span style="box-sizing: border-box; color: #2a00ff;">'Math'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'Test'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'A'</span>, KC1, FUN, <span style="box-sizing: border-box; color: #2a00ff;">'math'</span>), # Row 2
(<span style="box-sizing: border-box; color: #2a00ff;">'Mtrx'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'Angle'</span>,<span style="box-sizing: border-box; color: #2a00ff;">'B'</span>, KC1, FUN, <span style="box-sizing: border-box; color: #2a00ff;">'matrix'</span>),
(<span style="box-sizing: border-box; color: #2a00ff;">'Prgm'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'Draw'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'C'</span>, KC1, FUN, <span style="box-sizing: border-box; color: #2a00ff;">'program'</span>),
(<span style="box-sizing: border-box; color: #2a00ff;">'Vars'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'YVars'</span>,<span style="box-sizing: border-box; color: #2a00ff;">''</span>, KC1, FUN, <span style="box-sizing: border-box; color: #2a00ff;">'vars'</span>),
(<span style="box-sizing: border-box; color: #2a00ff;">'Clr'</span>, <span style="box-sizing: border-box; color: #2a00ff;">''</span>, <span style="box-sizing: border-box; color: #2a00ff;">''</span>, KC1, FUN, <span style="box-sizing: border-box; color: #2a00ff;">'clear'</span>)],
[(<span style="box-sizing: border-box; color: #2a00ff;">'X-1'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'Abs'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'D'</span>, KC1, FUN, <span style="box-sizing: border-box; color: #2a00ff;">'X1'</span>), # Row 3
(<span style="box-sizing: border-box; color: #2a00ff;">'Sin'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'Sin-1'</span>,<span style="box-sizing: border-box; color: #2a00ff;">'E'</span>, KC1, FUN, <span style="box-sizing: border-box; color: #2a00ff;">'sin'</span>),
(<span style="box-sizing: border-box; color: #2a00ff;">'Cos'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'Cos-1'</span>,<span style="box-sizing: border-box; color: #2a00ff;">'F'</span>, KC1, FUN, <span style="box-sizing: border-box; color: #2a00ff;">'cos'</span>),
(<span style="box-sizing: border-box; color: #2a00ff;">'Tan'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'Tan-1'</span>,<span style="box-sizing: border-box; color: #2a00ff;">'G'</span>, KC1, FUN, <span style="box-sizing: border-box; color: #2a00ff;">'tan'</span>),
(<span style="box-sizing: border-box; color: #2a00ff;">'^'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'PI'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'H'</span>, KC1, FUN, <span style="box-sizing: border-box; color: #2a00ff;">'up'</span>)],
[(<span style="box-sizing: border-box; color: #2a00ff;">'X2'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'Root'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'I'</span>, KC1, FUN, <span style="box-sizing: border-box; color: #2a00ff;">'X2'</span>), # Row 4
(<span style="box-sizing: border-box; color: #2a00ff;">','</span>, <span style="box-sizing: border-box; color: #2a00ff;">'EE'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'J'</span>, KC1, KEY, <span style="box-sizing: border-box; color: #2a00ff;">','</span>),
(<span style="box-sizing: border-box; color: #2a00ff;">'('</span>, <span style="box-sizing: border-box; color: #2a00ff;">'{'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'K'</span>, KC1, KEY, <span style="box-sizing: border-box; color: #2a00ff;">'('</span>),
(<span style="box-sizing: border-box; color: #2a00ff;">')'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'}'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'L'</span>, KC1, KEY, <span style="box-sizing: border-box; color: #2a00ff;">')'</span>),
(<span style="box-sizing: border-box; color: #2a00ff;">'/'</span>, <span style="box-sizing: border-box; color: #2a00ff;">''</span>, <span style="box-sizing: border-box; color: #2a00ff;">'M'</span>, KC4, KEY, <span style="box-sizing: border-box; color: #2a00ff;">'/'</span>)],
[(<span style="box-sizing: border-box; color: #2a00ff;">'Log'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'10x'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'N'</span>, KC1, FUN, <span style="box-sizing: border-box; color: #2a00ff;">'log'</span>), # Row 5
(<span style="box-sizing: border-box; color: #2a00ff;">'7'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'Un-1'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'O'</span>, KC2, KEY, <span style="box-sizing: border-box; color: #2a00ff;">'7'</span>),
(<span style="box-sizing: border-box; color: #2a00ff;">'8'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'Vn-1'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'P'</span>, KC2, KEY, <span style="box-sizing: border-box; color: #2a00ff;">'8'</span>),
(<span style="box-sizing: border-box; color: #2a00ff;">'9'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'n'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'Q'</span>, KC2, KEY, <span style="box-sizing: border-box; color: #2a00ff;">'9'</span>),
(<span style="box-sizing: border-box; color: #2a00ff;">'X'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'['</span>, <span style="box-sizing: border-box; color: #2a00ff;">'R'</span>, KC4, KEY, <span style="box-sizing: border-box; color: #2a00ff;">'*'</span>)],
[(<span style="box-sizing: border-box; color: #2a00ff;">'Ln'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'ex'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'S'</span>, KC1, FUN, <span style="box-sizing: border-box; color: #2a00ff;">'ln'</span>), # Row 6
(<span style="box-sizing: border-box; color: #2a00ff;">'4'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'L4'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'T'</span>, KC2, KEY, <span style="box-sizing: border-box; color: #2a00ff;">'4'</span>),
(<span style="box-sizing: border-box; color: #2a00ff;">'5'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'L5'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'U'</span>, KC2, KEY, <span style="box-sizing: border-box; color: #2a00ff;">'5'</span>),
(<span style="box-sizing: border-box; color: #2a00ff;">'6'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'L6'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'V'</span>, KC2, KEY, <span style="box-sizing: border-box; color: #2a00ff;">'6'</span>),
(<span style="box-sizing: border-box; color: #2a00ff;">'-'</span>, <span style="box-sizing: border-box; color: #2a00ff;">']'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'W'</span>, KC4, KEY, <span style="box-sizing: border-box; color: #2a00ff;">'-'</span>)],
[(<span style="box-sizing: border-box; color: #2a00ff;">'STO'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'RCL'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'X'</span>, KC1, FUN, <span style="box-sizing: border-box; color: #2a00ff;">'store'</span>), # Row 7
(<span style="box-sizing: border-box; color: #2a00ff;">'1'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'L1'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'Y'</span>, KC2, KEY, <span style="box-sizing: border-box; color: #2a00ff;">'1'</span>),
(<span style="box-sizing: border-box; color: #2a00ff;">'2'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'L2'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'Z'</span>, KC2, KEY, <span style="box-sizing: border-box; color: #2a00ff;">'2'</span>),
(<span style="box-sizing: border-box; color: #2a00ff;">'3'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'L3'</span>, <span style="box-sizing: border-box; color: #2a00ff;">''</span>, KC2, KEY, <span style="box-sizing: border-box; color: #2a00ff;">'3'</span>),
(<span style="box-sizing: border-box; color: #2a00ff;">'+'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'MEM'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'"'</span>, KC4, KEY, <span style="box-sizing: border-box; color: #2a00ff;">'+'</span>)],
[(<span style="box-sizing: border-box; color: #2a00ff;">'Off'</span>, <span style="box-sizing: border-box; color: #2a00ff;">''</span>, <span style="box-sizing: border-box; color: #2a00ff;">''</span>, KC1, FUN, <span style="box-sizing: border-box; color: #2a00ff;">'off'</span>), # Row 8
(<span style="box-sizing: border-box; color: #2a00ff;">'0'</span>, <span style="box-sizing: border-box; color: #2a00ff;">''</span>, <span style="box-sizing: border-box; color: #2a00ff;">''</span>, KC2, KEY, <span style="box-sizing: border-box; color: #2a00ff;">'0'</span>),
(<span style="box-sizing: border-box; color: #2a00ff;">'.'</span>, <span style="box-sizing: border-box; color: #2a00ff;">':'</span>, <span style="box-sizing: border-box; color: #2a00ff;">''</span>, KC2, KEY, <span style="box-sizing: border-box; color: #2a00ff;">'.'</span>),
(<span style="box-sizing: border-box; color: #2a00ff;">'(-)'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'ANS'</span>, <span style="box-sizing: border-box; color: #2a00ff;">'?'</span>, KC2, FUN, <span style="box-sizing: border-box; color: #2a00ff;">'neg'</span>),
(<span style="box-sizing: border-box; color: #2a00ff;">'Enter'</span>,<span style="box-sizing: border-box; color: #2a00ff;">'Entry'</span>,<span style="box-sizing: border-box; color: #2a00ff;">''</span>, KC4, FUN, <span style="box-sizing: border-box; color: #2a00ff;">'enter'</span>)]]
self.display = Pmw.ScrolledText(self, hscrollmode=<span style="box-sizing: border-box; color: #2a00ff;">'dynamic'</span>,
vscrollmode=<span style="box-sizing: border-box; color: #2a00ff;">'dynamic'</span>, hull_relief=<span style="box-sizing: border-box; color: #2a00ff;">'sunken'</span>,
hull_background=<span style="box-sizing: border-box; color: #2a00ff;">'gray40'</span>, hull_borderwidth=10,
text_background=<span style="box-sizing: border-box; color: #2a00ff;">'honeydew4'</span>, text_width=16,
text_foreground=<span style="box-sizing: border-box; color: #2a00ff;">'black'</span>, text_height=6,
text_padx=10, text_pady=10, text_relief=<span style="box-sizing: border-box; color: #2a00ff;">'groove'</span>,
text_font=(<span style="box-sizing: border-box; color: #2a00ff;">'arial'</span>, 12, <span style="box-sizing: border-box; color: #2a00ff;">'bold'</span>))
self.display.pack(side=TOP, expand=YES, fill=BOTH)
self.display.tag_config(<span style="box-sizing: border-box; color: #2a00ff;">'ans'</span>, foreground=<span style="box-sizing: border-box; color: #2a00ff;">'white'</span>)
self.display.component(<span style="box-sizing: border-box; color: #2a00ff;">'text'</span>).bind(<span style="box-sizing: border-box; color: #2a00ff;">'<Key>'</span>, self.doKeypress)
self.display.component(<span style="box-sizing: border-box; color: #2a00ff;">'text'</span>).bind(<span style="box-sizing: border-box; color: #2a00ff;">'<Return>'</span>, self.doEnter)
<span style="box-sizing: border-box; color: #7f0055;"><span style="box-sizing: border-box; font-weight: 700;">for</span></span> row in keys:
rowa = Frame(self, bg=<span style="box-sizing: border-box; color: #2a00ff;">'gray40'</span>)
rowb = Frame(self, bg=<span style="box-sizing: border-box; color: #2a00ff;">'gray40'</span>)
<span style="box-sizing: border-box; color: #7f0055;"><span style="box-sizing: border-box; font-weight: 700;">for</span></span> p1, p2, p3, color, ktype, func in row:
<span style="box-sizing: border-box; color: #7f0055;"><span style="box-sizing: border-box; font-weight: 700;">if</span></span> ktype == FUN:
a = lambda s=self, a=func: s.evalAction(a)
<span style="box-sizing: border-box; color: #7f0055;"><span style="box-sizing: border-box; font-weight: 700;">else</span></span>:
a = lambda s=self, k=func: s.keyAction(k)
SLabel(rowa, p2, p3)
Key(rowb, text=p1, bg=color, command=a)
rowa.pack(side=TOP, expand=YES, fill=BOTH)
rowb.pack(side=TOP, expand=YES, fill=BOTH)
<span style="box-sizing: border-box; color: #7f0055;"><span style="box-sizing: border-box; font-weight: 700;">class</span></span> Evaluator:
def __init__(self):
self.myNameSpace = {}
self.runpython(<span style="box-sizing: border-box; color: #2a00ff;">"from math import *"</span>)
def runpython(self, code):
<span style="box-sizing: border-box; color: #7f0055;"><span style="box-sizing: border-box; font-weight: 700;">try</span></span>:
<span style="box-sizing: border-box; color: #7f0055;"><span style="box-sizing: border-box; font-weight: 700;">return</span></span> <span style="box-sizing: border-box; color: #2a00ff;">'eval(code, self.myNameSpace, self.myNameSpace)'</span>
except SyntaxError:
<span style="box-sizing: border-box; color: #7f0055;"><span style="box-sizing: border-box; font-weight: 700;">try</span></span>:
exec code in self.myNameSpace, self.myNameSpace
except:
<span style="box-sizing: border-box; color: #7f0055;"><span style="box-sizing: border-box; font-weight: 700;">return</span></span> <span style="box-sizing: border-box; color: #2a00ff;">'Error'</span>
Calculator().mainloop()</pre>
<br />
Tag : <a href="http://programmerstrick.blogspot.in/search/label/Python">Python</a> <a href="http://programmerstrick.blogspot.in/search/label/Application">Applcation</a> <a href="http://programmerstrick.blogspot.in/search/label/Program">Program </a></div>
Mohit Patelhttp://www.blogger.com/profile/08269675484730515993noreply@blogger.com0tag:blogger.com,1999:blog-4579800890132441483.post-59788118967123347342015-06-25T03:43:00.003-07:002015-06-28T10:48:34.131-07:00C# : Efficiently Looping Over An Array<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="background-color: white; color: #202020; font-family: Arial; font-size: 15px;">This Tricks can improve the speed of programs that spend a lot of time looping over arrays.</span><br />
<br style="background-color: white; color: #202020; font-family: Arial; font-size: 15px;" />
<span style="background-color: white; color: #202020; font-family: Arial; font-size: 15px;">Propably you know from experience, that when you try to access an invalid array element (say, index 11 in an array of size 10) you will get an </span><span style="background-color: white; font-family: Arial; font-size: 15px;"><span style="color: #3d85c6;">IndexOutOfRangeException</span></span><span style="background-color: white; color: #202020; font-family: Arial; font-size: 15px;">. To be able to generate this exception and prohibit the dangerous access of memory beyond your array storage, the runtime performs an array bounds check everytime you access an array, which checks that the index you supply is lower then the array size.</span><br />
<span style="background-color: white; color: #202020; font-family: Arial; font-size: 15px;"><br /></span>
<span style="background-color: white; color: #202020; font-family: Arial; font-size: 15px;">For example, take a look at this code:</span><br />
<span style="background-color: white; color: #202020; font-family: Arial; font-size: 15px;"><br /></span>
<span style="background-color: white; color: #202020; font-family: Arial; font-size: 15px;"><br /></span>
<br />
<pre style="background-color: white; color: #202020; font-family: consolas; font-size: 15px;"><span style="color: blue;">int</span> count = 0;
<span style="color: blue;">int</span>[] array = <span style="color: blue;">new</span> <span style="color: blue;">int</span>[10];
<span style="color: green;">// omitted: fill array with some values</span>
<span style="color: blue;">for</span> (<span style="color: blue;">int</span> i = 0; i < 10; i++)
count += array[i];</pre>
<span style="background-color: white; color: #202020; font-family: Arial; font-size: 15px;"><br /></span>
<span style="background-color: white; color: #202020; font-family: Arial; font-size: 15px;">Here, we simply loop over all elements of the array and add them together.</span><br />
<span style="background-color: white; color: #202020; font-family: Arial; font-size: 15px;">But what the compiler actually produces looks something like the result of this code:</span><br />
<pre style="background-color: white; color: #202020; font-family: consolas; font-size: 15px;"><span style="color: blue;">
</span></pre>
<pre style="background-color: white; color: #202020; font-family: consolas; font-size: 15px;"><a href="https://www.blogger.com/blogger.g?blogID=4579800890132441483" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="https://www.blogger.com/blogger.g?blogID=4579800890132441483" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="https://www.blogger.com/blogger.g?blogID=4579800890132441483" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><span style="color: blue;">for</span> (<span style="color: blue;">int</span> i = 0; i < 10; i++)
{
<span style="color: blue;">if</span> (i >= array.Length)
<span style="color: blue;">throw</span> <span style="color: blue;">new</span> <span style="color: #2b91af;">IndexOutOfRangeException</span>();
count += array[i];
}</pre>
<span style="background-color: white; color: #202020; font-family: Arial; font-size: 15px;"><br /></span>
<span style="background-color: white; color: #202020; font-family: Arial; font-size: 15px;">Now the hidden cost is only a simple if expression for each array access, but if you have many or very large arrays which get looped over often, it can add up.</span><br />
<br style="background-color: white; color: #202020; font-family: Arial; font-size: 15px;" />
<span style="background-color: white; color: #202020; font-family: Arial; font-size: 15px;">But there are two ways to let the compiler skip the bounds checks and speed up array code:</span><br />
<br style="background-color: white; color: #202020; font-family: Arial; font-size: 15px;" />
<span style="background-color: white; color: #202020; font-family: Arial; font-size: 15px;">The first way is to use Array.Length as the upper bound of the loop variable, and use the unmodified loop variable to index the array:</span><br />
<pre style="background-color: white; color: #202020; font-family: consolas; font-size: 15px;"><span style="color: blue;">
</span></pre>
<pre style="background-color: white; color: #202020; font-family: consolas; font-size: 15px;"><span style="color: blue;">for</span> (<span style="color: blue;">int</span> i = 0; i < array.Length; i++)
count += array[i];</pre>
<br style="background-color: white; color: #202020; font-family: Arial; font-size: 15px;" />
<span style="background-color: white; color: #202020; font-family: Arial; font-size: 15px;">The second way is to loop over the array with foreach:</span><br />
<pre style="background-color: white; color: #202020; font-family: consolas; font-size: 15px;"><span style="color: blue;">foreach</span> (<span style="color: blue;">int</span> x <span style="color: blue;">in</span> array)
count += x;</pre>
<span style="background-color: white; color: #202020; font-family: Arial; font-size: 15px;"><br /></span>
<span style="background-color: white; color: #202020; font-family: Arial; font-size: 15px;">In both cases, the compiler can be sure that the array index will never be outside its bounds, and skip the bounds check.</span><br />
<span style="background-color: white; color: #202020; font-family: Arial; font-size: 15px;"><br /></span>
<span style="background-color: white; color: #202020; font-family: Arial; font-size: 15px;"><br /></span></div>
Mohit Patelhttp://www.blogger.com/profile/08269675484730515993noreply@blogger.com0