def align_clock(self): current_halign = int(self.get_halign()) horizontal = current_halign current_valign = int(self.get_valign()) vertical = current_valign while horizontal == current_halign: horizontal = ALIGNMENTS[random.randint(0, 2)] while vertical == current_valign: vertical = ALIGNMENTS[random.randint(0, 2)] self.set_halign(Gtk.Align(horizontal)) self.set_valign(Gtk.Align(vertical)) if self.screen.get_n_monitors() > 1: new_monitor = self.current_monitor n = self.screen.get_n_monitors() while new_monitor == self.current_monitor: new_monitor = random.randint(0, n - 1) self.current_monitor = new_monitor self.queue_resize() self.reveal() trackers.timer_tracker_get().cancel(str(self) + "align-timeout") return False
def positioning_callback(self): current_halign = int(self.get_halign()) horizontal = current_halign current_valign = int(self.get_valign()) vertical = current_valign while horizontal == current_halign: horizontal = ALIGNMENTS[random.randint(0, 2)] while vertical == current_valign: vertical = ALIGNMENTS[random.randint(0, 2)] self.set_halign(Gtk.Align(horizontal)) self.set_valign(Gtk.Align(vertical)) if status.screen.get_n_monitors() > 1: new_monitor = self.current_monitor n = status.screen.get_n_monitors() while new_monitor == self.current_monitor: new_monitor = random.randint(0, n - 1) self.current_monitor = new_monitor self.queue_resize() return True
def agregar_lbl_en_box(self, nom_lbl, texto, angulo, halign): nom_lbl = Gtk.Label() nom_lbl.set_label(texto) nom_lbl.set_angle(angulo) nom_lbl.set_halign( Gtk.Align(halign)) # 0 = Centrado - 1 = Izquierda - 2 = Derecha self.box.pack_start(nom_lbl, True, True, 0)
def on_settings_button_clicked(self, widget): """Open settings dialog""" dialog = Gtk.Dialog("Settings", self, Gtk.DialogFlags.MODAL, ("Cancel", Gtk.ResponseType.CANCEL, "Apply", Gtk.ResponseType.APPLY)) dialog.set_border_width(20) # Grid for settings options grid = Gtk.Grid(row_homogeneous=True, row_spacing=20) grid.attach(Gtk.Label("Tolerance:"), 0, 0, 1, 1) grid.attach(Gtk.Label("Include unknown faces:"), 0, 1, 1, 1) grid.attach(Gtk.Label("Strict search:"), 0, 2, 1, 1) # Settings options tolerance_entry = Gtk.Entry() global tolerance tolerance_entry.set_text(str(tolerance)) grid.attach(tolerance_entry, 1, 0, 1, 1) include_unknown_check = Gtk.CheckButton(active=True, halign=Gtk.Align(3)) grid.attach(include_unknown_check, 1, 1, 1, 1) strict_search_check = Gtk.CheckButton(active=True, halign=Gtk.Align(3)) grid.attach(strict_search_check, 1, 2, 1, 1) # Add grid to dialog area = dialog.get_content_area() area.add(grid) dialog.show_all() response = dialog.run() # Apply changes if response == Gtk.ResponseType.APPLY: global include_unknown, strict_search tolerance = float(tolerance_entry.get_text()) include_unknown = include_unknown_check.get_active() strict_search = strict_search_check.get_active() dialog.destroy()
def __init__(self): settings = Gio.Settings.new(self.BASE_KEY) nswitch = Gtk.Switch() window = Gtk.Window() window.connect('destroy', lambda w: Gtk.main_quit()) window.set_title('Music Integration Preferences') window.set_default_size(400, 160) window.set_border_width(6) window.set_position(Gtk.WindowPosition.CENTER) mainvbox = Gtk.VBox(spacing=6) window.add(mainvbox) mainhbox = Gtk.HBox() mainvbox.add(mainhbox) spacebox1 = Gtk.HBox() mainhbox.add(spacebox1) spacebox1.set_size_request(30, 0) vbox = Gtk.VBox() mainhbox.add(vbox) spacebox2 = Gtk.HBox() mainhbox.add(spacebox2) spacebox2.set_size_request(30, 0) label = Gtk.Label("") vbox.pack_start(label, False, True, 0) labelT = Gtk.Label("Choose your default setup :") vbox.pack_start(labelT, False, True, 0) hplayerbox = Gtk.HBox(spacing=0) vbox.pack_start(hplayerbox, False, True, 0) hpalign = Gtk.Align(3) hplayerbox.set_halign(hpalign) player = Gtk.ComboBoxText() hplayerbox.pack_start(player, False, True, 0) player.append_text('Choose a setup :') player.append_text('Player as Indicator in Panel') player.append_text('Player in Volume Menu') player.append_text('Notifications only') player.connect('changed', self.keys_change, settings, nswitch) player.set_active(int(settings.get_string("setup"))) player.set_size_request(300, 0) nlabel1 = Gtk.Label("") vbox.pack_start(nlabel1, False, True, 0) nhbox = Gtk.Box(spacing=0) vbox.pack_start(nhbox, False, True, 0) nhbox.set_size_request(300, 30) nlabel = Gtk.Label("Notifications") nhbox.pack_start(nlabel, False, True, 0) nswitch.set_active(settings.get_boolean("notification")) nswitch.connect('notify::active', self.n_change, settings) nhbox.pack_end(nswitch, False, True, 0) cohbox = Gtk.Box(spacing=0) vbox.pack_start(cohbox, False, True, 0) cohbox.set_size_request(300, 30) colabel = Gtk.Label("Cover Art Time Overlay") cohbox.pack_start(colabel, False, True, 0) coswitch = Gtk.Switch() coswitch.set_active(settings.get_boolean("overlay")) coswitch.connect('notify::active', self.co_change, settings) cohbox.pack_end(coswitch, False, True, 0) emptylabel = Gtk.Label("") mainvbox.add(emptylabel) quithbox = Gtk.HBox() mainvbox.add(quithbox) quitbutton = Gtk.Button("Quit") quitbutton.connect("clicked", Gtk.main_quit) quithbox.pack_start(quitbutton, False, True, 0) quitalign = Gtk.Align(2) quithbox.set_halign(quitalign) window.show_all() return
def __init__(self): settings = Gio.Settings.new(self.BASE_KEY) nswitch = Gtk.Switch() mlswitch = Gtk.Switch() window = Gtk.Window() window.connect('destroy', lambda w: Gtk.main_quit()) window.set_title('Music Integration Preferences') window.set_icon_name(Gtk.STOCK_PREFERENCES) window.set_default_size(400, 160) window.set_border_width(6) window.set_title(_('Music Integration Preferences')) window.set_icon_name(Gtk.STOCK_PREFERENCES) window.set_default_size(400, 100) window.set_border_width(10) window.set_position(Gtk.WindowPosition.CENTER) mainvbox = Gtk.VBox(spacing=6) window.add(mainvbox) mainhbox = Gtk.HBox() mainvbox.add(mainhbox) vbox = Gtk.VBox() mainhbox.add(vbox) hplayerbox = Gtk.Box(spacing=0) vbox.pack_start(hplayerbox, False, True, 0) labelT = Gtk.Label(_("Place Music as:")) hplayerbox.pack_start(labelT, False, True, 0) player = Gtk.ComboBoxText() player.append_text(_('Indicator in Right Panel')) player.append_text(_('Indicator in Center Panel')) player.append_text(_('Part of the Volume Menu')) player.append_text(_('Don\'t show in Panel')) player.connect('changed', self.keys_change, settings, nswitch, mlswitch) player.set_active(int(settings.get_string("setup"))) hplayerbox.pack_end(player, False, True, 2) label = Gtk.Label("") vbox.pack_start(label, False, True, 0) nhbox = Gtk.Box(spacing=0) vbox.pack_start(nhbox, False, True, 0) nlabel = Gtk.Label(_("Notifications")) nhbox.pack_start(nlabel, False, True, 0) nswitch.set_active(settings.get_boolean("notification")) nswitch.connect('notify::active', self.n_change, settings) nhbox.pack_end(nswitch, False, True, 2) mlhbox = Gtk.Box(spacing=0) vbox.pack_start(mlhbox, False, True, 0) mllabel = Gtk.Label(_("Song name in the panel")) mlhbox.pack_start(mllabel, False, True, 0) mlswitch.set_active(settings.get_boolean("musiclabel")) mlswitch.connect('notify::active', self.ml_change, settings) mlhbox.pack_end(mlswitch, False, True, 2) cohbox = Gtk.Box(spacing=0) vbox.pack_start(cohbox, False, True, 0) colabel = Gtk.Label(_("Time over cover art")) cohbox.pack_start(colabel, False, True, 0) coswitch = Gtk.Switch() coswitch.set_active(settings.get_boolean("overlay")) coswitch.connect('notify::active', self.co_change, settings) cohbox.pack_end(coswitch, False, True, 2) quithbox = Gtk.HBox() mainvbox.add(quithbox) quitbutton = Gtk.Button(_("Quit")) quitbutton.connect("clicked", Gtk.main_quit) quithbox.pack_start(quitbutton, False, True, 0) quitalign = Gtk.Align(2) quithbox.set_halign(quitalign) window.show_all() return
def __init__(self, config, *args, **kwargs): Gtk.ApplicationWindow.__init__(self, *args, **kwargs) self.set_default_size(950, 700) self.connect("delete-event", self.on_delete_event) # Get the settings from the config file self.config = config # Set up a list of buffer objects, holding data for every buffer self.buffers = BufferList() self.buffers.connect("bufferSwitched", self.on_buffer_switched) self.buffers.connect_after( "bufferSwitched", self.after_buffer_switched) # Set up GTK box box_horizontal = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0) self.add(box_horizontal) # Set up a headerbar self.headerbar = Gtk.HeaderBar() self.headerbar.set_has_subtitle(True) self.headerbar.set_title("Gtk-WeeChat") self.headerbar.set_subtitle("Not connected.") self.headerbar.set_show_close_button(True) self.set_titlebar(self.headerbar) # Add widget showing list of buffers box_horizontal.pack_start( self.buffers.treescrolledwindow, False, False, 0) sep = Gtk.Separator() box_horizontal.pack_start(sep, False, False, 0) # Add stack of buffers box_horizontal.pack_start(self.buffers.stack, True, True, 0) # Set up a menu menubutton = Gtk.MenuButton() icon = Gio.ThemedIcon(name="open-menu-symbolic") image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.BUTTON) menubutton.get_child().destroy() menubutton.add(image) menubutton.show_all() self.headerbar.pack_end(menubutton) menu = Gtk.Menu() menu.set_halign(Gtk.Align(3)) menuitem_darkmode = Gtk.CheckMenuItem(label="Dark") menuitem_darkmode.connect("toggled", self.on_darkmode_toggled) menuitem_darkmode.show() menu.append(menuitem_darkmode) menu_sep = Gtk.SeparatorMenuItem() menu_sep.show() menu.append(menu_sep) self.menuitem_connect = Gtk.MenuItem(label="Connect") self.menuitem_connect.connect("activate", self.on_connect_clicked) self.menuitem_connect.show() menu.append(self.menuitem_connect) self.menuitem_disconnect = Gtk.MenuItem(label="Disconnect") self.menuitem_disconnect.connect( "activate", self.on_disconnect_clicked) self.menuitem_disconnect.set_sensitive(False) self.menuitem_disconnect.show() menu.append(self.menuitem_disconnect) menuitem_quit = Gtk.MenuItem(label="Quit") menuitem_quit.set_action_name("app.quit") menuitem_quit.show() menu.append(menuitem_quit) menubutton.set_popup(menu) # Make everything visible (All is hidden by default in GTK 3) self.show_all() # Set up the network module self.net = Network(self.config) self.net.connect("messageFromWeechat", self._network_weechat_msg) self.net.connect("connectionChanged", self._connection_changed) # Connect to connection settings signals CONNECTION_SETTINGS.connect("connect", self.on_settings_connect) # Set up actions action = Gio.SimpleAction.new("buffer_next", None) action.connect("activate", self.buffers.on_buffer_next) self.add_action(action) action = Gio.SimpleAction.new("buffer_prev", None) action.connect("activate", self.buffers.on_buffer_prev) self.add_action(action) action = Gio.SimpleAction.new("copy_to_clipboard", None) action.connect("activate", self.buffers.on_copy_to_clipboard) self.add_action(action) action = Gio.SimpleAction.new("buffer_expand", None) action.connect("activate", self.on_buffer_expand) self.add_action(action) action = Gio.SimpleAction.new("buffer_collapse", None) action.connect("activate", self.on_buffer_collapse) self.add_action(action) # Autoconnect if necessary if self.net.check_settings() is True and \ self.config["relay"]["autoconnect"] == "on": if self.net.connect_weechat() is False: print("Failed to connect.") else: self.menuitem_connect.set_sensitive(False) self.menuitem_disconnect.set_sensitive(True) else: CONNECTION_SETTINGS.display() # Enable darkmode if enabled before self.dark_fallback_provider = Gtk.CssProvider() self.dark_fallback_provider.load_from_path( "{}/dark_fallback.css".format(CONFIG_DIR)) if STATE.get_dark(): menuitem_darkmode.set_active(True) # Sync our local hotlist with the weechat server GLib.timeout_add_seconds(60, self.request_hotlist)
def __init__(self, settings): Gtk.Window.__init__(self, title="Connection") self.set_type_hint(Gdk.WindowTypeHint.DIALOG) self.set_modal(True) self.set_keep_above(True) self.settings = settings self.connect("destroy", self._on_cancel) grid = Gtk.Grid() # Set up a headerbar headerbar = Gtk.HeaderBar() headerbar.set_has_subtitle(False) headerbar.set_title("Connection") headerbar.set_show_close_button(False) self.set_titlebar(headerbar) grid.set_column_spacing(5) grid.set_row_spacing(5) grid.set_margin_end(20) grid.set_margin_start(20) grid.set_margin_top(20) grid.set_margin_bottom(20) self.add(grid) label_names = ["Host", "Port", "Password", "SSL", "Autoconnect"] for index, name in enumerate(label_names): label = Gtk.Label(name) label.set_halign(Gtk.Align(2)) grid.attach(label, 0, index, 1, 1) self.entry1 = Gtk.Entry() grid.attach(self.entry1, 1, 0, 1, 1) self.entry1.set_activates_default(True) self.entry2 = Gtk.Entry() grid.attach(self.entry2, 1, 1, 1, 1) self.entry2.set_activates_default(True) self.entry3 = Gtk.Entry() self.entry3.set_visibility(False) grid.attach(self.entry3, 1, 2, 1, 1) self.entry3.set_activates_default(True) switch1_box = Gtk.Box() switch2_box = Gtk.Box() self.switch1 = Gtk.Switch() self.switch2 = Gtk.Switch() grid.attach(switch1_box, 1, 3, 1, 1) grid.attach(switch2_box, 1, 4, 1, 1) switch1_box.pack_start(self.switch1, False, False, 0) switch2_box.pack_start(self.switch2, False, False, 0) cancel_button = Gtk.Button(label="Cancel") connect_button = Gtk.Button(label="Connect") headerbar.pack_end(connect_button) headerbar.pack_start(cancel_button) style_context = connect_button.get_style_context() style_context.add_class("suggested-action") connect_button.set_can_default(True) connect_button.grab_default() cancel_button.connect("clicked", self._on_cancel) connect_button.connect("clicked", self._on_connect)