ciao a tutti,
 sto realizzando un editor di testo con interfaccia grafica, 
utilizzando gtk, glade e python come linguaggio di programmazione, ma non 
riesco a fare in modo di stampare quello che l'utente ha scritto nell'area di 
testo (textview), vi posto il sorgente nell'allegato sperando che possiate 
aiutarmi !

Grazie

PS : se volete provare l'applicazione per segnalarmi altri 
problemi oltre a questo, ricordatevi di rinominare l'allegato glade in prova.
glade

ciao
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd";>

<glade-interface>

<widget class="GtkWindow" id="window1">
  <property name="visible">True</property>
  <property name="title" translatable="yes">Editor di 
testo--Benvenuto!!</property>
  <property name="type">GTK_WINDOW_TOPLEVEL</property>
  <property name="window_position">GTK_WIN_POS_NONE</property>
  <property name="modal">False</property>
  <property name="resizable">True</property>
  <property name="destroy_with_parent">True</property>
  <property name="decorated">True</property>
  <property name="skip_taskbar_hint">False</property>
  <property name="skip_pager_hint">False</property>
  <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
  <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
  <property name="focus_on_map">True</property>
  <property name="urgency_hint">False</property>
  <signal name="delete_event" handler="on_window1_delete_event" 
last_modification_time="Fri, 30 May 2008 20:05:43 GMT"/>

  <child>
    <widget class="GtkFixed" id="fixed1">
      <property name="visible">True</property>

      <child>
        <widget class="GtkButton" id="salva">
          <property name="width_request">62</property>
          <property name="height_request">29</property>
          <property name="visible">True</property>
          <property name="can_focus">True</property>
          <property name="label" translatable="yes">salva</property>
          <property name="use_underline">True</property>
          <property name="relief">GTK_RELIEF_NORMAL</property>
          <property name="focus_on_click">True</property>
        </widget>
        <packing>
          <property name="x">16</property>
          <property name="y">16</property>
        </packing>
      </child>

      <child>
        <widget class="GtkVSeparator" id="vseparator1">
          <property name="width_request">16</property>
          <property name="height_request">16</property>
          <property name="visible">True</property>
        </widget>
        <packing>
          <property name="x">720</property>
          <property name="y">56</property>
        </packing>
      </child>

      <child>
        <widget class="GtkTextView" id="textview1">
          <property name="width_request">856</property>
          <property name="height_request">584</property>
          <property name="visible">True</property>
          <property name="can_focus">True</property>
          <property name="editable">True</property>
          <property name="overwrite">False</property>
          <property name="accepts_tab">True</property>
          <property name="justification">GTK_JUSTIFY_LEFT</property>
          <property name="wrap_mode">GTK_WRAP_NONE</property>
          <property name="cursor_visible">True</property>
          <property name="pixels_above_lines">0</property>
          <property name="pixels_below_lines">0</property>
          <property name="pixels_inside_wrap">0</property>
          <property name="left_margin">0</property>
          <property name="right_margin">0</property>
          <property name="indent">0</property>
          <property name="text" translatable="yes"></property>
        </widget>
        <packing>
          <property name="x">0</property>
          <property name="y">104</property>
        </packing>
      </child>

      <child>
        <widget class="GtkButton" id="STAMPA">
          <property name="width_request">62</property>
          <property name="height_request">29</property>
          <property name="visible">True</property>
          <property name="can_focus">True</property>
          <property name="label" translatable="yes">stampa</property>
          <property name="use_underline">True</property>
          <property name="relief">GTK_RELIEF_NORMAL</property>
          <property name="focus_on_click">True</property>
          <signal name="clicked" handler="on_STAMPA_clicked" 
last_modification_time="Sat, 31 May 2008 11:49:31 GMT"/>
        </widget>
        <packing>
          <property name="x">112</property>
          <property name="y">16</property>
        </packing>
      </child>

      <child>
        <widget class="GtkButton" id="apri_file">
          <property name="width_request">62</property>
          <property name="height_request">29</property>
          <property name="visible">True</property>
          <property name="can_focus">True</property>
          <property name="label" translatable="yes">apri file</property>
          <property name="use_underline">True</property>
          <property name="relief">GTK_RELIEF_NORMAL</property>
          <property name="focus_on_click">True</property>
          <signal name="clicked" handler="on_apri_file_clicked" 
last_modification_time="Sun, 01 Jun 2008 08:12:48 GMT"/>
        </widget>
        <packing>
          <property name="x">224</property>
          <property name="y">16</property>
        </packing>
      </child>
    </widget>
  </child>
</widget>

</glade-interface>




#!/usr/bin/env python


import gtk.glade
import os

buffer = None


def stampa(get_buffer):
   
    string = gui.get_widget("textview1").get_buffer()  # non funziona, perche'?
    file = open("nuovo", "w")
    print >> file, string   # scrive nel file il testo della textview 
    
    file.close()     
                           
    os.system("lpr nuovo") # stampa il file
                           

def salva():
    file = open("nuovo", "w").write(text)
    file.close()  
    
def apri_file(file_name):
        pass                      # da definire 
    

gui = gtk.glade.XML("prova.glade")  # richiamo l'interfaccia grafica  
    
                                                           
dic ={
       "on_window1_delete_event":gtk.main_quit,
       "on_STAMPA_clicked":stampa,
       "on_apri_file_clicked":apri_file
       }
gui.signal_autoconnect(dic)
gtk.main()
                      # mostra la finestra




_______________________________________________
Python mailing list
Python@lists.python.it
http://lists.python.it/mailman/listinfo/python

Rispondere a