[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Pyatcron-devel-list] Complete rewrite of the mainwin module
From: |
Xavier Nicolovici |
Subject: |
Re: [Pyatcron-devel-list] Complete rewrite of the mainwin module |
Date: |
Thu, 29 Apr 2004 08:49:07 +0200 |
User-agent: |
Mozilla Thunderbird 0.5 (Windows/20040207) |
Hmmm, seems that Outlook Web Acces is really wrong at sending
attachements. Sorry for this "winmail.dat" attachement.
Here is attached the patch, in a right format.
Bye,
Xavier
NICOLOVICI Xavier wrote:
Hi everyone,
I've mostly completly rewritten the mainwin.py module to use our new ScheduleListStore object.
Quickly, major changes are:
- ScheduleList class and lib.schedulelist module not needed anymore, should be removed from CVS
- lib.mainwin module code is now lighter, no more sync stuff between ScehduleList and TreeView
What's next on GUI:
- Adapt create task and edit task properties code
- Limit the create task action to creating command line Task
What's next on core system:
- Code the saving method of the ScheduleListStore and link it to the mainmenu_save event
When this will be done, I think that we might be ready to release a 0.1 release. What do u think guys?
Please let me know on what you would like to work before I start doing something.
You'll find attached a patch for those changes, build against the latest CVS tree.
Bye,
Xavier
This e-mail contains proprietary information some or all of which may be legally privileged. It is intended for the recipient only. If an addressing or a transmission error has misdirected this e-mail, please notify the author by replying to the e-mail. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this e-mail.
We take reasonable precautions to ensure our e-mails are virus free. However, we cannot accept responsibility for any virus transmitted by us and recommend that you subject any incoming e-mail to your own virus checking procedures.
_______________________________________________
Pyatcron-devel-list mailing list
address@hidden
http://mail.nongnu.org/mailman/listinfo/pyatcron-devel-list
Index: src/lib/gui.py
===================================================================
RCS file: /cvsroot/pyatcron/pyatcron/src/lib/gui.py,v
retrieving revision 1.4
diff -u -r1.4 gui.py
--- src/lib/gui.py 27 Apr 2004 14:56:25 -0000 1.4
+++ src/lib/gui.py 28 Apr 2004 16:19:33 -0000
@@ -1,7 +1,55 @@
from gtk import *
import gtk.glade
+import gobject
+
+from parser import *
+from syntacticengine import *
from config import GLADE_FILE_PATH
+
+class ScheduleListStore(gtk.ListStore):
+ def __init__(self,activeColor,inactiveColor):
+ # Call parent constructor with column defintions
+ gtk.ListStore.__init__(self,
+ gobject.TYPE_PYOBJECT,
+ gobject.TYPE_STRING,
+ gobject.TYPE_STRING,
+ gobject.TYPE_STRING)
+
+ # store active and inactive colors as internal fields
+ self.activeColor = activeColor
+ self.inactiveColor = inactiveColor
+
+ # Foreach system scheduled job, add them to ourself (ListStore)
+ for entry in CronEntryParser().getEntryList():
+ self.addScheduler(entry)
+ for entry in AtEntryParser().getEntryList():
+ self.addScheduler(entry)
+ for entry in PyAtCronEntryParser().getEntryList():
+ self.addScheduler(entry)
+
+ return
+
+ def addScheduler(self,scheduler):
+ # Start a syntactic engine
+ syntactic = SyntacticEngine(scheduler)
+ # get an GtkIter object on a new row at top of list
+ iter = self.prepend(None)
+ # set values to this new row
+ if(scheduler.isActive()):
+ color = self.activeColor
+ else:
+ color = self.inactiveColor
+ self.set(iter,0,scheduler,
+ 1,syntactic.getSchedulerName(),
+ 2,syntactic.getNextRunString(),
+ 3,color)
+
+ def saveSchedulers(self):
+ print "ScheduleListStore::saveSchedulers: NOT IMPLEMENTED"
+ return
+
+
class SchedulerEditor:
Index: src/lib/mainwin.py
===================================================================
RCS file: /cvsroot/pyatcron/pyatcron/src/lib/mainwin.py,v
retrieving revision 1.8
diff -u -r1.8 mainwin.py
--- src/lib/mainwin.py 28 Apr 2004 08:09:02 -0000 1.8
+++ src/lib/mainwin.py 28 Apr 2004 16:19:33 -0000
@@ -4,26 +4,20 @@
import datetime
import time
-from lib.schedulelist import ScheduleList
-from syntacticengine import SyntacticEngine
-from lib.gui import SchedulerEditor
+from gui import *
+from newtask import NewTask
+from about import About
# import glade path from config module
from config import GLADE_FILE_PATH
-from newtask import NewTask
-from about import About
-
-
# The main window's class.
class MainWin:
def __init__ (self):
# The index of the task currently highlighted (if any).
self.taskIndex = None
- # Get the list of schedulers
- self.scheduleList = ScheduleList ()
# The GtkTreePath of the last highlighted inactive task.
# It's used to switch between the inactive/highlighted colors
@@ -31,67 +25,53 @@
self.lastPath = None
# We load the widgets and the callbacks from the glade file.
- self.widgetTree = gtk.glade.XML (GLADE_FILE_PATH +
- "/mainwin.glade")
+ self.widgetTree = gtk.glade.XML (GLADE_FILE_PATH + "/mainwin.glade")
- dict = {}
- for key in dir(self.__class__):
- dict[key] = getattr(self, key)
- self.widgetTree.signal_autoconnect (dict)
-
- # When the selection changes, we call self.on_selection_changed().
- # This can't be handled directly by glade if not by using
- # the on_cursor_changed callback, which doesn't work well.
- self.widgetTree.get_widget
("tasklist").get_selection().connect("changed", self.on_selection_changed)
-
# It's the base widget.
self.win = self.widgetTree.get_widget ("mainwin")
-
- # This is used to get the "highlighted" color from the GTK
- # theme.
- self.highlightedColor = self.getThemeColor (3)
-
- # This is used to get the "insensitive" color from the GTK
- # theme.
- self.insensitiveColor = self.getThemeColor (4)
-
- # This is used to get the main background color from the GTK
- #theme.
- self.backgroundColor = self.getThemeColor (8)
-
- # We build the task list.
- self.updateTaskList ()
- # We get the current highlighted task's index.
- self.updateCurrentTask ()
-
- # Gets the colors from the GTK theme
- def getThemeColor (self, num):
- if (num < 5):
- redhex = hex (self.win.rc_get_style ().fg [num].red)
- else:
- redhex = hex (self.win.rc_get_style ().bg [num - 5].red)
- redsplit = redhex.split ('0x')
- redstr = redsplit [1]
+ # Get normal and insensitive state color from Gtk theme
+ self.normalColor = self.getThemeColor(gtk.STATE_NORMAL)
+ self.insensitiveColor = self.getThemeColor(gtk.STATE_INSENSITIVE)
+
+ # Initialize a ScheduleListStore object
+ self.listStore=ScheduleListStore(self.normalColor,
+ self.insensitiveColor)
- if (num < 5):
- greenhex = hex (self.win.rc_get_style ().fg [num].green)
- else:
- greenhex = hex (self.win.rc_get_style ().bg [num - 5].green)
- greensplit = greenhex.split ('0x')
- greenstr = greensplit [1]
+ # and set it as model of our main Gtk::TreeView
+ self.taskList = self.widgetTree.get_widget("tasklist")
+ self.taskList.set_model(self.listStore)
- if (num < 5):
- bluehex = hex (self.win.rc_get_style ().fg [num].blue)
- else:
- bluehex = hex (self.win.rc_get_style ().bg [num - 5].blue)
- bluesplit = bluehex.split ('0x')
- bluestr = bluesplit [1]
+ # Disable multiselect on TreeView
+ self.taskList.get_selection().set_mode(gtk.SELECTION_SINGLE)
- color = "#" + redstr + greenstr + bluestr
-
- return color
+ # initialize a cell renderer
+ renderer = CellRendererText()
+
+ # and finally set the visible column
+ column = gtk.TreeViewColumn("Task", renderer, text=1, foreground=3)
+ self.taskList.append_column(column)
+ column = gtk.TreeViewColumn("Next run", renderer, text=2, foreground=3)
+ self.taskList.append_column(column)
+
+ # autoconnect signals to callbacks
+ dict = {}
+ for key in dir(self.__class__):
+ dict[key] = getattr(self, key)
+ self.widgetTree.signal_autoconnect (dict)
+
+ # connect some specific signals
+ selection = self.taskList.get_selection()
+ selection.connect("changed",self.on_tasklist_selection_changed)
+
+ # update the GUI items
+ self.updateItemsSensitivity()
+ ###############################################
+ # #
+ # SIGNALS CALLBACKS #
+ # #
+ ###############################################
def on_mainwin_delete_event (self, obj, event):
self.quit ()
@@ -99,28 +79,12 @@
self.quit ()
def on_tasklist_button_press_event (self, obj, event):
- # If the right-mouse button is pressed, get the current selection.
+ # If the right-mouse button is pressed, show popup menu
if (event.button == 3):
- taskList = self.widgetTree.get_widget ("tasklist")
- iter = taskList.get_selection ().get_selected () [1]
-
- # If there is a selection, check that the click occured inside the
selected row.
- if (iter != None ):
- model = taskList.get_model ()
- path = model.get_path (iter)
- column = taskList.get_column (0)
- cell_area = taskList.get_cell_area (path, column)
- # If it's the case, setup and display the popup menu
- if (event.y >= cell_area.y and event.y <= cell_area.y +
cell_area.height):
- activable = model.get_value (iter, 1)
-
- self.widgetTree.get_widget
("popup_properties").set_sensitive (1)
- self.widgetTree.get_widget
("popup_activate").set_sensitive (activable)
- self.widgetTree.get_widget
("popup_deactivate").set_sensitive (1 - activable)
- self.widgetTree.get_widget ("popup_delete").set_sensitive
(1)
-
-
- self.widgetTree.get_widget ("popup").popup (None, None,
None, event.button, event.time)
+ self.showPopupMenu(event)
+
+ def on_tasklist_selection_changed(self,obj):
+ self.updateItemsSensitivity()
def on_mainmenu_save_activate (self, obj):
self.save ()
@@ -135,13 +99,13 @@
self.editTask ()
def on_mainmenu_activate_activate (self, obj):
- self.activateTask ()
+ self.setSchedulerActiveStatus(True)
def on_mainmenu_deactivate_activate (self, obj):
- self.deactivateTask ()
+ self.setSchedulerActiveStatus(False)
def on_mainmenu_delete_activate (self, obj):
- self.confirmDeleteTask ()
+ self.deleteScheduler ()
def on_mainmenu_about_activate (self, obj):
self.about ()
@@ -150,13 +114,13 @@
self.editTask ()
def on_popup_activate_activate (self, obj):
- self.activateTask ()
+ self.setSchedulerActiveStatus(True)
def on_popup_deactivate_activate (self, obj):
- self.deactivateTask ()
+ self.setSchedulerActiveStatus(False)
def on_popup_delete_activate (self, obj):
- self.confirmDeleteTask ()
+ self.deleteScheduler ()
def on_toolbar_new_clicked (self, obj):
self.createTask ()
@@ -165,37 +129,152 @@
self.editTask ()
def on_toolbar_activate_clicked (self, obj):
- self.activateTask ()
+ self.setSchedulerActiveStatus(True)
def on_toolbar_deactivate_clicked (self, obj):
- self.deactivateTask ()
+ self.setSchedulerActiveStatus(False)
def on_toolbar_delete_clicked (self, obj):
- self.confirmDeleteTask ()
-
- def on_tasklist_row_activated (self, obj, path, column):
- self.editTask ()
-
- def on_selection_changed (self, obj):
- self.updateCurrentTask ()
+ self.deleteScheduler()
def on_confirm_delete_response (self, obj, response):
# If deletion is confirmed, delete the task.
if (response == -8):
- self.deleteTask ()
-
+ self.deleteScheduler(True)
# Free the dialog.
obj.destroy ()
-
+
+ ###############################################
+ # #
+ # CLASS METHODS #
+ # #
+ ###############################################
+
+ # Gets the colors from the GTK theme
+ def getThemeColor (self, num):
+ if (num < 5):
+ redhex = hex (self.win.rc_get_style ().fg [num].red)
+ greenhex = hex (self.win.rc_get_style ().fg [num].green)
+ bluehex = hex (self.win.rc_get_style ().fg [num].blue)
+ else:
+ redhex = hex (self.win.rc_get_style ().bg [num - 5].red)
+ greenhex = hex (self.win.rc_get_style ().bg [num - 5].green)
+ bluehex = hex (self.win.rc_get_style ().bg [num - 5].blue)
+ redstr = redhex.split ('0x')[1]
+ greenstr = greenhex.split ('0x')[1]
+ bluestr = bluehex.split ('0x') [1]
+
+ return "#" + redstr + greenstr + bluestr
+
+ # Show a confirmation dialog before deleting the task.
+ def deleteScheduler (self,confirm = False):
+ if (confirm):
+ # deletion is confirmed, delete Scheduler
+ print "MainWin::deleteScheduler: NOT IMPLEMENTED"
+ else:
+ # Load a delete confirmation dialog window
+ xml = gtk.glade.XML (GLADE_FILE_PATH + "/confirm_delete.glade")
+ # autoconnect signals
+ dict = {}
+ for key in dir(self.__class__):
+ dict[key] = getattr(self, key)
+ xml.signal_autoconnect (dict)
+
+ # get the dialog window widget
+ confirm = xml.get_widget ("confirm_delete")
+
+ # Center the dialog on the main window.
+ confirm.set_transient_for (self.win)
+ confirm.set_position (gtk.WIN_POS_CENTER_ON_PARENT)
+
+ # Display the dialog.
+ confirm.show ()
+ return
+
+ def showPopupMenu(self,event):
+ self.widgetTree.get_widget ("popup").popup (None, None, None,
+ event.button, event.time)
+
+ def updateItemsSensitivity(self):
+ itemDict = {
+ "mainmenu_properties": 1,
+ "mainmenu_activate" : 1,
+ "mainmenu_deactivate": 1,
+ "mainmenu_delete" : 1,
+ "toolbar_new" : 1,
+ "toolbar_properties" : 1,
+ "toolbar_activate" : 1,
+ "toolbar_deactivate" : 1,
+ "toolbar_delete" : 1,
+ "popup_properties" : 1,
+ "popup_activate" : 1,
+ "popup_deactivate" : 1,
+ "popup_delete" : 1
+ }
+ # get iter of selected row
+ model,iter = self.taskList.get_selection().get_selected()
+ # check if there is a selected row
+ if(not iter):
+ itemDict["mainmenu_properties"] = 0
+ itemDict["mainmenu_activate"] = 0
+ itemDict["mainmenu_deactivate"] = 0
+ itemDict["mainmenu_delete"] = 0
+ itemDict["toolbar_properties"] = 0
+ itemDict["toolbar_activate"] = 0
+ itemDict["toolbar_deactivate"] = 0
+ itemDict["toolbar_delete"] = 0
+
+ else:
+ # check if the selected Scheduler is active
+ # NOTE: Not implemented at the moment, active is alwas True
+ active = model.get_value(iter,0).isActive()
+ itemDict["mainmenu_activate"] = not active
+ itemDict["mainmenu_deactivate"] = active
+ itemDict["toolbar_activate"] = not active
+ itemDict["toolbar_deactivate"] = active
+ itemDict["popup_activate"] = not active
+ itemDict["popup_deactivate"] = active
+
+ # set sensitivity on items
+ for key in itemDict:
+ self.widgetTree.get_widget(key).set_sensitive(itemDict[key])
+
+
+ # Set the active status of the selected Scheduler
+ def setSchedulerActiveStatus(self,status):
+ # get selected row
+ model,iter = self.taskList.get_selection().get_selected()
+ # do something only if there is a selected row
+ if(iter):
+ # set status to scheduler
+ model.get_value(iter,0).setActive(status)
+ # change color of text
+ if(status):
+ model.set_value(iter,3,self.normalColor)
+ else:
+ model.set_value(iter,3,self.insensitiveColor)
+ # update sensitivity of menu items
+ self.updateItemsSensitivity()
+
# Writes the current configuration.
def save (self):
- print "TODO: save"
+ self.listStore.saveSchedulers()
# Unreferences the main window's widgets, and exits.
def quit (self):
self.save ()
gtk.main_quit ()
+ # Launches the "about" dialog.
+ def about (self):
+ aboutObject = About (self.win)
+
+
+
+#######################################
+# TO BE REWRITTEN OR DELETED #
+#######################################
+
# Gets the current highlighted task's index.
def updateCurrentTask (self):
taskList = self.widgetTree.get_widget ("tasklist")
@@ -220,7 +299,7 @@
else:
# If the task is inactive, the "deactivate" icon toolbar is
insensitive, the "activate" icon is sensitive and vice-versa.
activable = model.get_value (iter, 1)
-
+
self.widgetTree.get_widget ("toolbar_properties").set_sensitive (1)
self.widgetTree.get_widget ("toolbar_activate").set_sensitive
(activable)
self.widgetTree.get_widget ("toolbar_deactivate").set_sensitive (1
- activable)
@@ -240,14 +319,16 @@
# We set the inactive task's color to "highlighted".
model.set_value (model.get_iter (path), 4,
self.highlightedColor)
- # Launches the new task assistant and refreshes the task list if a new
task was created.
+ # Launches the new task assistant and refreshes the task list
+ # if a new task was created.
def createTask (self):
assistantObject = NewTask (self)
def on_editor_changed(self, *args):
print "Updating list (only the task, not the scheduler)"
self.updateTaskList (True, True, False)
- # Launches the properties dialog and refreshes the task list if changes
were made.
+ # Launches the properties dialog and refreshes the task list if
+ # changes were made.
def editTask (self):
print "edit task #" + str (self.taskIndex)
self.editor = SchedulerEditor(self.scheduleList[self.taskIndex])
@@ -255,45 +336,7 @@
self.scheduleList[self.taskIndex].task.connect('changed',
self.on_editor_changed)
#self.updateTaskList ()
- # Makes the current task active and refreshes the task list.
- def activateTask (self):
- self.scheduleList [self.taskIndex].setActive (1)
- self.lastPath = None
- self.updateTaskList ()
-
- # Makes the current task inactive and refreshes the task list.
- def deactivateTask (self):
- self.scheduleList [self.taskIndex].setActive (0)
- self.updateTaskList ()
-
- # Show a confirmation dialog before deleting the task.
- def confirmDeleteTask (self):
- # Load the dialog.
- xml = gtk.glade.XML (GLADE_FILE_PATH +
- "/confirm_delete.glade")
-
- dict = {}
- for key in dir(self.__class__):
- dict[key] = getattr(self, key)
- xml.signal_autoconnect (dict)
-
- confirm = xml.get_widget ("confirm_delete")
-
- # Center the dialog on the main window.
- confirm.set_transient_for (self.win)
- confirm.set_position (gtk.WIN_POS_CENTER_ON_PARENT)
- # Display the dialog.
- confirm.show ()
-
- # Deletes the current task and refreshes the task list.
- def deleteTask (self):
- del(self.scheduleList[self.taskIndex])
- self.updateTaskList ()
-
- # Launches the "about" dialog.
- def about (self):
- aboutObject = About (self.win)
# Builds or refreshes the task list.
def updateTaskList (self, onlyCurrentTask = False, updateTask = True,
updateScheduler = True):
Index: src/lib/scheduler.py
===================================================================
RCS file: /cvsroot/pyatcron/pyatcron/src/lib/scheduler.py,v
retrieving revision 1.8
diff -u -r1.8 scheduler.py
--- src/lib/scheduler.py 27 Apr 2004 14:56:25 -0000 1.8
+++ src/lib/scheduler.py 28 Apr 2004 16:19:33 -0000
@@ -34,10 +34,12 @@
return str(self.task)
def setActive(self,value):
- if value == 1:
- self.active = 1
+ if (value):
+ self.active = True
+ print "Scheduler::setActive: active status set to True"
else:
- self.active = 0
+ self.active = False
+ print "Scheduler::setActive: active status set to False"
return
def isActive(self):
Index: src/lib/syntacticengine.py
===================================================================
RCS file: /cvsroot/pyatcron/pyatcron/src/lib/syntacticengine.py,v
retrieving revision 1.2
diff -u -r1.2 syntacticengine.py
--- src/lib/syntacticengine.py 15 Apr 2004 14:34:46 -0000 1.2
+++ src/lib/syntacticengine.py 28 Apr 2004 16:19:33 -0000
@@ -7,6 +7,9 @@
self.scheduler = scheduler
return
+ def getSchedulerName(self):
+ return str(self.scheduler)
+
def getNextRunString(self):
# Determine when the task will occur next
values = self.scheduler.getAttributes ()