1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636
|
#!/usr/bin/env python3
"""Provide a configuration dialog for the dock panel applet
Allow the user to specify whether the application running
indicator is light or dark coloured, so that it can always be
easily seen no matter what colour the panel is
"""
# Copyright (C) 1997-2003 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
# Author:
# Robin Thompson
# do not change the value of this variable - it will be set during build
# according to the value of the --with-gtk3 option used with .configure
build_gtk2 = False
import gi
if build_gtk2:
gi.require_version("Gtk", "2.0")
else:
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
import cairo
import math
class IndicatorType:
"""Class to define the indicator types"""
LIGHT = 0
DARK = 1
NONE = 2
class DockPrefsWindow(Gtk.Window):
"""Class to provide the preferences window functionality
Create and display the preferences window
Provide methods to get and set:
the type of indicator to be used by the dock applet
whether pinned/unpinned apps are to be displayed from all workspaces or
just the current workspace
whether the colour of the MATE panels is to be set to the dominant
colour of the current wallpaper image
"""
def __init__(self, ok_callback):
""" Constructor for the preferences window
Create the window and its contents and display them
set the callback for the ok button press
Args:
ok_callback : the method to be called when the ok button is
is pressed
"""
super().__init__(title="Preferences")
self.DA_SIZE = 32 # the size of the drawing areas for the light and
# dark indicators
self.connect("delete-event", self.win_delete_event)
# setup the window contents
self.set_border_width(5)
if build_gtk2:
self.__hbox = Gtk.HBox()
else:
self.__hbox = Gtk.Box()
self.__hbox.set_orientation(Gtk.Orientation.HORIZONTAL)
self.__hbox.set_spacing(2)
if build_gtk2:
self.__hbox1 = Gtk.HBox()
else:
self.__hbox1 = Gtk.Box()
self.__hbox1.set_orientation(Gtk.Orientation.HORIZONTAL)
self.__hbox1.set_spacing(2)
if build_gtk2:
self.__vbox = Gtk.VBox()
else:
self.__vbox = Gtk.Box()
self.__vbox.set_orientation(Gtk.Orientation.VERTICAL)
self.__vbox.set_spacing(2)
self.__cancel_btn = Gtk.Button(label=("Cancel1"),
stock=Gtk.STOCK_CANCEL)
self.__cancel_btn.connect("button-press-event",
self.win_cancel_button_press)
self.__ok_btn = Gtk.Button(label="Ok", stock=Gtk.STOCK_OK)
self.__ok_btn.connect("button-press-event", ok_callback)
if build_gtk2:
self.__hbbx = Gtk.HButtonBox()
else:
self.__hbbx = Gtk.ButtonBox()
self.__hbbx.set_orientation(Gtk.Orientation.HORIZONTAL)
self.__hbbx.set_spacing(4)
self.__hbbx.set_layout(Gtk.ButtonBoxStyle.END)
self.__hbbx.pack_start(self.__ok_btn, False, False, 4)
self.__hbbx.pack_start(self.__cancel_btn, False, False, 4)
self.__notebook = Gtk.Notebook()
self.__frame_ind_type = self.create_frame("Indicator Type")
self.__rb_light_ind = Gtk.RadioButton(label="Light (for dark panels)")
self.__rb_dark_ind = Gtk.RadioButton(group=self.__rb_light_ind,
label="Dark (for light panels)")
self.__rb_no_ind = Gtk.RadioButton(group=self.__rb_light_ind,
label="None - don't use indicators")
self.__rb_no_ind.connect("toggled", self.rb_no_ind_toggled)
self.__da_light_ind = Gtk.DrawingArea()
self.__da_light_ind.set_size_request(self.DA_SIZE, self.DA_SIZE)
# connect an event handler to draw the light indicator
if build_gtk2:
self.__da_light_ind.connect("expose-event", self.draw_light_ind)
else:
self.__da_light_ind.connect("draw", self.draw_light_ind)
self.__da_dark_ind = Gtk.DrawingArea()
self.__da_dark_ind.set_size_request(self.DA_SIZE, self.DA_SIZE)
# connect an event handler to draw the dark indicator
if build_gtk2:
self.__da_dark_ind.connect("expose-event", self.draw_dark_ind)
else:
self.__da_dark_ind.connect("draw", self.draw_dark_ind)
# create ui elements for multiple indicators for open windows
self.__cb_multi_ind = Gtk.CheckButton(label="Display an indicator for each open window")
self.__cb_multi_ind.set_tooltip_text("Display an indicator (max 4) for each open window")
if build_gtk2:
self.__table_ind_type = Gtk.Table(rows=3, columns=2,
homogeneous=False)
else:
self.__table_ind_type = Gtk.Grid()
self.__table_ind_type.set_column_spacing(4)
self.__table_ind_type.set_row_spacing(4)
self.__table_ind_type.set_row_homogeneous(True)
# add the indicator type ui elements to the table
if build_gtk2:
self.__table_ind_type.attach(self.__rb_light_ind, 0, 1, 0, 1,
Gtk.AttachOptions.FILL,
Gtk.AttachOptions.SHRINK,
2, 2)
self.__table_ind_type.attach(self.__da_light_ind, 1, 2, 0, 1,
Gtk.AttachOptions.FILL,
Gtk.AttachOptions.SHRINK,
2, 2)
self.__table_ind_type.attach(self.__rb_dark_ind, 0, 1, 1, 2,
Gtk.AttachOptions.FILL,
Gtk.AttachOptions.SHRINK,
2, 2)
self.__table_ind_type.attach(self.__da_dark_ind, 1, 2, 1, 2,
Gtk.AttachOptions.FILL,
Gtk.AttachOptions.SHRINK,
2, 2)
self.__table_ind_type.attach(self.__rb_no_ind, 0, 1, 2, 3,
Gtk.AttachOptions.FILL,
Gtk.AttachOptions.SHRINK,
2, 2)
else:
self.__table_ind_type.attach(self.__rb_light_ind, 0, 0, 1, 1)
self.__table_ind_type.attach(self.__da_light_ind, 1, 0, 1, 1)
self.__table_ind_type.attach(self.__rb_dark_ind, 0, 1, 1, 1)
self.__table_ind_type.attach(self.__da_dark_ind, 1, 1, 1, 1)
self.__table_ind_type.attach(self.__rb_no_ind, 0, 2, 3, 1)
# make sure the indicator type ui elements are aligned properly
self.__frame_ind_type_align = Gtk.Alignment(xalign=0.5, yalign=0.5,
xscale=1.0, yscale=1.0)
self.__frame_ind_type_align.set_padding(0, 0, 12, 0)
self.__frame_ind_type_align.add(self.__table_ind_type)
self.__frame_ind_type.add(self.__frame_ind_type_align)
if build_gtk2:
self.__ind_vbox = Gtk.VBox()
self.__ind_vbox.set_spacing(2)
self.__ind_vbox.pack_start(self.__frame_ind_type, False, False, 4)
self.__ind_vbox.pack_start(self.__cb_multi_ind, False, False, 4)
else:
self.__ind_vbox = Gtk.Grid()
self.__ind_vbox.set_column_spacing(6)
self.__ind_vbox.set_row_spacing(6)
self.__ind_vbox.attach(self.__frame_ind_type, 0, 0, 1, 1)
self.__ind_vbox.attach(self.__cb_multi_ind, 0, 1, 1, 1)
self.__frame_unpinned_apps = self.create_frame("Unpinned applications")
self.__rb_unpinned_all_ws = Gtk.RadioButton (label="Display unpinned apps from all workspaces")
self.__rb_unpinned_cur_ws = Gtk.RadioButton(group=self.__rb_unpinned_all_ws,
label="Display unpinned apps only from current workspace")
if build_gtk2:
self.__table_unpinned_apps = Gtk.Table(rows=2, columns=1,
homogeneous=False)
self.__table_unpinned_apps.attach(self.__rb_unpinned_all_ws,
0, 1, 0, 1,
Gtk.AttachOptions.FILL,
Gtk.AttachOptions.SHRINK,
2, 2)
self.__table_unpinned_apps.attach(self.__rb_unpinned_cur_ws,
0, 1, 1, 2,
Gtk.AttachOptions.FILL,
Gtk.AttachOptions.SHRINK,
2, 2)
else:
self.__table_unpinned_apps = Gtk.Grid()
self.__table_unpinned_apps.set_row_spacing(2)
self.__table_unpinned_apps.set_column_spacing(2)
self.__table_unpinned_apps.attach(self.__rb_unpinned_all_ws,
0, 0, 1, 1)
self.__table_unpinned_apps.attach(self.__rb_unpinned_cur_ws,
0, 1, 1, 1)
self.__frame_unpinned_apps_align = Gtk.Alignment(xalign=0.5, yalign=0.5,
xscale=1.0, yscale=1.0)
self.__frame_unpinned_apps_align.set_padding(0, 0, 12, 0)
self.__frame_unpinned_apps_align.add(self.__table_unpinned_apps)
self.__frame_unpinned_apps.add(self.__frame_unpinned_apps_align)
self.__cb_win_cur_ws = Gtk.CheckButton(label="Display indicators/window list items for current workspace only")
if build_gtk2:
self.__ws_vbox = Gtk.VBox()
else:
self.__ws_vbox = Gtk.Box()
self.__ws_vbox.set_orientation(Gtk.Orientation.VERTICAL)
self.__ws_vbox.set_spacing(2)
self.__ws_vbox.pack_start(self.__frame_unpinned_apps, False, False, 4)
self.__ws_vbox.pack_start(self.__cb_win_cur_ws, False, False, 4)
self.__frame_win_sel = self.create_frame("Window selection")
self.__rb_win_list = Gtk.RadioButton (label="From applet's window list")
self.__rb_win_thumb = Gtk.RadioButton(group=self.__rb_win_list, \
label="From window thumbnail previews (requires Compiz)")
self.__table_win_sel = Gtk.Table(rows=2, columns=1,
homogeneous=False)
self.__table_win_sel.attach(self.__rb_win_list,
0, 1, 0, 1,
Gtk.AttachOptions.FILL,
Gtk.AttachOptions.SHRINK,
2, 2)
self.__table_win_sel.attach(self.__rb_win_thumb,
0, 1, 1, 2,
Gtk.AttachOptions.FILL,
Gtk.AttachOptions.SHRINK,
2, 2)
self.__frame_win_sel_align = Gtk.Alignment(xalign=0.5, yalign=0.5,
xscale=1.0, yscale=1.0)
self.__frame_win_sel_align.set_padding(0, 0, 12, 0)
self.__frame_win_sel_align.add(self.__table_win_sel)
self.__frame_win_sel.add(self.__frame_win_sel_align)
if build_gtk2:
self.__win_sel_vbox = Gtk.VBox()
else:
self.__win_sel_vbox = Gtk.Box()
self.__win_sel_vbox.set_orientation(Gtk.Orientation.VERTICAL)
self.__win_sel_vbox.set_spacing(2)
self.__win_sel_vbox.pack_start(self.__frame_win_sel, False,
False, 4)
self.__frame_color_change = self.create_frame("Panel colour")
self.__cb_panel_color_change = Gtk.CheckButton(label="Change panel colour to match wallpaper")
self.__cb_panel_color_change.connect("toggled", self.color_change_toggled)
self.__cb_dock_panel_only = Gtk.CheckButton(label="Change colour of dock's panel only")
self.__table_color_change = Gtk.Table(rows=2, columns=1,
homogeneous=False)
self.__table_color_change.attach(self.__cb_panel_color_change,
0, 1, 0, 1,
Gtk.AttachOptions.FILL,
Gtk.AttachOptions.SHRINK,
2, 2)
self.__table_color_change.attach(self.__cb_dock_panel_only,
0, 1, 1, 2,
Gtk.AttachOptions.FILL,
Gtk.AttachOptions.SHRINK,
2, 2)
self.__frame_color_change_align = Gtk.Alignment(xalign=0.5, yalign=0.5,
xscale=1.0, yscale=1.0)
self.__frame_color_change_align.set_padding(0, 0, 12, 0)
self.__frame_color_change_align.add(self.__table_color_change)
self.__frame_color_change.add(self.__frame_color_change_align)
self.__cb_pan_act = Gtk.CheckButton(label="Disable popup action list " + \
"and show app actions\non panel " + \
"right click menu only")
if build_gtk2:
self.__panel_vbox = Gtk.VBox()
else:
self.__panel_vbox = Gtk.Box()
self.__panel_vbox.set_orientation(Gtk.Orientation.VERTICAL)
self.__panel_vbox.set_spacing(2)
self.__panel_vbox.pack_start(self.__frame_color_change,
False, False, 4)
self.__panel_vbox.pack_start(self.__cb_pan_act,
False, False, 4)
self.__vbox.pack_start(self.__notebook, True, True, 4)
self.__notebook.append_page(self.__ind_vbox, Gtk.Label("Indicators"))
self.__notebook.append_page(self.__ws_vbox, Gtk.Label("Workspaces"))
self.__notebook.append_page(self.__win_sel_vbox, Gtk.Label("Windows"))
self.__notebook.append_page(self.__panel_vbox,
Gtk.Label("Panel Options"))
self.__vbox.pack_start(Gtk.HSeparator(), True, True, 4)
self.__vbox.pack_start(self.__hbbx, False, False, 0)
self.add(self.__vbox)
self.show_all()
def create_frame(self, caption):
""" Convenience function to create a Gtk.Frame with a desired caption
in bold text
Returns:
frame - the Gtk.Frame we created
"""
frame = Gtk.Frame(label="aaaa")
lbl = frame.get_label_widget()
lbl.set_use_markup(True)
lbl.set_label("<b>%s</b>" % caption)
frame.set_shadow_type(Gtk.ShadowType.NONE)
frame.set_border_width(4)
return frame
def win_delete_event(self, widget, event, data=None):
"""Callback for the preferences window delete event
Do not delete the window, hide it instead so that it can be shown again
later if needed
"""
self.hide()
return True
def win_cancel_button_press(self, widget, event):
"""Callback for the preferences window Cancel button press
Hide the window
"""
self.hide()
def draw_light_ind(self, drawing_area, event):
"""Draw a light indicator on a dark background"""
if build_gtk2:
ctx = self.__da_light_ind.window.cairo_create()
else:
ctx = event
ctx.set_source_rgb(0.1, 0.5, 0.5)
ctx.rectangle(0, 0, self.DA_SIZE, self.DA_SIZE)
ctx.fill()
ctx.set_source_rgb(0.05, 0.05, 0.3)
ctx.rectangle(1, 1, self.DA_SIZE-2, self.DA_SIZE-2)
ctx.fill()
ind_x = self.DA_SIZE/2
ind_y = ind_x
rad_patt = cairo.RadialGradient(ind_x, ind_y, 2, ind_x, ind_y, 4)
rad_patt.add_color_stop_rgba(0, 0.9, 0.9, 0.9, 1)
rad_patt.add_color_stop_rgba(1, 0.0, 0.0, 0.0, 0)
ctx.set_source(rad_patt)
ctx.arc(ind_x, ind_y, 6, 0, 2*math.pi)
ctx.fill()
def draw_dark_ind(self, drawing_area, event):
"""Draw a dark indicator on a dark background."""
if build_gtk2:
ctx = self.__da_dark_ind.window.cairo_create()
else:
ctx = event
ctx.set_source_rgb(0.5, 0.5, 0.5)
ctx.rectangle(0, 0, self.DA_SIZE, self.DA_SIZE)
ctx.fill()
ctx.set_source_rgb(0.1, 0.8, 0.8)
ctx.rectangle(1, 1, self.DA_SIZE-2, self.DA_SIZE-2)
ctx.fill()
ind_x = self.DA_SIZE/2
ind_y = ind_x
rad_patt = cairo.RadialGradient(ind_x, ind_y, 2, ind_x, ind_y, 4)
rad_patt.add_color_stop_rgba(0, 0.0, 0.0, 0.0, 1)
rad_patt.add_color_stop_rgba(1, 0.9, 0.9, 0.9, 0)
ctx.set_source(rad_patt)
ctx.arc(ind_x, ind_y, 6, 0, 2*math.pi)
ctx.fill()
def color_change_toggled(self, widget):
"""Handler for the panel color change checkbox toggled event
If the panel colour change option is selected, enable the checkbox that
specifies whether or not all panels are to change colour
"""
self.__cb_dock_panel_only.set_sensitive(self.__cb_panel_color_change.get_active())
def rb_no_ind_toggled(self, widget):
""" Handler for the no indicator radio button toggled event
If the no indicator option is selected, disable the multiple indicator
checkbox
"""
self.__cb_multi_ind.set_sensitive(self.__rb_no_ind.get_active() is not True)
def get_indicator_type(self):
"""Get the indicator type specified in the preferences window.
Returns : IndicatorType
"""
if self.__rb_light_ind.get_active():
return IndicatorType.LIGHT
elif self.__rb_dark_ind.get_active():
return IndicatorType.DARK
else:
return IndicatorType.NONE
def set_indicator(self, indicator):
"""Set the indicator type
Args : indicator - an IndicatorType
"""
if indicator == IndicatorType.LIGHT:
self.__rb_light_ind.set_active(True)
elif indicator == IndicatorType.DARK:
self.__rb_dark_ind.set_active(True)
else:
self.__rb_no_ind.set_active(True)
def get_multi_ind(self):
"""Gets whether or not to use display an indicator for each open
window that a docked app has
Returns: boolean
"""
return self.__cb_multi_ind.get_active()
def set_multi_ind(self, use_multi_ind):
"""Sets whether or not to display multiple indicators
Args: use_multi_ind - boolean
"""
self.__cb_multi_ind.set_active(use_multi_ind)
def get_show_unpinned_apps_on_all_ws(self):
"""Gets whether unpinned apps are displayed in the dock on all workspaces
Returns: boolean
"""
return self.__rb_unpinned_all_ws.get_active()
def set_show_unpinned_apps_on_all_ws(self, show_on_all):
"""Sets whether unpinned apps are displayed in the dock on all workspaces
Args: show_on_all - boolean
"""
if show_on_all:
self.__rb_unpinned_all_ws.set_active(True)
else:
self.__rb_unpinned_cur_ws.set_active(True)
def get_show_pinned_apps_on_all_ws(self):
"""Gets whether pinned apps are displayed in the dock on all workspaces
Returns: boolean
"""
return self.__rb_pinned_all_ws.get_active()
def set_show_pinned_apps_on_all_ws(self, show_on_all):
"""Sets whether pinned apps are displayed in the dock on all workspaces
Args: show_on_all - boolean
"""
if show_on_all:
self.__rb_pinned_all_ws.set_active(True)
else:
self.__rb_pinned_cur_ws.set_active(True)
def get_pan_act(self):
""" Gets whether or not the show the action list on the panel
right click menu, rather than as a popup
Returns: boolean
"""
return self.__cb_pan_act.get_active()
def set_pan_act(self, pan_act):
""" Sets whether or not the show the action list on the panel
right click menu, rather than as a popup
Args:
pan_act: boolean
"""
self.__cb_pan_act.set_active(pan_act)
def get_use_win_list(self):
"""Gets whether to use the dock's window list to select windows
or whether to use Compiz thumbnail previews
Returns: boolean
"""
return self.__rb_win_list.get_active()
def set_use_win_list(self, use_win_list):
"""Sets whether to use the dock's window list to select windows
or whether to use Compiz thumbnail previews
Args: use_win_list - boolean
"""
if use_win_list:
self.__rb_win_list.set_active(True)
else:
self.__rb_win_thumb.set_active(True)
def get_change_panel_color(self):
""" Get whether the panel colour is to be changed according to the
current wallpaper
Returns: boolean
"""
return self.__cb_panel_color_change.get_active()
def set_change_panel_color(self, change_color):
""" Sets whether the panel color is to be changed according to the
current wallpaper
Args: change_color - boolean
"""
self.__cb_panel_color_change.set_active(change_color)
def get_change_dock_color_only(self):
""" Get whether only the panel containing the dock is to be changed
when setting the panel colour according to the current wallpaper
Returns: boolean
"""
return self.__cb_dock_panel_only.get_active()
def set_change_dock_color_only(self, dock_only):
""" Sets whether only the panel containing the dock is to be changed
when settings the panel colour according to the current wallpaper
Args: dock_only - boolean
"""
self.__cb_dock_panel_only.set_active(dock_only)
def get_win_cur_ws_only(self):
""" Gets whether the dock will show indicators/window list items for
the current workspace only
Returns: boolean
"""
return self.__cb_win_cur_ws.get_active()
def set_win_cur_ws_only(self, win_cur_ws_only):
""" Sets whether the dock will show indicators/window list items for
the current workspace only
Args: win_cur_ws_only - boolean
"""
self.__cb_win_cur_ws.set_active(win_cur_ws_only)
def main():
"""main function - debug code can go here"""
dpw = DockPrefsWindow(Gtk.main_quit)
Gtk.main()
if __name__ == "__main__":
main()
|