Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from wike.prefs import PrefsDialog
from wike.window import Window
from wike.view import network_session
from wike import wikipedia


# Main application class for Wike
Expand All @@ -30,8 +31,10 @@ def __init__(self):

self._window = None
self._launch_uri = ''
self._search_query = ''

self.add_main_option('url', b'u', GLib.OptionFlags.NONE, GLib.OptionArg.STRING, 'Open Wikipedia URL', None)
self.add_main_option('search', b's', GLib.OptionFlags.NONE, GLib.OptionArg.STRING, 'Search Wikipedia', None)

# Load custom css and set actions

Expand Down Expand Up @@ -95,14 +98,24 @@ def do_command_line(self, command_line):
if self._window:
self._window.new_page(self._launch_uri, None, True)


if 'search' in options:
self._search_query = options['search']

if self._window:
launch_uri = wikipedia.search(self._search_query.lower(), 'en', 1, False)[1][0]
self._window.new_page(launch_uri, None, True)
self._window.search_panel.search_entry.set_text(self._search_query)


self.activate()
return 0

# Create main window and connect close event

def do_activate(self):
if not self._window:
self._window = Window(self, self._launch_uri)
self._window = Window(self, self._launch_uri, self._search_query)
self._window.connect('close-request',self._window_close_cb)

self._window.present()
Expand Down
8 changes: 7 additions & 1 deletion src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from wike.page import PageBox
from wike.search import SearchPanel
from wike.toc import TocPanel
from wike import wikipedia


# Main window
Expand Down Expand Up @@ -53,7 +54,7 @@ class Window(Adw.ApplicationWindow):

# Initialize window, set actions and connect signals

def __init__(self, app, launch_uri):
def __init__(self, app, launch_uri, search_query):
super().__init__(application=app)

width = settings.get_int('window-width')
Expand Down Expand Up @@ -90,6 +91,8 @@ def __init__(self, app, launch_uri):
history_stack_page = self.panel_stack.add_named(self.history_panel, 'history')

self.page = PageBox(self, None)
if search_query != '':
launch_uri = wikipedia.search(search_query.lower(), 'en', 1, False)[1][0]

if launch_uri != '':
tabpage = self.tabview.append(self.page)
Expand Down Expand Up @@ -164,6 +167,9 @@ def __init__(self, app, launch_uri):
if settings.get_boolean('hide-tabs'):
self._hide_tabs(True)

if search_query != '':
self.search_panel.search_entry.set_text(search_query)

# Set actions for window

def _set_actions(self, app):
Expand Down