Added some code for starting
This commit is contained in:
5
src/widgetUtils/__init__.py
Normal file
5
src/widgetUtils/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
import platform
|
||||
if platform.system() == "Windows":
|
||||
from wxUtils import *
|
||||
#elif platform.system() == "Linux":
|
||||
# from gtkUtils import *
|
143
src/widgetUtils/gtkUtils.py
Normal file
143
src/widgetUtils/gtkUtils.py
Normal file
@@ -0,0 +1,143 @@
|
||||
from gi.repository import Gtk, Gdk
|
||||
from gi.repository import GObject
|
||||
|
||||
toolkit = "gtk"
|
||||
# Code responses for GTK +3 dialogs.
|
||||
# this is when an user presses OK on a dialogue.
|
||||
OK = Gtk.ResponseType.OK
|
||||
# This is when an user presses cancel on a dialogue.
|
||||
CANCEL = Gtk.ResponseType.CANCEL
|
||||
# This is when an user closes the dialogue or an id to create the close button.
|
||||
CLOSE = Gtk.ResponseType.CLOSE
|
||||
# The response for a "yes" Button pressed on a dialogue.
|
||||
YES = Gtk.ResponseType.YES
|
||||
# This is when the user presses No on a default dialogue.
|
||||
NO = Gtk.ResponseType.NO
|
||||
|
||||
#events
|
||||
# This is raised when the application must be closed.
|
||||
CLOSE_EVENT = "delete-event"
|
||||
# This is activated when a button is pressed.
|
||||
BUTTON_PRESSED = "clicked"
|
||||
# This is activated when an user enter text on an edit box.
|
||||
ENTERED_TEXT = "changed"
|
||||
MENU = "activate"
|
||||
|
||||
#KEYPRESS = wx.EVT_CHAR_HOOK
|
||||
#NOTEBOOK_PAGE_CHANGED = wx.EVT_NOTEBOOK_PAGE_CHANGED
|
||||
CHECKBOX = "toggled"
|
||||
|
||||
def exit_application():
|
||||
""" Closes the current window cleanly. """
|
||||
Gtk.main_quit()
|
||||
|
||||
def connect_event(parent, event, func, menuitem=None, *args, **kwargs):
|
||||
""" Connects an event to a function.
|
||||
parent Gtk.widget: The widget that will listen for the event.
|
||||
event widgetUtils.event: The event that will be listened for the parent. The event should be one of the widgetUtils events.
|
||||
function func: The function that will be connected to the event."""
|
||||
if menuitem == None:
|
||||
return getattr(parent, "connect")(event, func, *args, **kwargs)
|
||||
else:
|
||||
return getattr(menuitem, "connect")(event, func, *args, **kwargs)
|
||||
|
||||
class list(object):
|
||||
def __init__(self, *columns, **listArguments):
|
||||
self.columns = columns
|
||||
self.list_arguments = listArguments
|
||||
self.create_list()
|
||||
|
||||
def create_list(self):
|
||||
columns = []
|
||||
[columns.append(str) for i in self.columns]
|
||||
self.store = Gtk.ListStore(*columns)
|
||||
self.list = Gtk.TreeView(model=self.store)
|
||||
renderer = Gtk.CellRendererText()
|
||||
for i in range(0, len(self.columns)):
|
||||
column = Gtk.TreeViewColumn(self.columns[i], renderer, text=i)
|
||||
# column.set_sort_column_id(i)
|
||||
self.list.append_column(column)
|
||||
|
||||
def insert_item(self, reversed=False, *item):
|
||||
if reversed == False:
|
||||
self.store.append(row=item)
|
||||
else:
|
||||
self.store.insert(position=0, row=item)
|
||||
|
||||
def get_selected(self):
|
||||
tree_selection = self.list.get_selection()
|
||||
(model, pathlist) = tree_selection.get_selected_rows()
|
||||
return int(pathlist[0].to_string() )
|
||||
|
||||
def select_item(self, item):
|
||||
tree_selection = self.list.get_selection()
|
||||
tree_selection.select_path(item)
|
||||
|
||||
def remove_item(self, item):
|
||||
self.store.remove(self.store.get_iter(item))
|
||||
|
||||
def get_count(self):
|
||||
return len(self.store)
|
||||
|
||||
class baseDialog(Gtk.Dialog):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(baseDialog, self).__init__(*args, **kwargs)
|
||||
self.box = self.get_content_area()
|
||||
|
||||
def get_response(self):
|
||||
answer = self.run()
|
||||
return answer
|
||||
|
||||
class buffer(GObject.GObject):
|
||||
name = GObject.property(type=str)
|
||||
|
||||
def __init__(self, obj):
|
||||
super(buffer, self).__init__()
|
||||
self.buffer = obj
|
||||
|
||||
class notebook(object):
|
||||
|
||||
def __init__(self):
|
||||
self.store = Gtk.TreeStore(buffer.__gtype__)
|
||||
self.view = Gtk.TreeView()
|
||||
self.view.set_model(self.store)
|
||||
|
||||
column = Gtk.TreeViewColumn("Buffer")
|
||||
cell = Gtk.CellRendererText()
|
||||
column.pack_start(cell, True)
|
||||
column.set_cell_data_func(cell, self.get_buffer)
|
||||
self.view.append_column(column)
|
||||
|
||||
def get_current_page(self):
|
||||
tree_selection = self.view.get_selection()
|
||||
(model, pathlist) = tree_selection.get_selected_rows()
|
||||
iter = pathlist[0]
|
||||
return self.store[iter][0].buffer
|
||||
|
||||
def get_buffer(self, column, cell, model, iter, data):
|
||||
cell.set_property('text', self.store.get_value(iter, 0).name)
|
||||
|
||||
def match_func(self, row, name_, account):
|
||||
name = name_
|
||||
account = account
|
||||
iter = self.store.get_iter(row.path)
|
||||
if self.store[iter][0].buffer.name == name and self.store[iter][0].buffer.account == account:
|
||||
return (row.path, iter)
|
||||
else:
|
||||
return (None, None)
|
||||
|
||||
def search(self, rows, name_, account):
|
||||
if not rows: return None
|
||||
for row in rows:
|
||||
(path, iter) = self.match_func(row, name_, account)
|
||||
if iter != None:
|
||||
return (path, iter)
|
||||
(result_path, result_iter) = self.search(row.iterchildren(), name_, account)
|
||||
if result_path: return (result_path, result_iter)
|
||||
return (None, None)
|
||||
|
||||
class mainLoopObject(object):
|
||||
|
||||
def run(self):
|
||||
GObject.type_register(buffer)
|
||||
Gtk.main()
|
171
src/widgetUtils/wxUtils.py
Normal file
171
src/widgetUtils/wxUtils.py
Normal file
@@ -0,0 +1,171 @@
|
||||
import wx
|
||||
import paths
|
||||
import languageHandler
|
||||
import sys
|
||||
|
||||
toolkit = "wx"
|
||||
|
||||
### Code responses for WX dialogs.
|
||||
|
||||
# this is when an user presses OK on a dialogue.
|
||||
OK = wx.ID_OK
|
||||
|
||||
# This is when an user presses cancel on a dialogue.
|
||||
CANCEL = wx.ID_CANCEL
|
||||
|
||||
# This is when an user closes the dialogue or an id to create the close button.
|
||||
CLOSE = wx.ID_CLOSE
|
||||
|
||||
# The response for a "yes" Button pressed on a dialogue.
|
||||
YES = wx.ID_YES
|
||||
|
||||
# This is when the user presses No on a default dialogue.
|
||||
NO = wx.ID_NO
|
||||
|
||||
###events
|
||||
|
||||
# This is raised when the application must be closed.
|
||||
CLOSE_EVENT = wx.EVT_CLOSE
|
||||
|
||||
# This is activated when a button is pressed.
|
||||
BUTTON_PRESSED = wx.EVT_BUTTON
|
||||
|
||||
# This is raised when a checkbox changes its status.
|
||||
CHECKBOX = wx.EVT_CHECKBOX
|
||||
|
||||
# This is activated when an user enter text on an edit box.
|
||||
ENTERED_TEXT = wx.EVT_TEXT
|
||||
|
||||
# This is raised when a user activates a menu.
|
||||
MENU = wx.EVT_MENU
|
||||
|
||||
# This is raised when a user presses any key in the control.
|
||||
KEYPRESS = wx.EVT_CHAR_HOOK
|
||||
|
||||
# This is raised when a user releases a key in the control.
|
||||
KEYUP = wx.EVT_KEY_UP
|
||||
|
||||
# This happens when a notebook tab is changed, It is used in Treebooks too.
|
||||
NOTEBOOK_PAGE_CHANGED = wx.EVT_TREEBOOK_PAGE_CHANGED
|
||||
|
||||
# This happens when a radiobutton group changes its status.
|
||||
RADIOBUTTON = wx.EVT_RADIOBUTTON
|
||||
|
||||
# Taskbar mouse clicks.
|
||||
TASKBAR_RIGHT_CLICK = wx.EVT_TASKBAR_RIGHT_DOWN
|
||||
TASKBAR_LEFT_CLICK = wx.EVT_TASKBAR_LEFT_DOWN
|
||||
|
||||
def exit_application():
|
||||
""" Closes the current window cleanly. """
|
||||
wx.GetApp().ExitMainLoop()
|
||||
|
||||
def connect_event(parent, event, func, menuitem=None, *args, **kwargs):
|
||||
""" Connects an event to a function.
|
||||
parent wx.window: The widget that will listen for the event.
|
||||
event widgetUtils.event: The event that will be listened for the parent. The event should be one of the widgetUtils events.
|
||||
function func: The function that will be connected to the event."""
|
||||
if menuitem == None:
|
||||
return getattr(parent, "Bind")(event, func, *args, **kwargs)
|
||||
else:
|
||||
return getattr(parent, "Bind")(event, func, menuitem, *args, **kwargs)
|
||||
|
||||
def connectExitFunction(exitFunction):
|
||||
""" This connect the events in WX when an user is turning off the machine."""
|
||||
wx.GetApp().Bind(wx.EVT_QUERY_END_SESSION, exitFunction)
|
||||
wx.GetApp().Bind(wx.EVT_END_SESSION, exitFunction)
|
||||
|
||||
class BaseDialog(wx.Dialog):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(BaseDialog, self).__init__(*args, **kwargs)
|
||||
|
||||
def get_response(self):
|
||||
return self.ShowModal()
|
||||
|
||||
def get(self, control):
|
||||
if hasattr(self, control):
|
||||
control = getattr(self, control)
|
||||
if hasattr(control, "GetValue"): return getattr(control, "GetValue")()
|
||||
elif hasattr(control, "GetLabel"): return getattr(control, "GetLabel")()
|
||||
else: return -1
|
||||
else: return 0
|
||||
|
||||
def set(self, control, text):
|
||||
if hasattr(self, control):
|
||||
control = getattr(self, control)
|
||||
if hasattr(control, "SetValue"): return getattr(control, "SetValue")(text)
|
||||
elif hasattr(control, "SetLabel"): return getattr(control, "SetLabel")(text)
|
||||
elif hasattr(control, "ChangeValue"): return getattr(control, "ChangeValue")(text)
|
||||
else: return -1
|
||||
else: return 0
|
||||
|
||||
def destroy(self):
|
||||
self.Destroy()
|
||||
|
||||
def set_title(self, title):
|
||||
self.SetTitle(title)
|
||||
|
||||
def get_title(self):
|
||||
return self.GetTitle()
|
||||
|
||||
class mainLoopObject(wx.App):
|
||||
|
||||
def __init__(self):
|
||||
self.app = wx.App()
|
||||
self.lc = wx.Locale()
|
||||
lang=languageHandler.getLanguage()
|
||||
wxLang=self.lc.FindLanguageInfo(lang)
|
||||
if not wxLang and '_' in lang:
|
||||
wxLang=self.lc.FindLanguageInfo(lang.split('_')[0])
|
||||
if hasattr(sys,'frozen'):
|
||||
self.lc.AddCatalogLookupPathPrefix(paths.app_path("locales"))
|
||||
if wxLang:
|
||||
self.lc.Init(wxLang.Language)
|
||||
|
||||
def run(self):
|
||||
self.app.MainLoop()
|
||||
|
||||
class list(object):
|
||||
def __init__(self, parent, *columns, **listArguments):
|
||||
self.columns = columns
|
||||
self.listArguments = listArguments
|
||||
self.create_list(parent)
|
||||
|
||||
def set_windows_size(self, column, characters_max):
|
||||
self.list.SetColumnWidth(column, characters_max*2)
|
||||
|
||||
def set_size(self):
|
||||
self.list.SetSize((self.list.GetBestSize()[0], 728))
|
||||
|
||||
def create_list(self, parent):
|
||||
self.list = wx.ListCtrl(parent, -1, **self.listArguments)
|
||||
for i in xrange(0, len(self.columns)):
|
||||
self.list.InsertColumn(i, u"%s" % (self.columns[i]))
|
||||
|
||||
def insert_item(self, reversed, *item):
|
||||
""" Inserts an item on the list."""
|
||||
if reversed == False: items = self.list.GetItemCount()
|
||||
else: items = 0
|
||||
self.list.InsertStringItem(items, item[0])
|
||||
for i in xrange(1, len(self.columns)):
|
||||
self.list.SetStringItem(items, i, item[i])
|
||||
|
||||
def remove_item(self, pos):
|
||||
""" Deletes an item from the list."""
|
||||
if pos > 0: self.list.Focus(pos-1)
|
||||
self.list.DeleteItem(pos)
|
||||
|
||||
def clear(self):
|
||||
self.list.DeleteAllItems()
|
||||
|
||||
def get_selected(self):
|
||||
return self.list.GetFocusedItem()
|
||||
|
||||
def select_item(self, pos):
|
||||
self.list.Focus(pos)
|
||||
|
||||
def get_count(self):
|
||||
selected = self.list.GetItemCount()
|
||||
if selected == -1:
|
||||
return 0
|
||||
else:
|
||||
return selected
|
Reference in New Issue
Block a user