[GTKUI] Another update of methods to latest GTK2 API 2.24

* These updates make the code more compatible with GTK3
This commit is contained in:
Calum Lind 2016-11-10 22:49:21 +00:00 committed by Calum Lind
parent ccfe6b3c80
commit c8e6a4476d
13 changed files with 66 additions and 64 deletions

View File

@ -9,6 +9,7 @@
import gtk
import deluge.component as component
from deluge.common import get_pixmap, get_version
from deluge.ui.client import client
from deluge.ui.gtkui.common import get_deluge_icon
@ -17,6 +18,7 @@ from deluge.ui.gtkui.common import get_deluge_icon
class AboutDialog(object):
def __init__(self):
self.about = gtk.AboutDialog()
self.about.set_transient_for(component.get('MainWindow').get_window())
self.about.set_position(gtk.WIN_POS_CENTER)
self.about.set_name('Deluge')
self.about.set_program_name(_('Deluge'))

View File

@ -106,7 +106,7 @@ class AddTorrentDialog(component.Component):
render = gtk.CellRendererText()
column = gtk.TreeViewColumn(_('Size'))
column.pack_start(render)
column.pack_start(render, True)
column.set_cell_data_func(render, cell_data_size, 2)
self.listview_files.append_column(column)
@ -610,7 +610,7 @@ class AddTorrentDialog(component.Component):
dialog.set_transient_for(self.dialog)
pb = gtk.ProgressBar()
dialog.vbox.pack_start(pb, True, True)
dialog.vbox.pack_start(pb, True, True, 0)
dialog.show_all()
# Create a tmp file path

View File

@ -71,7 +71,7 @@ def build_menu_radio_list(value_list, callback, pref_value=None, suffix=None, sh
item_text = str(value)
if suffix:
item_text += ' ' + suffix
menuitem = gtk.RadioMenuItem(group, item_text)
menuitem = gtk.RadioMenuItem(group=group, label=item_text)
group = menuitem
if pref_value and value == pref_value:
menuitem.set_active(True)
@ -80,7 +80,7 @@ def build_menu_radio_list(value_list, callback, pref_value=None, suffix=None, sh
menu.append(menuitem)
if show_notset:
menuitem = gtk.RadioMenuItem(group, notset_label)
menuitem = gtk.RadioMenuItem(group=group, label=notset_label)
menuitem.set_name('unlimited')
if pref_value and pref_value < notset_lessthan:
menuitem.set_active(True)

View File

@ -83,7 +83,7 @@ class CreateTorrentDialog(object):
column = gtk.TreeViewColumn(_('Size'))
render = gtk.CellRendererText()
column.pack_start(render)
column.pack_start(render, True)
column.set_cell_data_func(render, cell_data_size, 2)
self.builder.get_object('treeview_files').append_column(column)

View File

@ -55,15 +55,15 @@ class BaseDialog(gtk.Dialog):
else:
image.set_from_stock(icon, gtk.ICON_SIZE_DIALOG)
image.set_alignment(0.5, 0.0)
hbox.pack_start(image, False, False)
hbox.pack_start(image, False, False, 0)
vbox = gtk.VBox(spacing=5)
tlabel = gtk.Label(text)
tlabel.set_use_markup(True)
tlabel.set_line_wrap(True)
tlabel.set_alignment(0.0, 0.5)
vbox.pack_start(tlabel, False, False)
hbox.pack_start(vbox, False, False)
self.vbox.pack_start(hbox, False, False)
vbox.pack_start(tlabel, False, False, 0)
hbox.pack_start(vbox, False, False, 0)
self.vbox.pack_start(hbox, False, False, 0)
self.vbox.set_spacing(5)
self.vbox.show_all()
@ -171,8 +171,8 @@ class ErrorDialog(BaseDialog):
sw.add(textview)
label = gtk.Label(_('Details:'))
label.set_alignment(0.0, 0.5)
self.vbox.pack_start(label, False, False)
self.vbox.pack_start(sw)
self.vbox.pack_start(label, False, False, 0)
self.vbox.pack_start(sw, True, True, 0)
self.vbox.show_all()
@ -341,7 +341,7 @@ class OtherDialog(BaseDialog):
hbox = gtk.HBox(spacing=5)
alignment_spacer = gtk.Alignment()
hbox.pack_start(alignment_spacer)
hbox.pack_start(alignment_spacer, True, True, 0)
alignment_spin = gtk.Alignment(1, 0.5, 1, 1)
adjustment_spin = gtk.Adjustment(value=-1, lower=-1, upper=2097151, step_incr=1, page_incr=10)
self.spinbutton = gtk.SpinButton(adjustment_spin)
@ -353,11 +353,11 @@ class OtherDialog(BaseDialog):
if self.value_type is float:
self.spinbutton.set_digits(1)
alignment_spin.add(self.spinbutton)
hbox.pack_start(alignment_spin, expand=False)
hbox.pack_start(alignment_spin, False, True, 0)
label_type = gtk.Label()
label_type.set_text(unit_text)
label_type.set_alignment(0.0, 0.5)
hbox.pack_start(label_type)
hbox.pack_start(label_type, True, True, 0)
self.vbox.pack_start(hbox, False, False, padding=5)
self.vbox.show_all()

View File

@ -141,7 +141,7 @@ class FilesTab(Tab):
# Progress column
column = gtk.TreeViewColumn(_('Progress'))
render = gtk.CellRendererProgress()
column.pack_start(render)
column.pack_start(render, True)
column.set_cell_data_func(render, cell_progress, (2, 3))
column.set_sort_column_id(3)
column.set_clickable(True)

View File

@ -386,12 +386,12 @@ class ListView(object):
if column.column_type == 'text':
if add:
tree_column.pack_start(column.renderer)
tree_column.pack_start(column.renderer, True)
tree_column.set_col_attributes(column.renderer, add=add,
text=column.column_indices[column.text_index])
elif column.column_type == 'bool':
if add:
tree_column.pack_start(column.renderer)
tree_column.pack_start(column.renderer, True)
tree_column.set_col_attributes(column.renderer, active=column.column_indices[0])
elif column.column_type == 'func':
if add:
@ -402,7 +402,7 @@ class ListView(object):
tree_column.set_cell_data_func(column.renderer, column.data_func, indice_arg)
elif column.column_type == 'progress':
if add:
tree_column.pack_start(column.renderer)
tree_column.pack_start(column.renderer, True)
if column.data_func is None:
tree_column.set_col_attributes(column.renderer, add=add,
text=column.column_indices[column.text_index],

View File

@ -286,12 +286,12 @@ class MainWindow(component.Component):
self.config['window_pane_position'] = self.vpaned.get_position()
def on_drag_data_received_event(self, widget, drag_context, x, y, selection_data, info, timestamp):
log.debug('Selection(s) dropped on main window %s', selection_data.data)
log.debug('Selection(s) dropped on main window %s', selection_data.get_text())
if selection_data.get_uris():
process_args(selection_data.get_uris())
else:
process_args(selection_data.data.split())
drag_context.finish(True, True)
process_args(selection_data.get_text().split())
drag_context.finish(True, True, timestamp)
def on_expose_event(self, widget, event):
component.get('SystemTray').blink(False)

View File

@ -402,19 +402,19 @@ class MenuBar(component.Component):
AboutDialog().run()
def on_menuitem_set_unlimited(self, widget):
log.debug('widget.name: %s', widget.name)
log.debug('widget name: %s', widget.get_name())
funcs = {
'menuitem_down_speed': client.core.set_torrent_max_download_speed,
'menuitem_up_speed': client.core.set_torrent_max_upload_speed,
'menuitem_max_connections': client.core.set_torrent_max_connections,
'menuitem_upload_slots': client.core.set_torrent_max_upload_slots
}
if widget.name in funcs.keys():
if widget.get_name() in funcs.keys():
for torrent in component.get('TorrentView').get_selected_torrents():
funcs[widget.name](torrent, -1)
funcs[widget.get_name()](torrent, -1)
def on_menuitem_set_other(self, widget):
log.debug('widget.name: %s', widget.name)
log.debug('widget name: %s', widget.get_name())
status_map = {
'menuitem_down_speed': ['max_download_speed', 'max_download_speed'],
'menuitem_up_speed': ['max_upload_speed', 'max_upload_speed'],
@ -435,11 +435,11 @@ class MenuBar(component.Component):
'menuitem_stop_seed_at_ratio': [_('Stop Seed At Ratio'), 'Stop torrent seeding at ratio', '', None]
}
core_key = status_map[widget.name][0]
core_key_global = status_map[widget.name][1]
core_key = status_map[widget.get_name()][0]
core_key_global = status_map[widget.get_name()][1]
def _on_torrent_status(status):
other_dialog = other_dialog_info[widget.name]
other_dialog = other_dialog_info[widget.get_name()]
# Add the default using status value
if status:
other_dialog.append(status[core_key_global])
@ -507,11 +507,11 @@ class MenuBar(component.Component):
self.change_owner_submenu_items = {}
maingroup = gtk.RadioMenuItem(None, None)
self.change_owner_submenu_items[None] = gtk.RadioMenuItem(maingroup)
self.change_owner_submenu_items[None] = gtk.RadioMenuItem(group=maingroup)
for account in known_accounts:
username = account['username']
item = gtk.RadioMenuItem(maingroup, username)
item = gtk.RadioMenuItem(group=maingroup, label=username)
self.change_owner_submenu_items[username] = item
self.change_owner_submenu.append(item)
item.connect('toggled', self._on_change_owner_toggled, username)

View File

@ -16,6 +16,7 @@ import gtk
from gobject import SIGNAL_RUN_FIRST, TYPE_NONE, GObject, type_register
from gtk import gdk, keysyms
import deluge.component as component
from deluge.common import resource_filename
from deluge.path_chooser_common import get_completion_paths
@ -189,7 +190,7 @@ class ValueList(object):
Enter or Return : Select
"""
keyval = event.keyval
state = event.state & gtk.accelerator_get_default_mod_mask()
state = event.get_state() & gtk.accelerator_get_default_mod_mask()
if keyval == keysyms.Escape or\
(key_is_up(keyval) and
@ -412,7 +413,7 @@ class StoredValuesList(ValueList):
"""
keyval = event.keyval
ctrl = event.state & gtk.gdk.CONTROL_MASK
ctrl = event.get_state() & gtk.gdk.CONTROL_MASK
# Edit selected row
if (keyval in [keysyms.Left, keysyms.Right, keysyms.space]):
@ -421,7 +422,7 @@ class StoredValuesList(ValueList):
self.on_edit_path(path, self.tree_column)
elif key_is_up_or_down(keyval):
# Swap the row value
if event.state & gtk.gdk.CONTROL_MASK:
if event.get_state() & gtk.gdk.CONTROL_MASK:
self.handle_list_scroll(_next=key_is_down(keyval),
swap=True)
else:
@ -482,7 +483,7 @@ class CompletionList(ValueList):
if ret:
return ret
keyval = event.keyval
ctrl = event.state & gtk.gdk.CONTROL_MASK
ctrl = event.get_state() & gtk.gdk.CONTROL_MASK
if key_is_up_or_down(keyval):
self.handle_list_scroll(_next=key_is_down(keyval))
return True
@ -561,8 +562,8 @@ class PathChooserPopup(object):
x, y = self.path_entry.get_window().get_origin()
# Add the position of the alignment_widget relative to the parent window.
x += self.alignment_widget.allocation.x
y += self.alignment_widget.allocation.y
x += self.alignment_widget.get_allocation().x
y += self.alignment_widget.get_allocation().y
height_extra = 8
buttonbox_width = 0
@ -570,8 +571,8 @@ class PathChooserPopup(object):
width = self.popup_window.size_request()[0]
if self.popup_buttonbox:
buttonbox_height = max(self.popup_buttonbox.size_request()[1], self.popup_buttonbox.allocation.height)
buttonbox_width = max(self.popup_buttonbox.size_request()[0], self.popup_buttonbox.allocation.width)
buttonbox_height = max(self.popup_buttonbox.size_request()[1], self.popup_buttonbox.get_allocation().height)
buttonbox_width = max(self.popup_buttonbox.size_request()[0], self.popup_buttonbox.get_allocation().width)
treeview_width = self.treeview.size_request()[0]
# After removing an element from the tree store, self.treeview.size_request()[0]
# returns -1 for some reason, so the requested width cannot be used until the treeview
@ -583,8 +584,8 @@ class PathChooserPopup(object):
elif len(self.tree_store) == 0:
width = 0
if width < self.alignment_widget.allocation.width:
width = self.alignment_widget.allocation.width
if width < self.alignment_widget.get_allocation().width:
width = self.alignment_widget.get_allocation().width
# 10 is extra spacing
content_width = self.treeview.size_request()[0] + buttonbox_width + 10
@ -622,14 +623,14 @@ class PathChooserPopup(object):
x = monitor.x + monitor.width - width
# Set the position
if y + self.path_entry.allocation.height + height <= monitor.y + monitor.height:
y += self.path_entry.allocation.height
if y + self.path_entry.get_allocation().height + height <= monitor.y + monitor.height:
y += self.path_entry.get_allocation().height
# Not enough space downwards on the screen
elif y - height >= monitor.y:
y -= height
elif (monitor.y + monitor.height - (y + self.path_entry.allocation.height) >
elif (monitor.y + monitor.height - (y + self.path_entry.get_allocation().height) >
y - monitor.y):
y += self.path_entry.allocation.height
y += self.path_entry.get_allocation().height
height = monitor.y + monitor.height - y
else:
height = y - monitor.y
@ -680,7 +681,7 @@ class PathChooserPopup(object):
hide = False
# Also if the intersection of self and the event is empty, hide
# the path_list
if (tuple(self.popup_window.allocation.intersect(
if (tuple(self.popup_window.get_allocation().intersect(
gdk.Rectangle(x=int(event.x), y=int(event.y),
width=1, height=1))) == (0, 0, 0, 0)):
hide = True
@ -773,8 +774,8 @@ class StoredValuesPopup(StoredValuesList, PathChooserPopup):
Handles scroll events from text entry, toggle button and treeview
"""
swap = event.state & gtk.gdk.CONTROL_MASK
scroll_window = event.state & gtk.gdk.SHIFT_MASK
swap = event.get_state() & gtk.gdk.CONTROL_MASK
scroll_window = event.get_state() & gtk.gdk.SHIFT_MASK
self.handle_list_scroll(_next=event.direction == gdk.SCROLL_DOWN,
set_entry=widget != self.treeview, swap=swap, scroll_window=scroll_window)
return True
@ -785,7 +786,7 @@ class StoredValuesPopup(StoredValuesList, PathChooserPopup):
is on any of the buttons in the popup
"""
keyval = event.keyval
state = event.state & gtk.accelerator_get_default_mod_mask()
state = event.get_state() & gtk.accelerator_get_default_mod_mask()
if keyval == keysyms.Escape or (key_is_up(keyval) and state == gdk.MOD1_MASK):
self.popdown()
return True
@ -954,7 +955,7 @@ class PathAutoCompleter(object):
if ret:
return ret
keyval = event.keyval
state = event.state & gtk.accelerator_get_default_mod_mask()
state = event.get_state() & gtk.accelerator_get_default_mod_mask()
if self.is_auto_completion_accelerator(keyval, state)\
and self.auto_complete_enabled:
values_count = self.completion_popup.get_values_count()
@ -1037,6 +1038,7 @@ class PathChooserComboBox(gtk.HBox, StoredValuesPopup, GObject):
self.open_filechooser_dialog_button = self.builder.get_object('button_open_dialog')
self.filechooser_button = self.open_filechooser_dialog_button
self.filechooserdialog = self.builder.get_object('filechooserdialog')
self.filechooserdialog.set_transient_for(component.get('MainWindow').get_window())
self.folder_name_label = self.builder.get_object('folder_name_label')
self.default_text = None
self.button_properties = self.builder.get_object('button_properties')
@ -1291,8 +1293,8 @@ class PathChooserComboBox(gtk.HBox, StoredValuesPopup, GObject):
"""
keyval = event.keyval
state = event.state & gtk.accelerator_get_default_mod_mask()
ctrl = event.state & gtk.gdk.CONTROL_MASK
state = event.get_state() & gtk.accelerator_get_default_mod_mask()
ctrl = event.get_state() & gtk.gdk.CONTROL_MASK
# Select new row with arrow up/down is pressed
if key_is_up_or_down(keyval):
@ -1385,7 +1387,7 @@ class PathChooserComboBox(gtk.HBox, StoredValuesPopup, GObject):
self.visible_rows_label = self.builder.get_object('visible_rows_label')
self.show_hidden_files_checkbutton = self.builder.get_object('show_hidden_files_checkbutton')
self.show_folder_name_on_button_checkbutton = self.builder.get_object('show_folder_name_on_button_checkbutton')
self.config_dialog.set_transient_for(self.popup_window)
self.config_dialog.set_transient_for(component.get('MainWindow').get_window())
def on_close(widget, event=None):
if not self.setting_accelerator_key:
@ -1444,7 +1446,7 @@ class PathChooserComboBox(gtk.HBox, StoredValuesPopup, GObject):
def on_completion_config_dialog_key_release_event(widget, event):
# We are listening for a new key
if set_key_button.get_active():
state = event.state & gtk.accelerator_get_default_mod_mask()
state = event.get_state() & gtk.accelerator_get_default_mod_mask()
accelerator_mask = state.numerator
# If e.g. only CTRL key is pressed.
if not gtk.accelerator_valid(event.keyval, accelerator_mask):
@ -1456,7 +1458,7 @@ class PathChooserComboBox(gtk.HBox, StoredValuesPopup, GObject):
return True
else:
keyval = event.keyval
ctrl = event.state & gtk.gdk.CONTROL_MASK
ctrl = event.get_state() & gtk.gdk.CONTROL_MASK
if ctrl:
# Set show/hide hidden files
if is_ascii_value(keyval, 'h'):

View File

@ -81,7 +81,7 @@ class Preferences(component.Component):
def set_separator(model, _iter, data=None):
if model.get_value(_iter, 1) == '_separator_':
return True
self.treeview.set_row_separator_func(set_separator)
self.treeview.set_row_separator_func(set_separator, None)
# Setup accounts tab lisview
self.accounts_levels_mapping = None
@ -232,7 +232,7 @@ class Preferences(component.Component):
scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
scrolled.show_all()
# Add this page to the notebook
index = self.notebook.append_page(scrolled)
index = self.notebook.append_page(scrolled, None)
self.liststore.append([index, name])
return name

View File

@ -225,17 +225,16 @@ class StatusBar(component.Component):
self.config['show_statusbar'] = visible
def show_not_connected(self):
self.hbox.pack_start(
self.not_connected_item.get_eventbox(), expand=False, fill=False)
self.hbox.pack_start(self.not_connected_item.get_eventbox(), False, False, 0)
def add_item(self, image=None, stock=None, text=None, markup=False, callback=None, tooltip=None, pack_start=False):
"""Adds an item to the status bar"""
# The return tuple.. we return whatever widgets we add
item = StatusBarItem(image, stock, text, markup, callback, tooltip)
if pack_start:
self.hbox.pack_start(item.get_eventbox(), expand=False, fill=False)
self.hbox.pack_start(item.get_eventbox(), False, False, 0)
else:
self.hbox.pack_end(item.get_eventbox(), expand=False, fill=False)
self.hbox.pack_end(item.get_eventbox(), False, False, 0)
return item
def remove_item(self, item):
@ -298,8 +297,7 @@ class StatusBar(component.Component):
def _on_dht(self, value):
self.dht_status = value
if value:
self.hbox.pack_start(
self.dht_item.get_eventbox(), expand=False, fill=False)
self.hbox.pack_start(self.dht_item.get_eventbox(), False, False, 0)
self.send_status_request()
else:
self.remove_item(self.dht_item)

View File

@ -162,7 +162,7 @@ class SystemTray(component.Component):
except Exception as ex:
log.debug('Unable to hide system tray menu widgets: %s', ex)
self.tray.set_tooltip(_('Deluge') + '\n' + _('Not Connected...'))
self.tray.set_tooltip_text(_('Deluge') + '\n' + _('Not Connected...'))
def shutdown(self):
if self.config['enable_system_tray']:
@ -227,7 +227,7 @@ class SystemTray(component.Component):
)
# Set the tooltip
self.tray.set_tooltip(msg)
self.tray.set_tooltip_text(msg)
self.send_status_request()