def on_response(self, dialog, response): # Save if response == Gtk.ResponseType.OK: # get shortcut shortcut = self.shortcut_label.get_text() if shortcut: # check if duplicated for action in self.parent.parent.settings['Shortcuts']: value = self.parent.parent.settings['Shortcuts'][action] if shortcut == value and action != self.action_name: self.error_box.print_message( 'Duplicate shortcut, please choose another one') return else: shortcut = None # save shortcut settings.update_and_save(self.parent.parent.settings, key='Shortcuts', subkey=self.action_name, value=shortcut) # apply to treeview for row in self.parent.shortcuts_tree_view.model: if row[0] == self.action_name: row[1] = shortcut break # Clear elif response == Gtk.ResponseType.CANCEL: # clear shortcut label self.shortcut_label.set_text('') # hide error box self.error_box.hide() return # Close self.destroy()
def on_minimap_switch_activated(self, switch, pspec): value = switch.get_active() if value: self.parent.minimap_box.show() else: self.parent.minimap_box.hide() settings.update_and_save(self.parent.settings, key='State', subkey='EnableMiniMap', value=value)
def on_podbar_switch_activated(self, switch, pspec): value = switch.get_active() if value: self.parent.podbar_box.show() else: self.parent.podbar_box.hide() settings.update_and_save(self.parent.settings, key='State', subkey='EnablePodBar', value=value)
def on_debug_switch_activated(self, switch, pspec): value = switch.get_active() self.debug_box.set_sensitive(value) if value: self.parent.debug_page.show() else: self.parent.debug_page.hide() settings.update_and_save(self.parent.settings, key='Debug', subkey='Enabled', value=value)
def on_game_version_combo_changed(self, combo): value = combo.get_active_value() settings.update_and_save(self.parent.settings, key='Game', subkey='Version', value=value) if value == shared.GameVersion.Retro: self.window_decoration_height_spin_button.set_value(10) self.verify_resources_color_check.set_active(False) self.collection_time_spin_button.set_value(11) else: self.window_decoration_height_spin_button.set_value(36) self.verify_resources_color_check.set_active(True) self.collection_time_spin_button.set_value(4)
def on_shortcuts_switch_activated(self, switch, pspec): value = switch.get_active() self.shortcuts_tree_view.vbox.set_sensitive(value) settings.update_and_save(self.parent.settings, 'EnableShortcuts', value)
def __init__(self, transient_for, title='Preferences'): CustomDialog.__init__(self, transient_for=transient_for, title=title) self.parent = transient_for # Stack & Stack switcher vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5) content_area = self.get_content_area() content_area.add(vbox) stack = Gtk.Stack() stack.set_margin_top(5) #stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT) #stack.set_transition_duration(1000) stack_switcher = Gtk.StackSwitcher() stack_switcher.set_stack(stack) vbox.pack_start(stack_switcher, True, True, 0) vbox.pack_start(stack, True, True, 0) ### General box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5) stack.add_titled(box, 'general', 'General') ## Debug hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5) box.add(hbox) hbox.add(Gtk.Label('<b>Debug</b>', xalign=0, use_markup=True)) debug_switch = Gtk.Switch() debug_switch.set_active(self.parent.settings['Debug']['Enabled']) debug_switch.connect('notify::active', self.on_debug_switch_activated) hbox.pack_end(debug_switch, False, False, 0) # Level self.debug_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5) self.debug_box.set_margin_left(10) self.debug_box.set_sensitive(self.parent.settings['Debug']['Enabled']) box.add(self.debug_box) self.debug_box.add(Gtk.Label('Level')) debug_level_combo = CustomComboBox(['High', 'Normal', 'Low']) debug_level_combo.set_active(self.parent.settings['Debug']['Level']) debug_level_combo.connect( 'changed', lambda combo: settings.update_and_save(self.parent.settings, key='Debug', subkey='Level', value=combo.get_active())) self.debug_box.pack_end(debug_level_combo, False, False, 0) ## Game box.add(Gtk.Label('<b>Game</b>', xalign=0, use_markup=True)) # Keep game checkbox keep_game_on_unplug_check = Gtk.CheckButton( 'Keep game open when unplug') keep_game_on_unplug_check.set_margin_left(10) keep_game_on_unplug_check.set_active( self.parent.settings['Game']['KeepOpen']) keep_game_on_unplug_check.connect( 'clicked', lambda check: settings.update_and_save(self.parent.settings, key='Game', subkey='KeepOpen', value=check.get_active())) box.add(keep_game_on_unplug_check) ## Account box.add(Gtk.Label('<b>Account</b>', xalign=0, use_markup=True)) # Exit game checkbox exit_game_on_disconnect_check = Gtk.CheckButton( 'Exit game when disconnect') exit_game_on_disconnect_check.set_margin_left(10) exit_game_on_disconnect_check.set_active( self.parent.settings['Account']['ExitGame']) exit_game_on_disconnect_check.connect( 'clicked', lambda check: settings.update_and_save(self.parent.settings, key='Account', subkey='ExitGame', value=check.get_active())) box.add(exit_game_on_disconnect_check) ### Bot box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5) stack.add_titled(box, 'bot', 'Bot') ## Job box.add(Gtk.Label('<b>Job</b>', xalign=0, use_markup=True)) # PodBar hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5) hbox.set_margin_left(10) hbox.add(Gtk.Label('PodBar')) podbar_switch = Gtk.Switch() podbar_switch.set_active(self.parent.settings['Job']['EnablePodBar']) podbar_switch.connect('notify::active', self.on_podbar_switch_activated) hbox.pack_end(podbar_switch, False, False, 0) box.add(hbox) # MiniMap hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5) hbox.set_margin_left(10) hbox.add(Gtk.Label('MiniMap')) minimap_switch = Gtk.Switch() minimap_switch.set_active(self.parent.settings['Job']['EnableMiniMap']) minimap_switch.connect('notify::active', self.on_minimap_switch_activated) hbox.pack_end(minimap_switch, False, False, 0) box.add(hbox) ## Farming box.add(Gtk.Label('<b>Farming</b>', xalign=0, use_markup=True)) # Save dragodindes images save_dragodindes_images_check = Gtk.CheckButton( 'Save dragodindes image') save_dragodindes_images_check.set_margin_left(10) save_dragodindes_images_check.set_active( self.parent.settings['Farming']['SaveDragodindesImages']) save_dragodindes_images_check.connect( 'clicked', lambda check: settings.update_and_save( self.parent.settings, key='Farming', subkey='SaveDragodindesImages', value=check.get_active())) box.add(save_dragodindes_images_check) ### Shortcuts box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5) stack.add_titled(box, 'shortcuts', 'Shortcuts') ## Keyboard Shortcuts hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) hbox.add( Gtk.Label('<b>Keyboard Shortcuts</b>', xalign=0, use_markup=True)) box.add(hbox) # Switch shortcuts_switch = Gtk.Switch() shortcuts_switch.set_active(self.parent.settings['EnableShortcuts']) shortcuts_switch.connect('notify::active', self.on_shortcuts_switch_activated) hbox.pack_end(shortcuts_switch, False, False, 0) # TreeView model = Gtk.ListStore(str, str) text_renderer = Gtk.CellRendererText() columns = [ Gtk.TreeViewColumn('Action', text_renderer, text=0), Gtk.TreeViewColumn('Shortcut', text_renderer, text=1) ] self.shortcuts_tree_view = CustomTreeView(model, columns) self.shortcuts_tree_view.vbox.set_sensitive( self.parent.settings['EnableShortcuts']) self.shortcuts_tree_view.connect( 'button-press-event', self.on_shortcuts_tree_view_double_clicked) self.shortcuts_tree_view.connect( 'selection-changed', self.on_shortcuts_tree_view_selection_changed) # fill treeview for action in sorted(self.parent.settings['Shortcuts']): shortcut = self.parent.settings['Shortcuts'][action] self.shortcuts_tree_view.append_row([action, shortcut], select=False, scroll_to=False) box.pack_start(self.shortcuts_tree_view, True, True, 0) # ActionBar actionbar = Gtk.ActionBar() self.shortcuts_edit_button = Gtk.Button() self.shortcuts_edit_button.set_tooltip_text('Edit') self.shortcuts_edit_button.set_image( Gtk.Image(icon_name='document-edit-symbolic')) self.shortcuts_edit_button.set_sensitive(False) self.shortcuts_edit_button.connect( 'clicked', self.on_shortcuts_edit_button_clicked) actionbar.add(self.shortcuts_edit_button) self.shortcuts_tree_view.vbox.pack_end(actionbar, False, False, 0) self.show_all()
def __init__(self, transient_for, title='Preferences'): CustomDialog.__init__(self, transient_for=transient_for, title=title) self.parent = transient_for # Stack & Stack switcher vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5) content_area = self.get_content_area() content_area.add(vbox) stack = Gtk.Stack() stack.set_margin_top(5) #stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT) #stack.set_transition_duration(1000) stack_switcher = Gtk.StackSwitcher() stack_switcher.set_stack(stack) vbox.pack_start(stack_switcher, True, True, 0) vbox.pack_start(stack, True, True, 0) ### General box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5) stack.add_titled(box, 'general', 'General') ## Debug hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5) box.add(hbox) hbox.add(Gtk.Label('<b>Debug</b>', xalign=0, use_markup=True)) debug_switch = Gtk.Switch() debug_switch.set_active(self.parent.settings['Debug']['Enabled']) debug_switch.connect('notify::active', self.on_debug_switch_activated) hbox.pack_end(debug_switch, False, False, 0) # Level self.debug_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5) self.debug_box.set_margin_left(10) self.debug_box.set_sensitive(self.parent.settings['Debug']['Enabled']) box.add(self.debug_box) self.debug_box.add(Gtk.Label('Level')) debug_level_combo = CustomComboBox(['High', 'Normal', 'Low']) debug_level_combo.set_active(self.parent.settings['Debug']['Level']) debug_level_combo.connect('changed', lambda combo: settings.update_and_save(self.parent.settings, key='Debug', subkey='Level', value=combo.get_active())) self.debug_box.pack_end(debug_level_combo, False, False, 0) ## Game box.add(Gtk.Label('<b>Game</b>', xalign=0, use_markup=True)) # Version hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5) hbox.set_margin_left(10) box.add(hbox) hbox.add(Gtk.Label('Version')) game_version_list = [ { 'label': 'Retro', 'value': shared.GameVersion.Retro }, { 'label': '2.x', 'value': shared.GameVersion.Two } ] game_version_combo = TextValueComboBox(game_version_list, model=Gtk.ListStore(str, int), text_key='label', value_key='value') game_version_combo.set_active_value(self.parent.settings['Game']['Version']) game_version_combo.connect('changed', self.on_game_version_combo_changed) hbox.pack_end(game_version_combo, False, False, 0) # Window decoration height hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5) hbox.set_margin_left(10) use_custom_window_decoration_height_check = Gtk.CheckButton('Window decoration height') use_custom_window_decoration_height_check.set_active(self.parent.settings['Game']['UseCustomWindowDecorationHeight']) use_custom_window_decoration_height_check.set_tooltip_text('(in pixels)') use_custom_window_decoration_height_check.connect('clicked', lambda check: ( settings.update_and_save(self.parent.settings, key='Game', subkey='UseCustomWindowDecorationHeight', value=check.get_active()), self.window_decoration_height_spin_button.set_sensitive(check.get_active()) ) ) hbox.add(use_custom_window_decoration_height_check) self.window_decoration_height_spin_button = SpinButton(min=5, max=100) self.window_decoration_height_spin_button.set_value(self.parent.settings['Game']['WindowDecorationHeight']) self.window_decoration_height_spin_button.set_sensitive(self.parent.settings['Game']['UseCustomWindowDecorationHeight']) self.window_decoration_height_spin_button.connect('value-changed', lambda button: settings.update_and_save(self.parent.settings, key='Game', subkey='WindowDecorationHeight', value=button.get_value_as_int())) hbox.pack_end(self.window_decoration_height_spin_button, False, False, 0) box.add(hbox) # Keep game checkbox keep_game_on_unplug_check = Gtk.CheckButton('Keep game open when unbinding') keep_game_on_unplug_check.set_margin_left(10) keep_game_on_unplug_check.set_active(self.parent.settings['Game']['KeepOpen']) keep_game_on_unplug_check.connect('clicked', lambda check: settings.update_and_save(self.parent.settings, key='Game', subkey='KeepOpen', value=check.get_active())) box.add(keep_game_on_unplug_check) ## Account box.add(Gtk.Label('<b>Account</b>', xalign=0, use_markup=True)) # Exit game checkbox exit_game_on_disconnect_check = Gtk.CheckButton('Exit game when disconnecting') exit_game_on_disconnect_check.set_margin_left(10) exit_game_on_disconnect_check.set_active(self.parent.settings['Account']['ExitGame']) exit_game_on_disconnect_check.connect('clicked', lambda check: settings.update_and_save(self.parent.settings, key='Account', subkey='ExitGame', value=check.get_active())) box.add(exit_game_on_disconnect_check) ### Bot box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5) stack.add_titled(box, 'bot', 'Bot') ## State box.add(Gtk.Label('<b>State</b>', xalign=0, use_markup=True)) # PodBar hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5) hbox.set_margin_left(10) hbox.add(Gtk.Label('PodBar')) podbar_switch = Gtk.Switch() podbar_switch.set_active(self.parent.settings['State']['EnablePodBar']) podbar_switch.connect('notify::active', self.on_podbar_switch_activated) hbox.pack_end(podbar_switch, False, False, 0) box.add(hbox) # MiniMap hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5) hbox.set_margin_left(10) hbox.add(Gtk.Label('MiniMap')) minimap_switch = Gtk.Switch() minimap_switch.set_active(self.parent.settings['State']['EnableMiniMap']) minimap_switch.connect('notify::active', self.on_minimap_switch_activated) hbox.pack_end(minimap_switch, False, False, 0) box.add(hbox) ## Farming box.add(Gtk.Label('<b>Farming</b>', xalign=0, use_markup=True)) # Save dragodindes images save_dragodindes_images_check = Gtk.CheckButton('Save dragodindes images') save_dragodindes_images_check.set_margin_left(10) save_dragodindes_images_check.set_active(self.parent.settings['Farming']['SaveDragodindesImages']) save_dragodindes_images_check.connect('clicked', lambda check: settings.update_and_save(self.parent.settings, key='Farming', subkey='SaveDragodindesImages', value=check.get_active())) box.add(save_dragodindes_images_check) # Check resources color self.verify_resources_color_check = Gtk.CheckButton('Check resources color') self.verify_resources_color_check.set_margin_left(10) self.verify_resources_color_check.set_active(self.parent.settings['Farming']['CheckResourcesColor']) self.verify_resources_color_check.connect('clicked', lambda check: settings.update_and_save(self.parent.settings, key='Farming', subkey='CheckResourcesColor', value=check.get_active())) box.add(self.verify_resources_color_check) # Auto close popups self.auto_close_popups_check = Gtk.CheckButton('Auto close popups (level up, invitation, ...)') self.auto_close_popups_check.set_margin_left(10) self.auto_close_popups_check.set_active(self.parent.settings['Farming']['AutoClosePopups']) self.auto_close_popups_check.connect('clicked', lambda check: settings.update_and_save(self.parent.settings, key='Farming', subkey='AutoClosePopups', value=check.get_active())) box.add(self.auto_close_popups_check) # Collection time hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5) hbox.set_margin_left(10) label = Gtk.Label('Collection time') label.set_tooltip_text('(in seconds)') hbox.add(label) self.collection_time_spin_button = SpinButton(min=1, max=60) self.collection_time_spin_button.set_value(self.parent.settings['Farming']['CollectionTime']) self.collection_time_spin_button.connect('value-changed', lambda button: settings.update_and_save(self.parent.settings, key='Farming', subkey='CollectionTime', value=button.get_value_as_int())) hbox.pack_end(self.collection_time_spin_button, False, False, 0) box.add(hbox) # First resource additional collection time hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5) hbox.set_margin_left(10) label = Gtk.Label('1st resource collection time') label.set_tooltip_text('(additional time for 1st resource in seconds)') hbox.add(label) first_resource_collection_time_spin_button = SpinButton(min=1, max=60) first_resource_collection_time_spin_button.set_value(self.parent.settings['Farming']['FirstResourceAdditionalCollectionTime']) first_resource_collection_time_spin_button.connect('value-changed', lambda button: settings.update_and_save(self.parent.settings, key='Farming', subkey='FirstResourceAdditionalCollectionTime', value=button.get_value_as_int())) hbox.pack_end(first_resource_collection_time_spin_button, False, False, 0) box.add(hbox) ### Shortcuts box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5) stack.add_titled(box, 'shortcuts', 'Shortcuts') ## Keyboard Shortcuts hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) hbox.add(Gtk.Label('<b>Keyboard Shortcuts</b>', xalign=0, use_markup=True)) box.add(hbox) # Switch shortcuts_switch = Gtk.Switch() shortcuts_switch.set_active(self.parent.settings['EnableShortcuts']) shortcuts_switch.connect('notify::active', self.on_shortcuts_switch_activated) hbox.pack_end(shortcuts_switch, False, False, 0) # TreeView model = Gtk.ListStore(str, str) text_renderer = Gtk.CellRendererText() columns = [ Gtk.TreeViewColumn('Action', text_renderer, text=0), Gtk.TreeViewColumn('Shortcut', text_renderer, text=1) ] self.shortcuts_tree_view = CustomTreeView(model, columns) self.shortcuts_tree_view.vbox.set_sensitive(self.parent.settings['EnableShortcuts']) self.shortcuts_tree_view.connect('button-press-event', self.on_shortcuts_tree_view_double_clicked) self.shortcuts_tree_view.connect('selection-changed', self.on_shortcuts_tree_view_selection_changed) # fill treeview for action in sorted(self.parent.settings['Shortcuts']): shortcut = self.parent.settings['Shortcuts'][action] self.shortcuts_tree_view.append_row([action, shortcut], select=False, scroll_to=False) box.pack_start(self.shortcuts_tree_view, True, True, 0) # ActionBar actionbar = Gtk.ActionBar() self.shortcuts_edit_button = Gtk.Button() self.shortcuts_edit_button.set_tooltip_text('Edit') self.shortcuts_edit_button.set_image(Gtk.Image(icon_name='document-edit-symbolic')) self.shortcuts_edit_button.set_sensitive(False) self.shortcuts_edit_button.connect('clicked', self.on_shortcuts_edit_button_clicked) actionbar.add(self.shortcuts_edit_button) self.shortcuts_tree_view.vbox.pack_end(actionbar, False, False, 0) self.show_all()