How can we suggest if something is worth learning if you don't tell us why you would even want to learn it in the first place?
Sceadwian said:How can we suggest if something is worth learning if you don't tell us why you would even want to learn it in the first place?
python can do GUI's and hte best bit is... as long as you provide the 3rd party libs for windows it is fully cross-platform!!!Marks256 said:Python can do GUIs????????????????????????? (linux i presume...)
#!/usr/bin/env python
"""
show how to add a matplotlib FigureCanvasGTK or FigureCanvasGTKAgg widget and
a toolbar to a gtk.Window
"""
import math
import gobject
from pylab import *
rcParams['numerix'] = 'numpy'
import matplotlib
matplotlib.use('GTK')
from matplotlib.figure import Figure
from matplotlib.axes import Subplot
from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas
from matplotlib.backends.backend_gtk import NavigationToolbar2GTK as NavigationToolbar
try:
import pygtk
pygtk.require("2.0")
except:
pass
try:
import gtk
import gtk.glade
except:
sys.exit(1)
TIME = range(360)
VOLT1 = [math.sin(math.radians(x+0)) for x in TIME]
VOLT2 = [math.sin(math.radians(x+120)) for x in TIME]
VOLT3 = [math.sin(math.radians(x+240)) for x in TIME]
PLOT_DATA = [VOLT1,VOLT2,VOLT3]
###################################################################
class appGui:
def __init__(self):
self.gladefile = 'graph-gui.glade'
self.windowname = 'graph-it'
self.wTree = gtk.glade.XML(self.gladefile, self.windowname)
dic = {"on_quit_clicked" : self.QuitClicked,##callback dictionary
"on_plot_clicked" : self.Plot,
"on_window_destroy" : (gtk.main_quit)}
self.wTree.signal_autoconnect(dic)
#self.figure = Figure(figsize=(6,4), dpi=100)
#self.axis = self.figure.add_subplot(111)
def test_timeout(self):
print "testing"
return True
gobject.timeout_add(1000,test_timeout,self)
def QuitClicked(self,widget):
gtk.main_quit()
def Plot(self,widget):
try:
self.canvas.destroy()
self.toolbar.destroy()
except:pass
self.figure = Figure(figsize=(6,4), dpi=100)
self.axis = self.figure.add_subplot(111)
self.axis.grid(True)
self.axis.set_ylabel('Volts (V)')
self.axis.set_xlabel('Time (s)')
self.axis.set_title('Test Graph')
for x in ['signal1','signal2','signal3']:
tmp = self.wTree.get_widget(x).get_active()
if tmp == -1: continue
self.axis.plot(TIME,PLOT_DATA[tmp])
#self.axis.plot(TIME,VOLT1,'r')
#self.axis.plot(TIME,VOLT2,'y')
#self.axis.plot(TIME,VOLT3,'b')
self.canvas = FigureCanvas(self.figure) # a gtk.DrawingArea
self.canvas.show()
self.graphview = self.wTree.get_widget("vbox1")
self.graphview.pack_start(self.canvas, True, True)
self.toolbar = NavigationToolbar(self.canvas,self.wTree.get_widget('graph-it'))
self.graphview.pack_start(self.toolbar, False, False)
if __name__ == '__main__':
app=appGui()
gtk.main()
#!/usr/bin/perl -w
use Tk;
use strict;
my $box;
my $dataout;
my $datain;
my $from='ascii';
my $to='bin';
my $mw = new MainWindow;
my $tin =$mw->Text(-background =>'white')->pack();
my $fromradio;
my $toradio;
my $fromascii=$mw->Radiobutton(-command=>\¬sameto ,-variable=>\$fromradio,-value=>1,-text=>'ascii');
my $fromhex=$mw->Radiobutton(-command=>\¬sameto,-variable=>\$fromradio,-value=>2,-text=>'hex');
my $frombin=$mw->Radiobutton(-command=>\¬sameto,-variable=>\$fromradio,-value=>3,-text=>'bin');
my $toascii=$mw->Radiobutton(-state=>'disabled',-variable=>\$toradio,-value=>1,-text=>'ascii');
my $tohex=$mw->Radiobutton(-state=>'disabled',-variable=>\$toradio,-value=>2,-text=>'hex');
my $tobin=$mw->Radiobutton(-state=>'disabled',-variable=>\$toradio,-value=>3,-text=>'bin');
$fromascii->pack(-side=>'left');
$frombin->pack(-side=>'left');
$fromhex->pack(-side=>'left');
$toascii->pack(-side=>'right');
$tobin->pack(-side=>'right');
$tohex->pack(-side=>'right');
$tin->delete('1.0','end');
$tin->insert('end','test');
my $response = $mw -> Button(-text=>"Convert",-command => \&convert)->pack();
MainLoop;
sub notsameto{
if($fromradio==1){
$toascii->configure(-state=>'disabled');
$tobin->configure(-state=>'normal');
$tohex->configure(-state=>'normal');
return;
}
if($fromradio==2){
$tohex->configure(-state=>'disabled');
$tobin->configure(-state=>'normal');
$toascii->configure(-state=>'normal');
return;
}
if($fromradio==3){
$tobin->configure(-state=>'disabled');
$tohex->configure(-state=>'normal');
$toascii->configure(-state=>'normal');
return;
}
}
sub b2ascii
{
my $l=length $_[0];
my $a=+pack "B$l",$_[0];
return $a;
}
sub a2hex
{
(my $str = shift) =~ s/(.|\n)/sprintf("%02lx", ord $1)/eg;
return $str;
}
sub h2ascii
{
(my $str = shift) =~ s/([a-fA-F0-9]{2})/chr(hex $1)/eg;
return $str;
}
sub a2bin
{
my $l=(length $_[0])*8;
my $a=+unpack "B$l",$_[0];
return $a;
}
sub convert(){
if(!$toradio){return;}
$datain=$tin->get('1.0','end');
$tin->delete('1.0','end');
if ($fromradio==1){
if ($toradio==3){$dataout=a2bin($datain);}
if ($toradio==2){$dataout=a2hex($datain);}
}
if($fromradio==2){
if($datain!~/[a-fA-F0-9]/)
{
$box = $mw->DialogBox( -buttons => ["OK"])->pack();
return;
}
if($toradio==1){$dataout=h2ascii($datain);}
if($toradio==3){$dataout=a2bin(h2ascii($datain));}
}
if($fromradio==3){
if ($datain!~/01/)
{
$box = $mw->DialogBox( -buttons => ["OK"])->pack();
return;
}
if($toradio==1){$dataout=b2ascii($datain);}
if($toradio==2){$dataout=a2hex(b2ascii($datain));}
}
$tin->insert('end',$dataout);
return;
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?