Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add main application view #1

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ config.json
chromedriver.exe
version.txt
*.log
*.exe
build
dist
77 changes: 77 additions & 0 deletions application.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import sys
import gi

gi.require_version("Gtk", "3.0")
# gi.require_version('WebKit', '3.0')
from gi.repository import GLib, Gio, Gtk
from handlers.main_handler import MainHandler
from utils.constants import MAINVIEW_DIR, MENU_DIR

class Application(Gtk.Application):

def __init__(self, *args, **kwargs):
super().__init__(
*args,
application_id="org.example.myapp",
flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE,
**kwargs
)
self.window = None
self.add_main_option(
"test",
ord("t"),
GLib.OptionFlags.NONE,
GLib.OptionArg.NONE,
"Command line test",
None,
)

def do_startup(self):
Gtk.Application.do_startup(self)
menu_xml = ""
action = Gio.SimpleAction.new("about", None)
action.connect("activate", self.on_about)
self.add_action(action)
action = Gio.SimpleAction.new("quit", None)
action.connect("activate", self.on_quit)
self.add_action(action)
with open(MENU_DIR, "r") as fs:
menu_xml = fs.read()
fs.close()
builder = Gtk.Builder.new_from_string(menu_xml, -1)
self.set_app_menu(builder.get_object("app-menu"))

def do_activate(self):
# We only allow a single window and raise any existing ones
if not self.window:
# Windows are associated with the application
# when the last one is closed the application shuts down
self.builder = Gtk.Builder()
self.builder.add_from_file(MAINVIEW_DIR)
self.builder.connect_signals(MainHandler())
self.window = self.builder.get_object("main-window")
# self.webview = WebKit.WebView()
# scrolled_window = self.builder.get_object("web-view")
# scrolled_window.add(self.webview)
# self.webview.load_uri("http://localhost:5000")
# self.add(scrolled_window)
self.window.set_application(self)
self.window.present()

def do_command_line(self, command_line):
options = command_line.get_options_dict()
# convert GVariantDict -> GVariant -> dict
options = options.end().unpack()

if "test" in options:
# This is printed on the main instance
print("Test argument recieved: %s" % options["test"])
self.activate()
return 0

def on_about(self, *args):
about_dialog = Gtk.AboutDialog(modal=True)
about_dialog.present()

def on_quit(self, *args):
self.quit()
Empty file added handlers/__init__.py
Empty file.
38 changes: 38 additions & 0 deletions handlers/main_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import gi

gi.require_version("Gtk", "3.0")
from gi.repository import GLib, Gio, Gtk
from views.setting_view import SettingView
from views.url_view import UrlView
from views.proxy_view import ProxyView
from youtubeviewer.config import create_config
from utils.constants import BATCH_FILE_DIR
# from youtube_viewer import main

class MainHandler:

def __init__(self):
self.builder = Gtk.Builder()

def on_add_url_pressed(self, *args):
url_dialog = UrlView()
url_dialog.present()

def add_proxy_pressed(self, *args):
proxy_dialog = ProxyView()
proxy_dialog.present()

def on_settings_pressed(self, *args):
setting_dialog = SettingView()
response = setting_dialog.run()
if response == Gtk.ResponseType.OK:
print("OK button clicked")
print(setting_dialog.__dict__)
else:
print("Dialog closed")

setting_dialog.destroy()

def on_run_clicked(self, *args):
# main()
pass
16 changes: 16 additions & 0 deletions handlers/setting_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import gi

gi.require_version("Gtk", "3.0")
from gi.repository import GLib, Gio, Gtk


class SettingHandler:

def on_database_toggled(self, *args):
pass

def on_http_toggled(self, *args):
pass

def on_proxy_manual_toggled(self, *args):
pass
7 changes: 7 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import sys
from application import Application

if __name__ == '__main__':
app = Application()
exit_status = app.run(sys.argv)
sys.exit(exit_status)
48 changes: 48 additions & 0 deletions main.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# -*- mode: python ; coding: utf-8 -*-


block_cipher = None


a = Analysis(
['main.py'],
pathex=[],
binaries=[],
datas=[
('ui/MainView.glade','ui'),
('ui/SettingView.glade','ui'),
('ui/menu.xml','ui')
],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

exe = EXE(
pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='main',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)
100 changes: 100 additions & 0 deletions ui/MainView.glade
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.40.0 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkWindow" id="main-window">
<property name="can-focus">False</property>
<property name="default-width">900</property>
<property name="default-height">600</property>
<child>
<object class="GtkFixed" id="main-layout">
<property name="width-request">900</property>
<property name="height-request">600</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkButton" id="add_proxy">
<property name="label" translatable="yes">Add proxy</property>
<property name="width-request">40</property>
<property name="height-request">30</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="halign">center</property>
<property name="valign">center</property>
<signal name="pressed" handler="add_proxy_pressed" swapped="no"/>
</object>
<packing>
<property name="x">10</property>
<property name="y">20</property>
</packing>
</child>
<child>
<object class="GtkButton" id="add_url">
<property name="label" translatable="yes">Add URL</property>
<property name="width-request">40</property>
<property name="height-request">30</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="halign">center</property>
<property name="valign">center</property>
<signal name="pressed" handler="on_add_url_pressed" swapped="no"/>
</object>
<packing>
<property name="x">120</property>
<property name="y">20</property>
</packing>
</child>
<child>
<object class="GtkButton" id="settings">
<property name="label" translatable="yes">Settings</property>
<property name="width-request">40</property>
<property name="height-request">30</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="halign">center</property>
<property name="valign">center</property>
<signal name="pressed" handler="on_settings_pressed" swapped="no"/>
</object>
<packing>
<property name="x">340</property>
<property name="y">20</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">run</property>
<property name="width-request">40</property>
<property name="height-request">30</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="clicked" handler="on_run_clicked" swapped="no"/>
</object>
<packing>
<property name="x">600</property>
<property name="y">100</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="web-view">
<property name="width-request">300</property>
<property name="height-request">300</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="shadow-type">in</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="x">230</property>
<property name="y">230</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
Loading