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 font option & implement toggle side panel #4

Open
wants to merge 1 commit 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
13 changes: 11 additions & 2 deletions thawab-lite.glade
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,20 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkMenuItem">
<object class="GtkMenuItem" id="toggle_side_panel_mnu">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Toggle Side Panel</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_toggle_side_panel_mnu_activate" swapped="no"/>
</object>
</child>
<child>
<object class="GtkMenuItem" id="font_mnu">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Font style</property>
<signal name="activate" handler="on_font_mnu_activate" swapped="no"/>
</object>
</child>
<child>
Expand Down Expand Up @@ -185,7 +194,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkScrolledWindow">
<object class="GtkScrolledWindow" id="side_panel">
<property name="width_request">200</property>
<property name="height_request">200</property>
<property name="visible">True</property>
Expand Down
35 changes: 33 additions & 2 deletions thawab-lite.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from threading import Thread

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

import pypyodbc as pyodbc
#try: import pypyodbc as pyodbc
Expand Down Expand Up @@ -120,6 +120,21 @@ def get_filename(parent=None):

sura_aya_re = re.compile(ur'(\d+):(\d+)')

font_dlg = None
def get_font_name(parent=None):
global font_dlg
if font_dlg:
font_dlg.set_transient_for(parent)
if font_dlg.run()!=Gtk.ResponseType.OK: return None
return font_dlg.get_font_name()
font_dlg = Gtk.FontSelectionDialog(
"Select font style",
parent= parent)
font_dlg.connect('delete-event', lambda w,*a: w.hide() or True)
font_dlg.connect('response', lambda w,*a: w.hide() or True)
if font_dlg.run()!=Gtk.ResponseType.OK: return None
return font_dlg.get_font_name()

class MyApp(object):
instances = 0
def __init__(self, filename=None):
Expand All @@ -141,6 +156,7 @@ def __init__(self, filename=None):
self.window = builder.get_object("main_win")
self.header = builder.get_object("header")
self.body = builder.get_object("body")
self.side_panel = builder.get_object("side_panel")
self.toc_store = builder.get_object("toc_store")
self.toc_tree = builder.get_object("toc_tree")
self.search_entry = builder.get_object("search_entry")
Expand Down Expand Up @@ -239,7 +255,7 @@ def open(self, filename):
self.filename = filename
cols = get_table_col(filename, 'Main')
self.db = db = pyodbc.connect(
tob('DRIVER=libmdbodbc.so;DBQ={}'.format(filename)),
tob('DRIVER=libmdbodbc.so;DBQ={}'.format(filename).decode("utf-8")),
readonly=True, ansi=True, unicode_results=False,
)
cursor = db.cursor()
Expand Down Expand Up @@ -334,6 +350,21 @@ def on_open_btn_clicked(self, w):
else:
spawn_clone(filename)

def on_toggle_side_panel_mnu_activate(self, w):
if self.side_panel.get_visible(): self.side_panel.hide()
else: self.side_panel.show()


def on_font_mnu_activate(self, w):
font_name = get_font_name(self.window)
if font_name:
#TODO: add it to queue if necessary
#TODO: Make an option for changing only the body box font or both body box and side panel
font_desc = Pango.FontDescription(font_name)
if font_desc:
self.body.modify_font(font_desc)
self.toc_tree.modify_font(font_desc)

files = sys.argv[1:]
if not files:
MyApp()
Expand Down