deluge/src/dgtk.py

96 lines
2.9 KiB
Python
Raw Normal View History

# dgtk.py
#
# Copyright (C) Zach Tibbitts 2006 <zach@collegegeek.org>
2007-01-08 19:38:19 +00:00
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
2007-01-08 19:38:19 +00:00
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
2007-01-08 19:38:19 +00:00
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
2007-01-08 19:38:19 +00:00
# along with this program. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
2007-01-08 19:38:19 +00:00
2006-12-08 20:26:35 +00:00
# Similar to dcommon, this contains any common functions
2007-01-08 19:38:19 +00:00
# related to gtk that are needed by the client
import dcommon
2006-12-08 19:02:22 +00:00
import gettext
import pygtk
pygtk.require('2.0')
import gtk
import gtk.glade
2007-02-12 18:14:15 +00:00
## Browse for .torrent files
def show_file_open_dialog(parent=None):
chooser = gtk.FileChooserDialog("Choose a .torrent file", parent, gtk.FILE_CHOOSER_ACTION_OPEN,
2007-01-11 00:58:23 +00:00
buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
2007-02-12 18:14:15 +00:00
f0 = gtk.FileFilter()
f0.set_name(".torrent files")
f0.add_pattern("*." + "torrent")
chooser.add_filter(f0)
f1 = gtk.FileFilter()
f1.set_name("All files")
f1.add_pattern("*")
chooser.add_filter(f1)
2007-01-11 00:58:23 +00:00
response = chooser.run()
if response == gtk.RESPONSE_OK:
result = chooser.get_filename()
else:
result = None
chooser.destroy()
return result
def show_directory_chooser_dialog(parent=None):
chooser = gtk.FileChooserDialog("Choose a download directory", parent, gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK))
if chooser.run() == gtk.RESPONSE_OK:
result = chooser.get_filename()
else:
result = None
chooser.destroy()
return result
2007-01-11 00:58:23 +00:00
2006-12-24 04:08:34 +00:00
## Functions to create columns
2006-12-22 23:24:42 +00:00
def add_text_column(view, header, cid):
render = gtk.CellRendererText()
column = gtk.TreeViewColumn(header, render, text=cid)
2007-01-11 21:53:25 +00:00
column.set_clickable(True)
2007-02-08 23:52:01 +00:00
column.set_sort_column_id(cid)
2006-12-22 23:24:42 +00:00
column.set_resizable(True)
column.set_expand(False)
view.append_column(column)
return column
2006-12-22 23:24:42 +00:00
def add_progress_column(view, header, pid, mid):
render = gtk.CellRendererProgress()
column = gtk.TreeViewColumn(header, render, value=pid, text=mid)
2007-01-11 21:53:25 +00:00
column.set_clickable(True)
2007-02-08 23:52:01 +00:00
column.set_sort_column_id(pid)
2006-12-22 23:24:42 +00:00
column.set_resizable(True)
2006-12-24 04:08:34 +00:00
column.set_expand(False)
view.append_column(column)
return column
def add_toggle_column(view, header, cid, toggled_signal=None):
render = gtk.CellRendererToggle()
render.set_property('activatable', True)
column = gtk.TreeViewColumn(header, render, active=cid)
2007-01-11 21:53:25 +00:00
column.set_clickable(True)
2006-12-24 04:08:34 +00:00
column.set_resizable(True)
column.set_expand(False)
2006-12-22 23:24:42 +00:00
view.append_column(column)
2006-12-24 04:08:34 +00:00
if toggled_signal is not None:
2007-02-14 22:43:48 +00:00
render.connect("toggled", toggled_signal)
return column