Esempio n. 1
0
 def disconnect(self, win: Gtk.Window, view: View) -> None:
     try:
         win.disconnect_by_func(view.page_activated)
         win.disconnect_by_func(view.pages_selected)
     except Exception as e:
         print(e)
         pass
Esempio n. 2
0
def build_image_compare_window(window: Gtk.Window):
    grouped_images = {}
    for image in get_duplicates():
        grouped_images.setdefault(image["phash"], []).append(image)

    duplicates_app = DuplicatesApp(grouped_images)
    window.add(duplicates_app)
Esempio n. 3
0
def get_monitor_screen(window: Gtk.Window):
    display = window.get_display()
    logger.debug('Display: {}, {}', display, display.get_name())
    # FIXME: It returns wrong monitor
    monitor = display.get_monitor_at_window(window.get_window())
    geo = monitor.get_geometry()
    w, h = geo.width, geo.height
    logger.debug('Monitor size: {}', (w, h))
    return (w, h)
Esempio n. 4
0
def win_add_action(
    win: Gtk.Window, name: str, shortcut: str,
    callback: Callable[[Gio.SimpleAction, GLib.Variant], None]
) -> Gio.SimpleAction:
    action = Gio.SimpleAction.new(name, None)
    win.add_shortcut(new_action_shortcut(shortcut, f'win.{name}'))
    action.connect('activate', callback)
    win.add_action(action)
    return action
Esempio n. 5
0
def present_window(window: Gtk.Window):
    if window.is_active():
        return

    timestamp = Gtk.get_current_event_time()
    if timestamp == 0:
        from gi.repository import GdkX11
        timestamp = GdkX11.x11_get_server_time(window.get_window())

    window.present_with_time(timestamp)
Esempio n. 6
0
def resize_window(window: Gtk.Window, width: int, height: int) -> None:
    """
    Resize window, but also checks if huge window or negative values
    """
    screen_w, screen_h = get_total_screen_geometry()
    if not width or not height:
        return
    if width > screen_w:
        width = screen_w
    if height > screen_h:
        height = screen_h
    window.resize(abs(width), abs(height))
Esempio n. 7
0
    def apply_to_window(self, window: Gtk.Window):
        accel_group = Gtk.AccelGroup()
        for hot_key in self.entries:
            # noinspection PyDefaultArgument
            def callback(_group,
                         _acceleratable,
                         _keyval,
                         _modifier,
                         args=hot_key.args):
                hot_key.callback(window, *args)

            accel_group.connect(hot_key.key, hot_key.mode, 0, callback)
        window.add_accel_group(accel_group)
Esempio n. 8
0
def move_window(window: Gtk.Window, pos_x: int, pos_y: int) -> None:
    """
    Move the window, but also check if out of screen
    """
    screen_w, screen_h = get_total_screen_geometry()
    if pos_x < 0:
        pos_x = 0
    if pos_y < 0:
        pos_y = 0
    width, height = window.get_size()
    if pos_x + width > screen_w:
        pos_x = screen_w - width
    if pos_y + height > screen_h:
        pos_y = screen_h - height
    window.move(pos_x, pos_y)
Esempio n. 9
0
def set_strut(gdkwin: Gtk.Window):
    from Xlib import display, Xatom
    height = gdkwin.get_height()
    width = Gdk.Display.get_default().get_monitor_at_window(
        gdkwin).get_geometry().width

    disp = display.Display()
    xwin = disp.create_resource_object("window", gdkwin.get_xid())
    xwin.change_property(disp.intern_atom("_NET_WM_STRUT"), Xatom.CARDINAL, 32,
                         [0, 0, 0, height])
    xwin.change_property(disp.intern_atom("_NET_WM_STRUT_PARTIAL"),
                         Xatom.CARDINAL, 32,
                         [0, 0, 0, height, 0, 0, 0, 0, 0, 0, 0, width])
    disp.sync()
    disp.close()
    print(height, width)
Esempio n. 10
0
    def __init__(self, languages, *args, **kwargs):
        Window.__init__(self, *args, **kwargs)

        icon = lambda x: IconTheme.get_default().load_icon((name), x, 0)
        icons = [icon(size) for size in [32, 48, 64, 96]]
        self.set_icon_list(icons)

        self.languages.set_header_func(self.update_header)
        for language in languages:
            row = ListBoxRow()
            label = Label()
            label.set_text(language['itemLabel']['value'])
            label.code = language['c']['value']
            row.child = label
            row.add(label)
            self.languages.add(row)
        self.languages.show_all()
Esempio n. 11
0
    def __init__(self, *args, new_session=True, quit_cb=None, verbose=False):
        Window.__init__(self, *args)

        # Set window icon
        icon = lambda x: IconTheme.get_default().load_icon((name), x, 0)
        icons = [icon(size) for size in [32, 48, 64, 96]];
        self.set_icon_list(icons);

        self.verbose = verbose
        self.new_session = new_session
        self.results_listbox.selected = EntitySet()
        self.filtered_results = EntitySet()
        self.entities = self.results_listbox.selected
        self.variables = EntitySet(triplet=False)
        self.hb_title = self.header_bar.get_title()
        self.hb_subtitle = self.header_bar.get_subtitle()

        self.search_entry_connection = self.search_entry.connect("search-changed",
                                                                 self.search_entry_search_changed_cb)

        self.filters_listbox = FiltersList()
        self.filters_viewport.add(self.filters_listbox)

        if quit_cb:
            self.quit_cb = quit_cb
            self.connect("delete-event", self.on_quit)
        self.show()

        if new_session:
            self.header_bar.set_show_close_button(True)
        else:
            self.header_bar.set_show_close_button(False)
            self.back.set_visible(True)

        self.open_button.connect('clicked', self.open_button_clicked_cb)
        text = """<b>Search for an <a href="url">entity</a> in the database</b>"""
        if system() == 'Linux':
            url = "help:daty/daty-entities"
        if system() == 'Windows':
            url = "http://daty.prevete.ml/daty-entities.html"
        text = sub('url', url, text)
        set_text(self.subtitle, text, url, markup=True)
Esempio n. 12
0
    def __init__(self, *args, **kwargs):
        Window.__init__(self, *args, **kwargs)

        icon = lambda x: IconTheme.get_default().load_icon((name), x, 0)
        icons = [icon(size) for size in [32, 48, 64, 96]]
        self.set_icon_list(icons)

        self.credentials.set_header_func(self.update_header)
        self.languages.set_header_func(self.update_header)

        for key in self.config.data['credentials']:
            row = ListBoxRow()
            grid = Grid()
            grid.props.column_homogeneous = True
            label = Label()
            label.set_text(key)
            label.props.halign = Align(1)
            context = label.get_style_context()
            resource = "/ml/prevete/Daty/gtk/value.css"
            set_style(context, resource, "dim-label", True)
            entry = Entry()
            entry.set_text(self.config.data['credentials'][key])
            context = entry.get_style_context()
            set_style(context, resource, "flat", True)
            grid.attach(label, 0, 0, 1, 1)
            grid.attach(entry, 1, 0, 2, 1)
            row.add(grid)
            self.credentials.add(row)
        self.credentials.show_all()

        query = """SELECT ?item ?itemLabel ?c
{
  ?item wdt:P424 ?c .
  MINUS{?item wdt:P31/wdt:P279* wd:Q14827288} #exclude Wikimedia projects
  MINUS{?item wdt:P31/wdt:P279* wd:Q17442446} #exclude Wikimedia internal stuff
  SERVICE wikibase:label { bd:serviceParam wikibase:language "your_first_language". }
}
        """

        query = sub("your_first_language", self.config.data['languages'][0],
                    query)
        self.retrieve(query, self.languages_callback)
Esempio n. 13
0
    def on_active_window_changed(self, screen: Wnck.Screen,
                                 previously_active_window: Gtk.Window) -> None:
        now = datetime.now()

        # to prevent double handler connections
        if previously_active_window and self.name_changed_handler_id:
            previously_active_window.disconnect(self.name_changed_handler_id)

        active_window = screen.get_active_window()

        if active_window:
            self.name_changed_handler_id = active_window.connect(
                'name-changed', self.on_name_changed)
            wm_class = get_wm_class(active_window.get_xid())
            window_name = get_window_name(active_window)
        else:
            wm_class = SpecialWmClass.DESKTOP.value
            window_name = ''

        self.on_open_window(wm_class, window_name, now)
Esempio n. 14
0
 def _file_dialog_handler(self, saver_dialog: Gtk.Dialog, window: Gtk.Window):
     response = saver_dialog.run()
     if response == Gtk.ResponseType.OK:
         doc = window.get_active_document()
         # save the document with Gedit's save as function
         gfile_path = Gio.File.new_for_path(saver_dialog.get_filename())
         doc.save_as(gfile_path, doc.get_encoding(), doc.get_newline_type(), doc.get_compression_type(),
                     Gedit.DocumentSaveFlags(15))
         saver_dialog.destroy()
     elif response == Gtk.ResponseType.CANCEL:
         saver_dialog.destroy()
    def add_source(self, source_list_widget: Gtk.ListBox, window: Gtk.Window):
        dialog = Gtk.FileChooserDialog(
            "Wybierz plik z przykładowymi tekstami",
            window,
            Gtk.FileChooserAction.OPEN,
            (
                Gtk.STOCK_CANCEL,
                Gtk.ResponseType.CANCEL,
                Gtk.STOCK_OPEN,
                Gtk.ResponseType.OK,
            ),
        )

        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            print(dialog.get_filename())
            lines = open(dialog.get_filename(), encoding='utf8').read().splitlines()
            self.__marcow_chain.feed(lines)
            source_list_widget.add(Gtk.Label(dialog.get_filename()))
            window.show_all()
        dialog.destroy()
Esempio n. 16
0
def load_tlp_config(_, window: Gtk.Window, reloadtlpconfig: bool) -> None:
    """Load TLP configuration to UI."""
    if reloadtlpconfig:
        init_tlp_file_config()

    newmainbox = create_main_box(window)
    children = window.get_children()
    for child in children:
        window.remove(child)
    window.add(newmainbox)
    window.show_all()
Esempio n. 17
0
def load_tlp_config(self, window: Gtk.Window, reloadtlpconfig: bool):

    if reloadtlpconfig:
        settings.tlpconfig = read_tlp_file_config(settings.tlpconfigfile)
        settings.tlpconfig_original = copy.deepcopy(settings.tlpconfig)

    newmainbox = create_main_box(window)
    children = window.get_children()
    for child in children:
        window.remove(child)
    window.add(newmainbox)
    window.show_all()
Esempio n. 18
0
def load_tlp_config(_, window: Gtk.Window, reloadtlpconfig: bool) -> None:
    """Load TLP configuration to UI"""

    if reloadtlpconfig:
        settings.tlpconfig = read_tlp_file_config(settings.tlpconfigfile)
        settings.tlpconfig_original = copy.deepcopy(settings.tlpconfig)

    newmainbox = create_main_box(window)
    children = window.get_children()
    for child in children:
        window.remove(child)
    window.add(newmainbox)
    window.show_all()
Esempio n. 19
0
def resize_to_match_screen(window: Gtk.Window):
    '''Try to detect desktop or mobile screen, and resize to promote the horizontal or vertical layout.'''
    scale = window.get_scale_factor()
    best_horizontal_width = BEST_HORIZONTAL_WIDTH / scale
    best_vertical_height = BEST_VERTICAL_HEIGHT / scale
    sw, sh = get_monitor_screen(window)
    w, h = window.get_size()
    logger.debug('Current window size: {}', (w, h))
    if sw > best_horizontal_width:
        window.resize(best_horizontal_width, h)
    elif sh > best_vertical_height:
        window.resize(w, best_vertical_height)
Esempio n. 20
0
    def run(self, settings=None, window=None, debug=False, on_close=None):
        self.on_close = on_close
        threads_init()

        if window is None:
            self.window = Window(WindowType.TOPLEVEL)
            self.window.set_position(WindowPosition.CENTER_ALWAYS)
        else:
            self.window = window

        browser = self.controller.get_browser(self.uri, debug=debug,
                                              settings=settings)
        self.window.connect("delete-event", self.quit)
        self.window.set_border_width(0)
        self.window.add(browser)

        sleep(1)
        self.window.show_all()
        self.window.show()
        main()
Esempio n. 21
0
    def __init__(self, parent: Gtk.Window, dialog_flags: Gtk.DialogFlags,
                 message_type: Gtk.MessageType, buttons_type: Gtk.ButtonsType,
                 *args, **kwargs):
        img = IMGS[message_type]
        if IS_SUCCESS in kwargs:
            if kwargs[IS_SUCCESS]:
                img = IMG_HAPPY
            del kwargs[IS_SUCCESS]
        self.img: Gtk.Image = Gtk.Image.new_from_file(
            os.path.join(data_dir(), img))
        super().__init__(parent, dialog_flags, message_type, buttons_type,
                         *args, **kwargs)

        box: Gtk.Box = self.get_message_area()
        parent: Gtk.Box = box.get_parent()
        box.set_valign(Gtk.Align.CENTER)

        parent.pack_start(self.img, False, False, 0)
        parent.pack_start(box, False, False, 0)

        parent.child_set_property(self.img, 'position', 0)
        self.img.show()
Esempio n. 22
0
 def init(self, window: Gtk.Window) -> None:
     logger.debug("action=init")
     window.add_accel_group(self.accel_group)
Esempio n. 23
0
    def __init__(self, builder: Gtk.Builder, window: Gtk.Window,
                 settings: SkyTempleSettingsStore):
        self.builder = builder
        self._window = window
        self.__class__._instance = self

        self.settings = settings
        self.recent_files = self.settings.get_recent_files()

        self._load_support_images()

        # Created on demand
        self._loading_dialog: Gtk.Dialog
        self._main_item_list: Gtk.TreeView
        self._main_item_filter: Gtk.TreeModel
        self._last_selected_view_model: Optional[Gtk.TreeModel] = None
        self._last_selected_view_iter: Optional[Gtk.TreeIter] = None

        self._recent_files_store: Gtk.ListStore = self.builder.get_object(
            'recent_files_store')
        self._item_store: Gtk.TreeStore = builder.get_object('item_store')
        self._editor_stack: Gtk.Stack = builder.get_object('editor_stack')

        builder.connect_signals(self)
        window.connect("destroy", self.on_destroy)

        self._search_text: Optional[str] = None
        self._current_view_module: Optional[AbstractModule] = None
        self._current_view_controller: Optional[AbstractController] = None
        self._current_view_controller_class: Optional[
            Type[AbstractController]] = None
        self._current_view_item_id: Optional[int] = None
        self._resize_timeout_id: Optional[int] = None
        self._loaded_map_bg_module: Optional['MapBgModule'] = None
        self._current_breadcrumbs: List[str] = []
        self._after_save_action = None
        self.csd_enabled = self.settings.csd_enabled()

        if not sys.platform.startswith('darwin'):
            # Don't load the window position on macOS to prevent
            # the window from getting stuck on a disconnected screen
            self._load_position_and_size()

        self._configure_csd()
        self._load_icon()
        self._load_recent_files()
        self._connect_item_views()
        self._configure_error_view()
        self._check_for_updates()
        self._check_for_banner()
        self._check_for_native()

        self._debugger_manager = DebuggerManager()

        self.tilequant_controller = TilequantController(
            self._window, self.builder)
        self.settings_controller = SettingsController(self._window,
                                                      self.builder,
                                                      self.settings)

        GLib.idle_add(lambda: self._ask_for_sentry())
Esempio n. 24
0
def set_alpha(win: Gtk.Window) -> None:
    visual = win.get_screen().get_rgba_visual()
    win.set_visual(visual)
    win.set_app_paintable(True)
Esempio n. 25
0
def set_css(win: Gtk.Window) -> None:
    provider = Gtk.CssProvider()
    provider.load_from_data(css)
    Gtk.StyleContext.add_provider_for_screen(win.get_screen(), provider,
                                             Gtk.STYLE_PROVIDER_PRIORITY_USER)
Esempio n. 26
0
class Zaguan(object):
    def __init__(self, uri, controller=None):
        if controller is None:
            controller = WebContainerController()
        self.controller = controller
        self.uri = uri
        self.on_close = None

    def run(self, settings=None, window=None, debug=False, on_close=None):
        self.on_close = on_close
        threads_init()

        if window is None:
            self.window = Window(WindowType.TOPLEVEL)
            self.window.set_position(WindowPosition.CENTER_ALWAYS)
        else:
            self.window = window

        browser = self.controller.get_browser(self.uri, debug=debug,
                                              settings=settings)
        self.window.connect("delete-event", self.quit)
        self.window.set_border_width(0)
        self.window.add(browser)

        sleep(1)
        self.window.show_all()
        self.window.show()
        main()

    def quit(self, widget, event):
        if self.on_close is not None:
            self.on_close(widget, event)
Esempio n. 27
0
 def on_close(win: Gtk.Window, _event: Gdk.Event) -> bool:
     win.destroy()
     self._plugin_window = None
     return False
Esempio n. 28
0
    def initialize(self, window: Gtk.Window) -> None:
        logger.debug("component=shortcuts action=initialize")

        window.add_accel_group(self.accel_group)
Esempio n. 29
0
 def connect(self, win: Gtk.Window, view: View) -> None:
     win.connect('page_activated', view.page_activated)
     win.connect('pages_selected', view.pages_selected)
Esempio n. 30
0
 def hdl_response(dialog: Gtk.Window, *_) -> None:
     self._file_exists_info_dialog = None
     dialog.destroy()
Esempio n. 31
0
    def __init__(self, extensions):
        # Start threads
        threads_init()

        self.extensions = extensions

        # Create the main Bluemindo window
        self.main_window = Window()
        functions.open_bluemindo(self.main_window)

        # Handling close button
        def close_window(wdg, ka):
            functions.close_bluemindo(self.main_window, True)

        self.main_window.connect('delete_event', close_window)

        # Create the whole Header Bar
        box = HeaderBar()
        box.set_show_close_button(True)
        box.props.title = 'Bluemindo'
        self.main_window.set_titlebar(box)

        # Add an icon to the window
        icon_file = join(functions.datadir, 'image', 'logo_head_small.png')
        pixbuf = Pixbuf.new_from_file(icon_file)
        self.main_window.set_icon(pixbuf)

        # Add the about button
        about_button = Button(relief=2)
        about_button.add(
            Image.new_from_gicon(ThemedIcon(name='help-about-symbolic'),
                                 IconSize.BUTTON))
        box.pack_end(about_button)

        # Add the reload button
        refresh_button = Button(relief=2)
        refresh_button.add(
            Image.new_from_gicon(ThemedIcon(name='view-refresh-symbolic'),
                                 IconSize.BUTTON))
        box.pack_end(refresh_button)

        # Add PREVIOUS/STOP/PLAYPAUSE/NEXT buttons
        player_box = Box(orientation=Orientation.HORIZONTAL)
        StyleContext.add_class(player_box.get_style_context(), 'linked')

        previous_b = Button()
        previous_b.set_size_request(42, -1)
        previous_b.add(
            Image.new_from_gicon(
                ThemedIcon(name='media-skip-backward-symbolic'),
                IconSize.BUTTON))
        player_box.add(previous_b)

        stop_b = Button()
        stop_b.set_size_request(42, -1)
        stop_b.add(
            Image.new_from_gicon(
                ThemedIcon(name='media-playback-stop-symbolic'),
                IconSize.BUTTON))
        player_box.add(stop_b)

        playpause_b = Button()
        playpause_b.set_size_request(55, -1)
        playpause_b.add(
            Image.new_from_gicon(
                ThemedIcon(name='media-playback-start-symbolic'),
                IconSize.BUTTON))
        player_box.add(playpause_b)

        next_b = Button()
        next_b.set_size_request(42, -1)
        next_b.add(
            Image.new_from_gicon(
                ThemedIcon(name='media-skip-forward-symbolic'),
                IconSize.BUTTON))
        player_box.add(next_b)

        box.pack_start(player_box)

        # Create the main window
        glade_main = join(functions.datadir, 'glade', 'mainwindow.ui')
        win = gtk_builder()
        win.set_translation_domain('bluemindo')
        win.add_from_file(glade_main)

        self.main_window.add(win.get_object('box1'))

        # Connect to the about button
        def show_dialog(wdg):
            dialog = AboutDialog()
            dialog.set_transient_for(self.main_window)

            dialog.set_artists(['Thomas Julien <*****@*****.**>'])
            dialog.set_authors([
                'Erwan Briand <*****@*****.**>',
                'Vincent Berset <*****@*****.**>',
                'Thibaut Girka <*****@*****.**>',
                'Ľubomír Remák <*****@*****.**>',
                'Anaël Verrier <*****@*****.**>'
            ])
            dialog.set_translator_credits(
                'Bruno Conde <*****@*****.**>\n' +
                'Niklas Grahn <*****@*****.**>\n' +
                'Ľubomír Remák <*****@*****.**>\n' +
                'Salvatore Tomarchio <*****@*****.**>\n' +
                'Shang Yuanchun <*****@*****.**>')

            dialog.set_copyright('Copyright © 2007-2016 Erwan Briand ' +
                                 '<*****@*****.**>')

            dialog.set_comments(
                _('Ergonomic and modern music player ' +
                  'designed for audiophiles.'))

            dialog.set_license('GNU General Public License (v3)')
            dialog.set_license_type(10)

            dialog.set_program_name('Bluemindo')
            dialog.set_version('1.0RC1')
            dialog.set_website('http://bluemindo.codingteam.net')

            pxbf = Pixbuf.new_from_file_at_scale(
                join(functions.datadir, 'image', 'logo_head_big.png'), 60, 60,
                True)
            dialog.set_logo(pxbf)

            dialog.show_all()

        about_button.connect('clicked', show_dialog)

        # Start main handler
        headerbar_wdg = [
            box, None, about_button, refresh_button, player_box, previous_b,
            stop_b, playpause_b, next_b, None,
            win.get_object('box1'), self.main_window
        ]
        self.wdg = [headerbar_wdg, win]
Esempio n. 32
0
 def apply_to_window(self, window: Gtk.Window) -> None:
     window.set_titlebar(self.header_bar)
Esempio n. 33
0
    def connect_window(self, win: Gtk.Window) -> None:
        """Connect widget to parent window."""
        self.win = win

        self.wm_maximise.connect("clicked", lambda x: self.maximise())
        self.wm_minimise.connect("clicked", lambda x: win.iconify())
Esempio n. 34
0
def get_window_name(window: Gtk.Window) -> str:
    return window.get_name() if window else 'EMPTY WINDOW'