├── .github
└── workflows
│ └── main.yml
├── .gitignore
├── Dockerfile
├── LICENSE
├── README.md
├── build
├── gallery
├── import_progress.png
├── imported.png
├── initial_state.png
├── menu.png
└── thumbnails
│ ├── import_progress_thumbnail.png
│ ├── imported_thumbnail.png
│ ├── initial_state_thumbnail.png
│ └── menu_thumbnail.png
├── init.sh
├── quick_run
├── run
└── src
├── controller.py
├── helpers.py
├── main.py
├── model.py
├── resources
└── logo.png
└── view.py
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | # Build and Publish Docker Image to Docker Hub
2 | name: docker build
3 |
4 | # Triggers the workflow on push events on the master branch
5 | on:
6 | push:
7 | branches:
8 | - master
9 |
10 | jobs:
11 | build:
12 |
13 | # The type of environment that the job will run on
14 | runs-on: ubuntu-latest
15 |
16 | steps:
17 |
18 | # Checks out the repository under $GITHUB_WORKSPACE, so the job can access it
19 | - name: Check out source code
20 | uses: actions/checkout@master
21 |
22 | # Builds and pushes a docker image of the source code to Docker Hub
23 | - name: Build and push Docker image
24 | uses: docker/build-push-action@master
25 | with:
26 |
27 | # Docker Hub credentials
28 | username: ${{ secrets.DOCKER_USERNAME }}
29 | password: ${{ secrets.DOCKER_TOKEN }}
30 |
31 | # Docker repository to tag the image with
32 | repository: rastapank/flow-dashboard
33 |
34 | # Automatically tags the built image with the git reference as per the readme
35 | tag_with_ref: true
36 |
37 | # Adds labels with git repository information to the built image
38 | add_git_labels: true
39 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | src/__pycache__/
2 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | ## Stage 1: Build environment
2 | FROM alpine AS environment
3 |
4 | # Install dependencies
5 | RUN apk add python3 \
6 | py3-gobject3 \
7 | py3-lxml \
8 | gtk+3.0 \
9 | libcanberra-gtk3 \
10 | ttf-cantarell \
11 | adwaita-icon-theme \
12 | font-noto
13 |
14 |
15 | ## Stage 2: Run app
16 | FROM environment AS app
17 |
18 | # Port where the broadway daemon listens on
19 | EXPOSE 8085/tcp
20 |
21 | # Configure environment
22 | ENV NO_AT_BRIDGE=1 GTK_THEME=Adwaita:dark GDK_BACKEND=broadway BROADWAY_DISPLAY=:5
23 |
24 | # Set a directory for the app
25 | WORKDIR /opt/flow-dashboard
26 |
27 | # Copy necessary files to container
28 | COPY init.sh src/ src/
29 |
30 | # Start the app
31 | ENTRYPOINT ["/bin/sh", "./src/init.sh"]
32 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # flow-dashboard [](https://github.com/UoC-Radio/flow-dashboard/actions?query=workflow%3A%22docker+build%22)
2 | #### A GTK+ based GUI generator of the radio station's on-air schedule.
3 |
4 | This is a graphical XML generator and database front-end application. It acts as the GUI of [Audio Scheduler](https://github.com/UoC-Radio/audio-scheduler/). It aims to:
5 | * Facilitate creation of the [music schedule](http://radio.uoc.gr/schedule/schedule.xml), which is given as input to Audio Scheduler.
6 | * Provide zone management for the music library of the radio station.
7 |
8 | ## Screenshots
9 | [](/gallery/initial_state.png?raw=true)
10 | [](/gallery/menu.png?raw=true)
11 | [](/gallery/import_progress.png?raw=true)
12 | [](/gallery/imported.png?raw=true)
13 |
14 | ## Build and Run natively
15 | ### Dependencies
16 | To run flow-dashboard, you will need to have the following installed:
17 | * Python 3
18 | * GTK+3 [[Instructions]](https://pygobject.readthedocs.io/en/latest/getting_started.html)
19 | * lxml for python 3 [[Instructions]](https://lxml.de/installation.html)
20 |
21 | ### Run
22 | After installing the dependencies above, just do:
23 | ```
24 | python3 ./src/main.py
25 | ```
26 |
27 | ## Build and Run with Docker
28 | An alternative (and probably easier) way to build and run the app is by using Docker. Besides Docker, you don't need any other dependencies installed.
29 | The app will run locally as a web application.
30 |
31 | ### Linux & MacOS
32 | To build and run the app from source:
33 | ```
34 | ./build
35 | ./run
36 | ```
37 |
38 | To download and run the latest version of the app:
39 | ```
40 | ./quick_run
41 | ```
42 | The above command first updates the app if it is outdated, and then runs it.
43 |
44 | ### Windows
45 | The app can be deployed by executing Docker commands manually. Check out the provided bash scripts for a hint.
46 |
47 | ## Credits
48 | [ggalan87](https://github.com/ggalan87) for his advice on GUI design
49 | [looselyrigorous](https://github.com/looselyrigorous) for his CSS styling ideas
50 |
--------------------------------------------------------------------------------
/build:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | buildCommand="docker build -t rastapank/flow-dashboard:local-build ."
4 | echo "[*] Executing: $buildCommand"
5 | $buildCommand
6 |
--------------------------------------------------------------------------------
/gallery/import_progress.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UoC-Radio/flow-dashboard/bc391efb85d32e439fc21b3c34b108353c98e4c2/gallery/import_progress.png
--------------------------------------------------------------------------------
/gallery/imported.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UoC-Radio/flow-dashboard/bc391efb85d32e439fc21b3c34b108353c98e4c2/gallery/imported.png
--------------------------------------------------------------------------------
/gallery/initial_state.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UoC-Radio/flow-dashboard/bc391efb85d32e439fc21b3c34b108353c98e4c2/gallery/initial_state.png
--------------------------------------------------------------------------------
/gallery/menu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UoC-Radio/flow-dashboard/bc391efb85d32e439fc21b3c34b108353c98e4c2/gallery/menu.png
--------------------------------------------------------------------------------
/gallery/thumbnails/import_progress_thumbnail.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UoC-Radio/flow-dashboard/bc391efb85d32e439fc21b3c34b108353c98e4c2/gallery/thumbnails/import_progress_thumbnail.png
--------------------------------------------------------------------------------
/gallery/thumbnails/imported_thumbnail.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UoC-Radio/flow-dashboard/bc391efb85d32e439fc21b3c34b108353c98e4c2/gallery/thumbnails/imported_thumbnail.png
--------------------------------------------------------------------------------
/gallery/thumbnails/initial_state_thumbnail.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UoC-Radio/flow-dashboard/bc391efb85d32e439fc21b3c34b108353c98e4c2/gallery/thumbnails/initial_state_thumbnail.png
--------------------------------------------------------------------------------
/gallery/thumbnails/menu_thumbnail.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UoC-Radio/flow-dashboard/bc391efb85d32e439fc21b3c34b108353c98e4c2/gallery/thumbnails/menu_thumbnail.png
--------------------------------------------------------------------------------
/init.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | broadwayd :5 &
4 | python3 ./src/main.py
5 |
--------------------------------------------------------------------------------
/quick_run:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | ./run --quick
4 |
--------------------------------------------------------------------------------
/run:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | if [ "$1" = "--quick" ]; then
4 | repo=rastapank/flow-dashboard:latest
5 | docker pull $repo
6 | containerName=flow-dashboard-upstream
7 | else
8 | repo=rastapank/flow-dashboard:local-build
9 | containerName=flow-dashboard-local
10 | fi
11 |
12 | # Make a shared directory, which can be accessed by both host and container.
13 | # It can be used for sharing schedule files.
14 | sharedDirName=schedules
15 | mkdir -p $sharedDirName
16 |
17 | if [ -d "$sharedDirName" ]; then
18 | hostSharedDirPath=`pwd`/$sharedDirName
19 | containerSharedDirPath=/opt/flow-dashboard/$sharedDirName
20 | makeSharedDir="-v $hostSharedDirPath:$containerSharedDirPath"
21 |
22 | else
23 | echo "[!] Shared directory \"$sharedDir\" not found. Manual copy of the schedule to/from container is required."
24 | makeSharedDir=""
25 | fi
26 |
27 | runCommand="docker run -t --rm -P $makeSharedDir --name $containerName $repo"
28 | echo "[*] Executing: $runCommand"
29 | $runCommand &
30 | sleep 2
31 |
32 | hostPort=`docker port $containerName | cut -d ":" -f 2`
33 |
34 | if [ -n "$hostPort" ]; then
35 | URL="http://localhost:$hostPort"
36 | echo "[*] App is running on: $URL"
37 |
38 | if [ -n "$BROWSER" ]; then
39 | $BROWSER $URL
40 | elif which xdg-open > /dev/null; then
41 | xdg-open $URL
42 | elif which gnome-open > /dev/null; then
43 | gnome-open $URL
44 | elif [ `uname -s` = "Darwin" ]; then
45 | open $URL
46 | else
47 | echo "Could not detect the web browser to use. Please visit: $URL"
48 | fi
49 | fi
50 |
--------------------------------------------------------------------------------
/src/controller.py:
--------------------------------------------------------------------------------
1 | """
2 | The Controller
3 |
4 | Copyright (C) 2018 Elias Papavasileiou
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 | """
19 |
20 | import gi
21 | gi.require_version('Gtk', '3.0')
22 | from gi.repository.Gtk import Application, Builder, Entry, MessageType, ResponseType,\
23 | EntryCompletion
24 | from gi.repository.Gio import SimpleAction
25 | from gi.repository.GLib import idle_add
26 | from lxml import etree as ET
27 | from xml.dom.minidom import parseString
28 | from urllib.request import urlopen
29 | from threading import Thread
30 | from time import sleep
31 |
32 | from helpers import Playlist, getPlaylistNameFromPath, addPlaylistToZone,\
33 | MENU, XSD_SCHEMA_URL, XSD_SCHEMA_FALLBACK, WEEK, APP_TITLE, getHoursModel
34 | from view import View
35 | from model import Model
36 |
37 |
38 | class Controller(Application):
39 | """ Coordinates communication between the Model and the View.
40 |
41 | The whole point of MVC is to seperate the data (Model) from the GUI (View),
42 | to make the design modular.
43 |
44 | Thanks to GTK+, the view is automatically updated
45 | whenever the model changes.
46 | """
47 |
48 | def __init__(self):
49 | super().__init__()
50 |
51 | def do_startup(self):
52 | """ Perform startup operations.
53 |
54 | Called once, on application startup.
55 | """
56 | Application.do_startup(self)
57 |
58 | # Connect the close button to a callback
59 | action = SimpleAction.new('quit', None)
60 | action.connect('activate', self.on_quit)
61 | self.add_action(action)
62 |
63 | # Install main menu
64 | builder = Builder()
65 | builder.add_from_string(MENU)
66 | self.set_app_menu(builder.get_object('app-menu'))
67 |
68 | # Get a (single) view and model.
69 | # Because this function is executed only once,
70 | # multiple models or views cannot exist.
71 | self.view = View(application=self, title=APP_TITLE)
72 | self.model = Model()
73 |
74 | # Pass view all the callbacks, to assign each one to the appropriate GUI object.
75 | self.view.setCallbacks(self.Callbacks(self.model, self.view, self.XML(
76 | self.model, self.view)))
77 |
78 | # Initialize the GUI
79 | self.view.initGUI()
80 |
81 | # Connect each view component with its corresponding model.
82 | # This is clearly a controller's responsibility.
83 | self.view.zones.set_model(self.model.zones)
84 | self.view.playlists.set_model(self.model.playlists)
85 | for dayIndex in range(7):
86 | self.view.schedule[dayIndex].set_model(self.model.schedule[dayIndex])
87 |
88 | # Set app title and logo in gnome's top bar
89 | self.view.set_wmclass('Flow Dashboard', 'Flow Dashboard')
90 | self.view.set_icon_from_file('src/resources/logo.png')
91 |
92 | # Make the GUI visible
93 | self.view.show_all()
94 |
95 | # Zone Inspector is set initially invisible, until a zone is selected
96 | self.view.zoneInspector.hide()
97 |
98 | def do_activate(self):
99 | """ Perform activation operations.
100 |
101 | Called every time the user tries to start the app
102 | (even when it is already started).
103 | """
104 | # Give app the keyboard focus
105 | self.view.present()
106 |
107 | def on_quit(self, action, param):
108 | """ Perform cleanup operations.
109 |
110 | Called once, on application exit.
111 | """
112 | self.quit()
113 |
114 |
115 | class Callbacks:
116 | """ Handle user interaction with the GUI.
117 |
118 | Contains all the callback functions.
119 |
120 | Each function is called when a specific action is performed by the user,
121 | to fulfill the request that corresponds to that action.
122 | """
123 |
124 | def __init__(self, model, view, xml):
125 | self.model = model
126 | self.view = view
127 | self.xml = xml
128 | self.progressBarWindow = None
129 |
130 | def onAddZoneButtonClicked(self, button):
131 | """
132 | 1) Display a dialog where the user can input the new zone name.
133 | 2) Handle user input.
134 |
135 | Trigger:
136 | User clicks the "+" button in Zones header bar.
137 | """
138 | entry = Entry()
139 | addZoneDialog = self.view.dialogs.AddZone(self.view, entry)
140 | while True:
141 | response = addZoneDialog.run()
142 | if response == ResponseType.OK:
143 | # Get user input from the dialog
144 | zoneName = entry.get_text()
145 | if not self.model.zoneExistsInDatabase(zoneName):
146 | # Ζone is absent from the database.
147 | # Αdd it and try to load it with the default playlists.
148 | self.model.addZoneToDatabase(zoneName)
149 | self.model.attemptToAddDefaultPlaylistsToZone(zoneName)
150 | break
151 | else:
152 | # Zone already exists in database.
153 | # Notify the user and let him retry.
154 | self.view.dialogs.MessagePopup(addZoneDialog, MessageType.ERROR,
155 | 'Error', 'Zone already exists.').show()
156 | else:
157 | break
158 | addZoneDialog.destroy()
159 |
160 | def onRemoveZoneButtonClicked(self, button):
161 | """ Remove selected zone.
162 |
163 | Trigger:
164 | User clicks the "-" button in Zones header bar.
165 | """
166 | # Remove the selected Zones row.
167 | # If no Zones row is selected, nothing happens.
168 | rowToRemove = self.view.zones.get_selection().get_selected()[1]
169 | if rowToRemove is not None:
170 | self.model.removeZoneFromDatabase(rowToRemove)
171 |
172 | def onAddPlaylistButtonClicked(self, button):
173 | """
174 | 1) Display a file chooser dialog where the user can select playlist files.
175 | 2) Handle user selection.
176 |
177 | Trigger:
178 | User clicks the "+" button in Playlists header bar.
179 | """
180 | addPlaylistDialog = self.view.dialogs.AddPlaylist(self.view)
181 | response = addPlaylistDialog.run()
182 | if response == ResponseType.OK:
183 | # Get playlist paths from the dialog.
184 | # User can select more than one playlist files.
185 | playlistPaths = addPlaylistDialog.get_filenames()
186 | # Add playlists to database if they are absent from it
187 | for playlistPath in playlistPaths:
188 | playlistName = getPlaylistNameFromPath(playlistPath)
189 | if not self.model.playlistExistsInDatabase(playlistName):
190 | self.model.addPlaylistToDatabase(playlistPath)
191 | addPlaylistDialog.destroy()
192 |
193 | def onRemovePlaylistButtonClicked(self, button):
194 | """ Remove selected playlist.
195 |
196 | Trigger:
197 | User clicks the "-" button in Playlists header bar.
198 | """
199 | # Remove the selected Playlists row.
200 | # If no Playlists row is selected, nothing happens.
201 | rowToRemove = self.view.playlists.get_selection().get_selected()[1]
202 | if rowToRemove is not None:
203 | self.model.removePlaylistFromDatabase(rowToRemove)
204 |
205 | def onAddZoneToScheduleButtonClicked(self, button):
206 | """ Add selected zone to the selected day of the Flow Schedule.
207 |
208 | Trigger:
209 | User clicks the "+" button in Flow Schedule header bar.
210 | """
211 | # Add the selected Zone to Flow Schedule.
212 | # If no Zone row is selected, nothing happens.
213 | zoneToAdd = self.view.zones.get_selection().get_selected()[1]
214 | if zoneToAdd is not None:
215 | zoneName = self.model.zones[
216 | self.view.zones.get_selection().get_selected()[1]
217 | ][0]
218 | selectedDayIndex = self.view.scheduleNotebook.get_current_page()
219 | self.model.addZoneToSchedule(selectedDayIndex, zoneName)
220 |
221 | def onRemoveZoneFromScheduleButtonClicked(self, button):
222 | """ Remove selected occurrence of a zone in the Flow Schedule.
223 |
224 | Trigger:
225 | User clicks the "-" button in Flow Schedule header bar.
226 | """
227 | # Remove the selected Flow Schedule row.
228 | # If no Flow Schedule row is selected, nothing happens.
229 | selectedDayIndex = self.view.scheduleNotebook.get_current_page()
230 | rowToRemove = self.view.schedule[
231 | selectedDayIndex].get_selection().get_selected()[1]
232 | if rowToRemove is not None:
233 | self.model.removeZoneFromSchedule(selectedDayIndex, rowToRemove)
234 |
235 | def onAddPlaylistToZoneButtonClicked(self, button):
236 | """ Add selected playlist to selected zone.
237 |
238 | Trigger:
239 | User clicks the "+" button in Zone Inspector header bar.
240 | """
241 | # Add the selected Playlist to Zone Inspector.
242 | # If no Playlist row is selected, nothing happens.
243 | playlistToAdd = self.view.playlists.get_selection().get_selected()[1]
244 | if playlistToAdd is not None:
245 | playlistName = self.model.playlists[
246 | self.view.playlists.get_selection().get_selected()[1]
247 | ][0]
248 | zoneName = self.model.zones[
249 | self.view.zones.get_selection().get_selected()[1]
250 | ][0]
251 | addPlaylistToZone(playlistName, zoneName, self.model)
252 |
253 | def onRemovePlaylistFromZoneButtonClicked(self, button):
254 | """ Remove selected playlist from selected zone.
255 |
256 | Trigger:
257 | User clicks the "-" button in Zone Inspector header bar.
258 | """
259 | # Remove the selected Zone Inspector row.
260 | # If no Zone Inspector row is selected, nothing happens.
261 | rowToRemove = self.view.zoneInspector.get_selection().get_selected()[1]
262 | if rowToRemove is not None:
263 | zoneName = self.model.zones[
264 | self.view.zones.get_selection().get_selected()[1]
265 | ][0]
266 | self.model.removePlaylistFromZone(zoneName, rowToRemove)
267 |
268 | def onScheduleRowEditingStarted(self, renderer, editable, path, column):
269 | """ Activate autocompletion in the Flow Schedule cell that is being edited.
270 |
271 | Trigger:
272 | User starts editing a Flow Schedule row.
273 | """
274 | completion = EntryCompletion.new()
275 | model = self.model.zones if column == 1 else getHoursModel()
276 | completion.set_model(model)
277 | completion.set_text_column(0)
278 | editable.set_completion(completion)
279 |
280 | def onScheduleRowEdited(self, renderer, path, newString, dayIndex, column):
281 | """ Handle user input and update the model.
282 |
283 | Trigger:
284 | User finishes editing a Flow Schedule row.
285 | """
286 | if column != 1:
287 | # Update the model accordingly.
288 | self.model.schedule[dayIndex][path][column] = newString
289 | elif not self.model.zoneExistsInDatabase(newString):
290 | # New zone does not exist in database. Notify the user.
291 | self.view.dialogs.MessagePopup(self.view, MessageType.ERROR, 'Error',
292 | 'Zone does not exist in database.').show()
293 | elif self.model.schedule[dayIndex][path][column] != newString:
294 | # User changes a zone's name in Flow Schedule.
295 | # Update the model accordingly.
296 | self.model.schedule[dayIndex][path][column] = newString
297 |
298 | def onZoneRowEdited(self, renderer, path, newString, column):
299 | """ Handle user input and update the model.
300 |
301 | Trigger:
302 | User finishes editing a Zones row.
303 | """
304 | if column != 0:
305 | # Update the model accordingly.
306 | self.model.zones[path][column] = newString
307 | elif not self.model.zoneExistsInDatabase(newString):
308 | # User changes a zone's name in Zones.
309 | oldZoneName = self.model.zones[path][column]
310 | self.model.editZoneNameInDatabase(oldZoneName, newString)
311 | elif self.model.zones[path][column] != newString:
312 | # New zone already exists in database. Notify the user.
313 | self.view.dialogs.MessagePopup(self.view, MessageType.ERROR, 'Error',
314 | 'Zone already exists.').show()
315 |
316 | def onZoneInspectorRowEditingStarted(self, renderer, editable, path, column):
317 | """ Activate autocompletion in the Zone Inspector cell that is being edited.
318 |
319 | Trigger:
320 | User starts editing a Zone Inspector row.
321 | """
322 | if column == 0:
323 | completion = EntryCompletion.new()
324 | completion.set_model(self.model.playlists)
325 | completion.set_text_column(0)
326 | editable.set_completion(completion)
327 |
328 | def onZoneInspectorRowEdited(self, renderer, path, newString, column):
329 | """ Handle user input and update the model.
330 |
331 | Trigger:
332 | User finishes editing a Zone Inspector row.
333 | """
334 | zoneSelected = self.model.zones[
335 | self.view.zones.get_selection().get_selected()[1]
336 | ][0]
337 | if column != 0:
338 | # Update the model accordingly.
339 | self.model.zoneInspector[zoneSelected][path][column] = newString
340 | elif not self.model.playlistExistsInDatabase(newString):
341 | # New playlist does not exist in database. Notify the user.
342 | self.view.dialogs.MessagePopup(self.view, MessageType.ERROR, 'Error',
343 | 'Playlist does not exist in database.').show()
344 | elif self.model.zoneInspector[zoneSelected][path][column] != newString:
345 | # User changes a playlist's name in Zone Inspector.
346 | # Update the model accordingly.
347 | self.model.zoneInspector[zoneSelected][path][column] = newString
348 |
349 | def onPlaylistTypeChanged(self, widget, path, newPlaylistType):
350 | """ Update the model.
351 |
352 | Trigger:
353 | User selects a playlist type.
354 | """
355 | # Get selected zone and update the model accordingly.
356 | zoneSelected = self.model.zones[
357 | self.view.zones.get_selection().get_selected()[1]
358 | ][0]
359 | self.model.zoneInspector[zoneSelected][path][1] = newPlaylistType
360 |
361 | def onShuffleToggled(self, renderer, path, column):
362 | """ Update the model.
363 |
364 | Trigger:
365 | User clicks the "Shuffle" checkbox.
366 | """
367 | # Get selected zone and update the model accordingly.
368 | zoneSelected = self.model.zones[
369 | self.view.zones.get_selection().get_selected()[1]
370 | ][0]
371 | self.model.zoneInspector[zoneSelected][path][column] = not\
372 | self.model.zoneInspector[zoneSelected][path][column]
373 |
374 | def onZoneRowSelected(self, selection):
375 | """ Update the GUI.
376 |
377 | Trigger:
378 | User selects a Zone row.
379 | """
380 | zoneRowSelected = selection.get_selected()[1]
381 | if zoneRowSelected is not None:
382 | # Make Zone Inspector display the contents of selected zone.
383 | # Do this by connecting Zone Inspector's view with selected
384 | # zone's model
385 | zoneSelected = self.model.zones[zoneRowSelected][0]
386 | self.view.zoneInspector.set_model(self.model.zoneInspector[zoneSelected])
387 | # Show Zone Inspector
388 | if not self.view.zoneInspector.get_visible():
389 | self.view.zoneInspector.show()
390 | # Enable "-" button in Zones header bar
391 | self.view.removeZoneButton.set_sensitive(True)
392 | # Enable "+" button in Zone Inspector header bar, if there is a selected playlist
393 | playlistRowSelected = self.view.playlists.get_selection().get_selected()[1]
394 | if playlistRowSelected is not None:
395 | self.view.addPlaylistToZoneButton.set_sensitive(True)
396 | # Enable "+" button in Flow Schedule header bar
397 | self.view.addZoneToScheduleButton.set_sensitive(True)
398 | else:
399 | # No zone is selected
400 | # Hide Zone Inspector
401 | self.view.zoneInspector.hide()
402 | # Disable "-" button in Zones header bar
403 | self.view.removeZoneButton.set_sensitive(False)
404 | # Disable "+" button in Zone Inspector header bar
405 | self.view.addPlaylistToZoneButton.set_sensitive(False)
406 | # Disable "+" button in Flow Schedule header bar
407 | self.view.addZoneToScheduleButton.set_sensitive(False)
408 |
409 | def onPlaylistRowSelected(self, selection):
410 | """ Update the GUI.
411 |
412 | Trigger:
413 | User selects a Playlist row.
414 | """
415 | playlistRowSelected = selection.get_selected()[1]
416 | if playlistRowSelected is not None:
417 | # Enable "-" button in Playlists header bar
418 | self.view.removePlaylistButton.set_sensitive(True)
419 | # Enable "+" button in Zone Inspector header bar, if there is a selected zone
420 | zoneRowSelected = self.view.zones.get_selection().get_selected()[1]
421 | if zoneRowSelected is not None:
422 | self.view.addPlaylistToZoneButton.set_sensitive(True)
423 | else:
424 | # Disable "-" button in Playlists header bar
425 | self.view.removePlaylistButton.set_sensitive(False)
426 | # Disable "+" button in Zone Inspector header bar
427 | self.view.addPlaylistToZoneButton.set_sensitive(False)
428 |
429 | def onScheduleRowSelected(self, selection):
430 | """ Update the GUI.
431 |
432 | Trigger:
433 | User selects a Flow Schedule row.
434 | """
435 | scheduleRowSelected = selection.get_selected()[1]
436 | if scheduleRowSelected is not None:
437 | # Enable "-" button in Flow Schedule header bar
438 | self.view.removeZoneFromScheduleButton.set_sensitive(True)
439 | else:
440 | # Disable "-" button in Flow Schedule header bar
441 | self.view.removeZoneFromScheduleButton.set_sensitive(False)
442 |
443 | def onScheduleDaySelected(self, schedule, day, dayIndex):
444 | """ Update the GUI.
445 |
446 | Trigger:
447 | User selects a Flow Schedule day.
448 | """
449 | scheduleRowSelected = self.view.schedule[
450 | dayIndex].get_selection().get_selected()[1]
451 | if scheduleRowSelected is not None:
452 | # Enable "-" button in Flow Schedule header bar
453 | self.view.removeZoneFromScheduleButton.set_sensitive(True)
454 | else:
455 | # Disable "-" button in Flow Schedule header bar
456 | self.view.removeZoneFromScheduleButton.set_sensitive(False)
457 |
458 | def onZoneInspectorRowSelected(self, selection):
459 | """ Update the GUI.
460 |
461 | Trigger:
462 | User selects a Zone Inspector row.
463 | """
464 | zoneInspectorRowSelected = selection.get_selected()[1]
465 | if zoneInspectorRowSelected is not None:
466 | # Enable "-" button in Zone Inspector header bar
467 | self.view.removePlaylistFromZoneButton.set_sensitive(True)
468 | else:
469 | # Disable "-" button in Zone Inspector header bar
470 | self.view.removePlaylistFromZoneButton.set_sensitive(False)
471 |
472 | def onImportXMLMenuOptionSelected(self, action, value):
473 | """
474 | 1) Display a file chooser dialog where the user can select an XML file.
475 | 2) Initiate the import of the selected file.
476 |
477 | Trigger:
478 | User clicks the Import XML menu option.
479 | """
480 | # Create a dialog to let user select the xml file to import
481 | importXMLDialog = self.view.dialogs.ImportXML(self.view)
482 | # Show the dialog
483 | response = importXMLDialog.run()
484 | if response == ResponseType.OK:
485 | # User clicks the dialog's Import button
486 | # Get the file path of the XML file to be imported
487 | xmlPath = importXMLDialog.get_filename()
488 | # Create and show the progress bar
489 | self.progressBarWindow = self.view.Windows.ProgressBar(
490 | self.view, 'Import Progress')
491 | self.progressBarWindow.show_all()
492 | # Execute import in a seperate thread, to let the main thread
493 | # handle GUI activity
494 | Thread(target=self.xml.importXML, args=(xmlPath,
495 | self.progressBarWindow.update,
496 | self.progressBarWindow.destroy)).start()
497 | importXMLDialog.destroy()
498 |
499 | def onExportXMLMenuOptionSelected(self, action, value):
500 | """
501 | 1) Display a file chooser dialog where the user can select a filename.
502 | 2) Initiate the export of the GUI content as XML data to the selected file.
503 |
504 | Trigger:
505 | User clicks the Export XML menu option.
506 | """
507 | # Create a dialog to let user type the xml filename to export
508 | exportXMLDialog = self.view.dialogs.ExportXML(self.view)
509 | # Show the dialog
510 | response = exportXMLDialog.run()
511 | if response == ResponseType.OK:
512 | # User clicks the dialog's Export button
513 | # Get the file path of the XML file to be exported
514 | xmlPath = exportXMLDialog.get_filename()
515 | # Create and show the progress bar
516 | self.progressBarWindow = self.view.Windows.ProgressBar(
517 | self.view, 'Export Progress')
518 | self.progressBarWindow.show_all()
519 | # Execute export in a seperate thread, to let the main thread
520 | # handle GUI activity
521 | Thread(target=self.xml.exportXML, args=(xmlPath,
522 | self.progressBarWindow.update,
523 | self.progressBarWindow.destroy)).start()
524 | exportXMLDialog.destroy()
525 |
526 |
527 | class XML:
528 | """ Perform XML-related operations. """
529 |
530 | def __init__(self, model, view):
531 | self.model = model
532 | self.view = view
533 | self.xmlSchema = None
534 |
535 | def importXML(self, inputXmlPath, updateProgressBar, destroyProgressBar):
536 | """ Import the XML file selected by the user.
537 |
538 | Use idle_add to make non-blocking requests
539 | for GUI-related operations to the main thread.
540 | """
541 | # Parse input XML file
542 | parser = ET.XMLParser(remove_comments=True)
543 | with open(inputXmlPath) as inputXmlFile:
544 | try:
545 | tree = ET.parse(inputXmlFile, parser)
546 | except Exception as e:
547 | print('Failed to parse input XML.\n' + str(e))
548 | idle_add(self.view.dialogs.MessagePopup(self.view,
549 | MessageType.ERROR, 'Error',
550 | 'Failed to parse input XML.',
551 | str(e), 'Import aborted.').show)
552 | idle_add(destroyProgressBar)
553 | return
554 | idle_add(updateProgressBar)
555 | sleep(0.1)
556 |
557 | # Download and parse XSD schema
558 | if self.xmlSchema is None:
559 | self.downloadAndParseXSDSchema()
560 | idle_add(updateProgressBar)
561 | sleep(0.1)
562 |
563 | # Validate input XML file against schema
564 | root = tree.getroot()
565 | if self.xmlSchema is not None:
566 | print('Validating input XML ...')
567 | failureMessage = 'Import aborted.'
568 | if not self.validateXML(root, failureMessage):
569 | idle_add(destroyProgressBar)
570 | return
571 | else:
572 | print('Validation of input won\'t be performed.')
573 | idle_add(self.view.dialogs.MessagePopup(self.view,
574 | MessageType.WARNING, 'Warning',
575 | 'Validation of input won\'t be performed.').show)
576 | idle_add(updateProgressBar)
577 | sleep(0.1)
578 |
579 | # Do import
580 |
581 | # Get a day of the week
582 | for dayIndex, day in enumerate(root.getchildren()):
583 |
584 | # Import its zones one by one
585 | for zone in day.getchildren():
586 | self.importZone(zone, dayIndex)
587 | idle_add(updateProgressBar)
588 | sleep(0.1)
589 |
590 | # Add imported file's location to main window title
591 | self.view.set_title(inputXmlPath + ' \u2014 ' + APP_TITLE)
592 | idle_add(destroyProgressBar)
593 |
594 | def importZone(self, zoneElement, dayIndex):
595 | """
596 | 1) Add zone to Flow Schedule.
597 | 2) Add it to the Zones database.
598 | 3) Import its playlists.
599 | """
600 | # Get the name and start time of a zone to add it to the Flow Schedule
601 | zoneName = zoneElement.get('Name')
602 | zoneStartTime = zoneElement.get('Start')[:-3] # Use -3 to ignore seconds
603 | self.model.addZoneToSchedule(dayIndex, zoneName, zoneStartTime)
604 |
605 | # Do not parse this zone element if the zone is
606 | # already (parsed and) added to the database.
607 | # It is assumed that every occurrence of a zone in the Flow Schedule
608 | # is identical to all the other occurrences of the same zone.
609 | # Thus, it only has to be parsed once, the first time it is encountered.
610 | if not self.model.zoneExistsInDatabase(zoneName):
611 |
612 | # Get the zone's metadata and add it to the database
613 | zoneMaintainers = zoneDescription = zoneComments = ''
614 | maintainerElement = zoneElement.find('Maintainer')
615 | if maintainerElement is not None:
616 | zoneMaintainers = maintainerElement.text
617 | descriptionElement = zoneElement.find('Description')
618 | if descriptionElement is not None:
619 | zoneDescription = descriptionElement.text
620 | commentElement = zoneElement.find('Comment')
621 | if commentElement is not None:
622 | zoneComments = commentElement.text
623 | self.model.addZoneToDatabase(zoneName, zoneMaintainers,
624 | zoneDescription, zoneComments)
625 |
626 | # Import its playlists one by one
627 | for zoneChild in zoneElement.getchildren():
628 | if zoneChild.tag in ['Main', 'Intermediate', 'Fallback']:
629 | self.importPlaylist(zoneName, zoneChild)
630 |
631 | def importPlaylist(self, zoneName, playlistElement):
632 | """
633 | 1) Add playlist to zoneName's inspector.
634 | 2) Add it to the Playlists database.
635 | """
636 | # Parse this playlist element.
637 | # Note that, unlike the zones, it has to be parsed every time it is
638 | # encountered because its configuration settings may differ
639 | # depending on the zone it appears in.
640 | playlist = Playlist()
641 | playlist.type = playlistElement.tag
642 | for playlistChild in playlistElement.getchildren():
643 | if playlistChild.tag == 'Path':
644 | playlist.name = getPlaylistNameFromPath(playlistChild.text)
645 |
646 | # In case it is the first time this playlist is encountered,
647 | # add it to the database.
648 | if not self.model.playlistExistsInDatabase(playlist.name):
649 | self.model.addPlaylistToDatabase(playlistChild.text)
650 |
651 | if playlistChild.tag == 'Shuffle':
652 | playlist.shuffle = (playlistChild.text == 'true')
653 | if playlistChild.tag == 'Fader':
654 | for faderChild in playlistChild.getchildren():
655 | if faderChild.tag == 'FadeInDurationSecs':
656 | playlist.fadeInSecs = faderChild.text
657 | if faderChild.tag == 'FadeOutDurationSecs':
658 | playlist.fadeOutSecs = faderChild.text
659 | if faderChild.tag == 'MinLevel':
660 | playlist.minLevel = faderChild.text
661 | if faderChild.tag == 'MaxLevel':
662 | playlist.maxLevel = faderChild.text
663 | if playlistChild.tag == 'SchedIntervalMins':
664 | playlist.schedIntervalMins = playlistChild.text
665 | if playlistChild.tag == 'NumSchedItems':
666 | playlist.numSchedItems = playlistChild.text
667 | self.model.addPlaylistToZone(zoneName, playlist)
668 |
669 | def exportXML(self, outputXmlPath, updateProgressBar, destroyProgressBar):
670 | """ Export the GUI content to an XML file.
671 |
672 | Use idle_add to make non-blocking requests
673 | for GUI-related operations to the main thread.
674 | """
675 | # Create week element
676 | weekElement = ET.Element('WeekSchedule')
677 |
678 | # Add days to week
679 | for dayIndex, day in enumerate(WEEK):
680 | dayElement = ET.SubElement(weekElement, day[:3])
681 |
682 | # Add zones to day
683 | for scheduleRow in self.model.schedule[dayIndex]:
684 | self.exportZone(scheduleRow, dayElement)
685 | idle_add(updateProgressBar)
686 | sleep(0.1)
687 |
688 | # Remove empty elements
689 | self.clearEmptyElements(weekElement)
690 |
691 | # Download and parse XSD schema
692 | if self.xmlSchema is None:
693 | self.downloadAndParseXSDSchema()
694 | idle_add(updateProgressBar)
695 | sleep(0.1)
696 |
697 | # Validate output XML data against schema
698 | if self.xmlSchema is not None:
699 | print('Validating output XML ...')
700 | failureMessage = 'Export aborted.'
701 | if not self.validateXML(weekElement, failureMessage):
702 | idle_add(destroyProgressBar)
703 | return
704 | else:
705 | print('Validation of output won\'t be performed.')
706 | idle_add(self.view.dialogs.MessagePopup(self.view,
707 | MessageType.WARNING, 'Warning',
708 | 'Validation of output won\'t be performed.').show)
709 | idle_add(updateProgressBar)
710 | sleep(0.1)
711 |
712 | # Output XML data to file
713 | with open(outputXmlPath, 'w') as f:
714 | dom = parseString(ET.tostring(weekElement))
715 | f.write(dom.toprettyxml(indent='\t', encoding='UTF-8').decode())
716 | idle_add(self.view.dialogs.MessagePopup(self.view,
717 | MessageType.INFO, 'Info', 'Export successful.').show)
718 | idle_add(updateProgressBar)
719 | sleep(0.1)
720 | idle_add(destroyProgressBar)
721 |
722 | def exportZone(self, scheduleRow, dayElement):
723 | """
724 | 1) Add scheduleRow's zone with its metadata to dayElement
725 | 2) Export its playlists
726 | """
727 | zoneStartTime = scheduleRow[0]
728 | zoneName = scheduleRow[1]
729 | zoneElement = ET.SubElement(dayElement, 'Zone')
730 | zoneElement.set('Name', zoneName)
731 | zoneElement.set('Start', zoneStartTime + ':00')
732 | zoneRow = self.model.getZoneRow(zoneName)
733 | ET.SubElement(zoneElement, 'Maintainer').text = self.model.zones[zoneRow][2]
734 | ET.SubElement(zoneElement, 'Description').text = self.model.zones[zoneRow][1]
735 | ET.SubElement(zoneElement, 'Comment').text = self.model.zones[zoneRow][3]
736 |
737 | # Add playlists to zone
738 | self.exportPlaylists(zoneName, zoneElement)
739 |
740 | def exportPlaylists(self, zoneName, zoneElement):
741 | """ Add zoneName's playlists to zoneElement """
742 | # Add Main
743 | mainPlaylistRow = self.model.getMainPlaylistRow(zoneName)
744 | if mainPlaylistRow is not None:
745 | playlistElement = ET.SubElement(zoneElement, 'Main')
746 | self.fillPlaylistElement(playlistElement, self.model.zoneInspector[
747 | zoneName][mainPlaylistRow])
748 |
749 | # Add Fallback
750 | fallbackPlaylistRow = self.model.getFallbackPlaylistRow(zoneName)
751 | if fallbackPlaylistRow is not None:
752 | playlistElement = ET.SubElement(zoneElement, 'Fallback')
753 | self.fillPlaylistElement(playlistElement, self.model.zoneInspector[
754 | zoneName][fallbackPlaylistRow])
755 |
756 | # Add Intermediates
757 | for zoneInspectorRow in self.model.zoneInspector[zoneName]:
758 | if zoneInspectorRow[1] == 'Intermediate':
759 | intermediatePlaylistRow = zoneInspectorRow
760 | playlistElement = ET.SubElement(zoneElement, 'Intermediate')
761 | playlistElement.set('Name', intermediatePlaylistRow[0])
762 | self.fillPlaylistElement(playlistElement, intermediatePlaylistRow)
763 |
764 | def downloadAndParseXSDSchema(self):
765 | """ Download XSD schema from the web and parse it.
766 |
767 | In case of download failure, use the hardcoded schema.
768 | In case of parse failure, notify the user.
769 | """
770 | try:
771 | xsdSchemaFile = urlopen(XSD_SCHEMA_URL, timeout=3)
772 | except Exception as e:
773 | print('Failed to download XSD schema.\n' + str(e))
774 | print('Using hardcoded XSD schema ...')
775 | try:
776 | self.xmlSchema = ET.XMLSchema(ET.fromstring(
777 | XSD_SCHEMA_FALLBACK.encode('utf-8')))
778 | except Exception as e:
779 | print('Failed to parse XSD schema.\n' + str(e))
780 | idle_add(self.view.dialogs.MessagePopup(self.view,
781 | MessageType.ERROR, 'Error',
782 | 'Failed to parse XSD schema.', str(e)).show)
783 | else:
784 | print('Got XSD Schema from', XSD_SCHEMA_URL)
785 | try:
786 | self.xmlSchema = ET.XMLSchema(ET.parse(xsdSchemaFile))
787 | except Exception as e:
788 | print('Failed to parse XSD schema.\n' + str(e))
789 | idle_add(self.view.dialogs.MessagePopup(self.view,
790 | MessageType.ERROR, 'Error',
791 | 'Failed to parse XSD schema.', str(e)).show)
792 |
793 | def validateXML(self, rootElement, failureMessage):
794 | """ Validate the contents of rootElement.
795 |
796 | In case of validation failure, notify the user with failureMessage.
797 | """
798 | try:
799 | self.xmlSchema.assertValid(rootElement)
800 | except Exception as e:
801 | print('Validation failed.\n' + str(e))
802 | idle_add(self.view.dialogs.MessagePopup(self.view,
803 | MessageType.ERROR, 'Error', 'Validation failed.',
804 | str(e), failureMessage).show)
805 | return False
806 | else:
807 | print('Validation successful.')
808 | return True
809 |
810 | def fillPlaylistElement(self, playlistElement, zoneInspectorRow):
811 | """ Construct a playlist element from zoneInspectorRow contents. """
812 | playlistRow = self.model.getPlaylistRow(zoneInspectorRow[0])
813 | ET.SubElement(playlistElement, 'Path').text = self.model.playlists[
814 | playlistRow][1]
815 | ET.SubElement(playlistElement, 'Shuffle').text =\
816 | 'true' if zoneInspectorRow[2] else 'false'
817 | faderElement = ET.SubElement(playlistElement, 'Fader')
818 | ET.SubElement(faderElement, 'FadeInDurationSecs').text = zoneInspectorRow[5]
819 | ET.SubElement(faderElement, 'FadeOutDurationSecs').text = zoneInspectorRow[6]
820 | ET.SubElement(faderElement, 'MinLevel').text = zoneInspectorRow[7]
821 | ET.SubElement(faderElement, 'MaxLevel').text = zoneInspectorRow[8]
822 | ET.SubElement(playlistElement, 'SchedIntervalMins').text = zoneInspectorRow[3]
823 | ET.SubElement(playlistElement, 'NumSchedItems').text = zoneInspectorRow[4]
824 |
825 | def clearEmptyElements(self, root):
826 | """ Remove root's empty children. """
827 | context = ET.iterwalk(root)
828 | for _, elem in context:
829 | parent = elem.getparent()
830 | if parent is not None and self.isRecursivelyEmpty(elem):
831 | parent.remove(elem)
832 |
833 | def isRecursivelyEmpty(self, e):
834 | """ Determine whether an element e is recursively empty. """
835 | if e.text is not None and e.text != '':
836 | return False
837 | return all((self.isRecursivelyEmpty(c) for c in e.iterchildren()))
838 |
--------------------------------------------------------------------------------
/src/helpers.py:
--------------------------------------------------------------------------------
1 | """
2 | Helpers
3 |
4 | Copyright (C) 2018 Elias Papavasileiou
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 | """
19 |
20 | from os.path import basename, splitext
21 | from gi.repository.Gtk import ListStore, SortType
22 |
23 |
24 | """ Constants, functions, classes and embedded files that are used throughout the application. """
25 |
26 | # Constants
27 |
28 | APP_TITLE = 'Autopilot Schedule'
29 |
30 | WEEK = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
31 |
32 | XSD_SCHEMA_URL =\
33 | 'https://raw.githubusercontent.com/UoC-Radio/audio-scheduler/master/config_schema.xsd'
34 |
35 |
36 | # Functions
37 |
38 | HOURS = None
39 |
40 | def getHoursModel():
41 | global HOURS
42 | if HOURS is None:
43 | HOURS = ListStore(str)
44 | HOURS.set_sort_column_id(0, SortType.ASCENDING)
45 | for i in range(24):
46 | HOURS.append((str(i).zfill(2) + ':00',))
47 | return HOURS
48 |
49 | def getPlaylistNameFromPath(playlistPath):
50 | return splitext(basename(playlistPath))[0]
51 |
52 | def addPlaylistToZone(playlistName, zoneName, model):
53 | # Add playlist to selected zone as Main playlist.
54 | # If the zone has already a Main playlist, add it as Intermediate.
55 | if not model.zoneHasMainPlaylist(zoneName):
56 | playlist = Playlist(playlistName,
57 | 'Main', True, '', '', '1', '1', '0', '1')
58 | else:
59 | playlist = Playlist(playlistName,
60 | 'Intermediate', True, '30', '1', '1', '1',
61 | '0', '1')
62 | model.addPlaylistToZone(zoneName, playlist)
63 |
64 |
65 | # Classes
66 |
67 | class Playlist:
68 |
69 | def __init__(self, name='', type='', shuffle='', schedIntervalMins='', numSchedItems='',
70 | fadeInSecs='', fadeOutSecs='', minLevel='', maxLevel=''):
71 | self.name = name
72 | self.type = type
73 | self.shuffle = shuffle
74 | self.schedIntervalMins = schedIntervalMins
75 | self.numSchedItems = numSchedItems
76 | self.fadeInSecs = fadeInSecs
77 | self.fadeOutSecs = fadeOutSecs
78 | self.minLevel = minLevel
79 | self.maxLevel = maxLevel
80 |
81 |
82 | # Embedded files
83 |
84 | CSS = """
85 | .button {
86 | background-blend-mode: luminosity;
87 | }
88 |
89 | .button:disabled {
90 | background-color: gray;
91 | }
92 |
93 | .button-minus {
94 | background-color: darkred;
95 | }
96 |
97 | .button-plus {
98 | background-color: darkgreen;
99 | }
100 |
101 | progress, trough {
102 | min-height: 30px;
103 | }
104 | """
105 |
106 | MENU = """
107 |
108 |
120 |
121 | """
122 |
123 | XSD_SCHEMA_FALLBACK = """
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 |
--------------------------------------------------------------------------------
/src/main.py:
--------------------------------------------------------------------------------
1 | """
2 | Main function
3 |
4 | Copyright (C) 2018 Elias Papavasileiou
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 | """
19 |
20 | from controller import Controller
21 |
22 |
23 | if __name__ == '__main__':
24 | """ Start the controller.
25 |
26 | It subclasses Application.
27 | """
28 | Controller().run()
29 |
--------------------------------------------------------------------------------
/src/model.py:
--------------------------------------------------------------------------------
1 | """
2 | The Model
3 |
4 | Copyright (C) 2018 Elias Papavasileiou
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 | """
19 |
20 | from gi.repository.Gtk import ListStore, SortType, TreePath
21 | from helpers import Playlist, getPlaylistNameFromPath
22 |
23 |
24 | class Model:
25 | """ Holds the application's data, as well as operations on them.
26 |
27 | The Model consists of four sub-models that correspond to the four main window parts:
28 | Flow Schedule, Zones, Zone Inspector and Playlists.
29 | """
30 |
31 | def __init__(self):
32 | """ Initialize sub-models.
33 |
34 | Do not initialize the zoneInspector sub-model,
35 | because no zone exists on application startup.
36 | """
37 | # Weekly Schedule Model
38 | self.schedule = {}
39 | for dayIndex in range(7):
40 | self.schedule[dayIndex] = ListStore(str, str)
41 | self.schedule[dayIndex].set_sort_column_id(0, SortType.ASCENDING)
42 |
43 | # Zone Model
44 | self.zones = ListStore(str, str, str, str)
45 | self.zones.set_sort_column_id(0, SortType.ASCENDING)
46 |
47 | # Zone Inspector Model
48 | self.zoneInspector = {}
49 |
50 | # Playlist Model
51 | self.playlists = ListStore(str, str)
52 | self.playlists.set_sort_column_id(0, SortType.ASCENDING)
53 |
54 |
55 | # Public methods
56 |
57 | def addZoneToDatabase(self, zoneName, zoneMaintainers='',
58 | zoneDescription='', zoneComments=''):
59 | """ Add a zone to the database.
60 |
61 | Subsequently, initialize its inspector.
62 | """
63 | self.zones.append((zoneName, zoneDescription, zoneMaintainers, zoneComments))
64 | self.initZoneInspector(zoneName)
65 |
66 | def removeZoneFromDatabase(self, zoneRow):
67 | """
68 | Remove a zone from the database.
69 |
70 | Subsequently, remove every occurrence of it in the Flow Schedule.
71 | Also remove its inspector.
72 | """
73 | zoneName = self.zones[zoneRow][0]
74 | del self.zones[zoneRow]
75 | for dayIndex in range(7):
76 | while True:
77 | scheduleRow = self.getRowOfItemInColumnOfModel(zoneName, 1,
78 | self.schedule[dayIndex])
79 | if scheduleRow is not None:
80 | del self.schedule[dayIndex][scheduleRow]
81 | else:
82 | break
83 | self.zoneInspector[zoneName].clear()
84 | del self.zoneInspector[zoneName]
85 |
86 | def editZoneNameInDatabase(self, oldZoneName, newZoneName):
87 | """ Edit a zone's name in the database.
88 |
89 | Subsequently, rename every occurrence of it in the Flow Schedule.
90 | Also rename its inspector.
91 | """
92 | zoneRow = self.getZoneRow(oldZoneName)
93 | self.zones[zoneRow][0] = newZoneName
94 | for dayIndex in range(7):
95 | while True:
96 | scheduleRow = self.getRowOfItemInColumnOfModel(oldZoneName, 1,
97 | self.schedule[dayIndex])
98 | if scheduleRow is not None:
99 | self.schedule[dayIndex][scheduleRow][1] = newZoneName
100 | else:
101 | break
102 | self.initZoneInspector(newZoneName)
103 | self.zoneInspector[newZoneName] = self.zoneInspector[oldZoneName]
104 | del self.zoneInspector[oldZoneName]
105 |
106 | def addPlaylistToDatabase(self, playlistPath):
107 | """ Add a playlist to the database. """
108 | playlistName = getPlaylistNameFromPath(playlistPath)
109 | self.playlists.append((playlistName, playlistPath))
110 |
111 | def removePlaylistFromDatabase(self, playlistRow):
112 | """ Remove a playlist from the database.
113 |
114 | Subsequently, remove it from every zone in the database.
115 | """
116 | playlistName = self.playlists[playlistRow][0]
117 | del self.playlists[playlistRow]
118 | for zone in self.zones:
119 | zoneName = zone[0]
120 | while True:
121 | zoneInspectorRow = self.getRowOfItemInColumnOfModel(
122 | playlistName, 0, self.zoneInspector[zoneName])
123 | if zoneInspectorRow is not None:
124 | del self.zoneInspector[zoneName][zoneInspectorRow]
125 | else:
126 | break
127 |
128 | def addZoneToSchedule(self, dayIndex, zoneName, zoneStartTime='00:00'):
129 | """ Add zoneName to the day that corresponds to dayIndex in Flow Schedule. """
130 | self.schedule[dayIndex].append((zoneStartTime, zoneName))
131 |
132 | def removeZoneFromSchedule(self, dayIndex, scheduleRow):
133 | """ Remove a zone from the day that corresponds to dayIndex in Flow Schedule. """
134 | del self.schedule[dayIndex][scheduleRow]
135 |
136 | def addPlaylistToZone(self, zoneName, playlist):
137 | """ Add playlist to zoneName. """
138 | self.zoneInspector[zoneName].append((
139 | playlist.name, playlist.type, playlist.shuffle, playlist.schedIntervalMins,
140 | playlist.numSchedItems, playlist.fadeInSecs, playlist.fadeOutSecs,
141 | playlist.minLevel, playlist.maxLevel))
142 |
143 | def removePlaylistFromZone(self, zoneName, zoneInspectorRow):
144 | """ Remove the playlist located in zoneInspectorRow from zoneName. """
145 | del self.zoneInspector[zoneName][zoneInspectorRow]
146 |
147 | def zoneExistsInDatabase(self, zoneName):
148 | """ Return true if zoneName exists in database. """
149 | return self.itemExistsInColumnOfModel(zoneName, 0, self.zones)
150 |
151 | def playlistExistsInDatabase(self, playlistName):
152 | """ Return true if playlistName exists in database. """
153 | return self.itemExistsInColumnOfModel(playlistName, 0, self.playlists)
154 |
155 | def zoneHasMainPlaylist(self, zoneName):
156 | """ Return true if zoneName has a Main playlist. """
157 | return self.itemExistsInColumnOfModel('Main', 1, self.zoneInspector[zoneName])
158 |
159 | def getZoneRow(self, zoneName):
160 | """ Return the zoneName's row in Zones. """
161 | return self.getRowOfItemInColumnOfModel(zoneName, 0, self.zones)
162 |
163 | def getPlaylistRow(self, playlistName):
164 | """ Return the playlistName's row in Playlists. """
165 | return self.getRowOfItemInColumnOfModel(playlistName, 0, self.playlists)
166 |
167 | def getMainPlaylistRow(self, zoneName):
168 | """ Return the Main playlist's row of zoneName in zoneInspector. """
169 | return self.getRowOfItemInColumnOfModel('Main', 1, self.zoneInspector[zoneName])
170 |
171 | def getFallbackPlaylistRow(self, zoneName):
172 | """ Return the Fallback playlist's row of zoneName in zoneInspector. """
173 | return self.getRowOfItemInColumnOfModel('Fallback', 1,
174 | self.zoneInspector[zoneName])
175 |
176 | def attemptToAddDefaultPlaylistsToZone(self, zoneName):
177 | """ Add default playlists to zoneName, if they exist in database. """
178 | if self.playlistExistsInDatabase('fallback'):
179 | playlist = Playlist('fallback', 'Fallback', True, '', '', '2', '2', '0', '1')
180 | self.addPlaylistToZone(zoneName, playlist)
181 | if self.playlistExistsInDatabase('Spots'):
182 | playlist = Playlist('Spots', 'Intermediate', True, '70', '1', '', '', '', '')
183 | self.addPlaylistToZone(zoneName, playlist)
184 | if self.playlistExistsInDatabase('Jingles'):
185 | playlist = Playlist('Jingles', 'Intermediate', True,
186 | '40', '1', '', '', '', '')
187 | self.addPlaylistToZone(zoneName, playlist)
188 |
189 |
190 | # Private methods
191 |
192 | def itemExistsInColumnOfModel(self, item, column, model):
193 | """ If item exists in model's column, return true. """
194 | return any((row[column] == item for row in model))
195 |
196 | def getRowOfItemInColumnOfModel(self, item, column, model):
197 | """ If item exists in model's column, return its row. """
198 | for i in range(len(model)):
199 | treeiter = model.get_iter(TreePath(i))
200 | if model[treeiter][column] == item:
201 | return treeiter
202 | return None
203 |
204 | def initZoneInspector(self, zoneName):
205 | """ Initialize zoneName's inspector. """
206 | self.zoneInspector[zoneName] = ListStore(str, str, bool, str, str,
207 | str, str, str, str)
208 | self.zoneInspector[zoneName].set_sort_column_id(1, SortType.DESCENDING)
209 |
--------------------------------------------------------------------------------
/src/resources/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UoC-Radio/flow-dashboard/bc391efb85d32e439fc21b3c34b108353c98e4c2/src/resources/logo.png
--------------------------------------------------------------------------------
/src/view.py:
--------------------------------------------------------------------------------
1 | """
2 | The View
3 |
4 | Copyright (C) 2018 Elias Papavasileiou
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 | """
19 |
20 | from gi.repository import Gtk, Gdk
21 | from gi.repository.Gio import SimpleAction
22 | from gi.repository.Pango import WrapMode
23 | from helpers import CSS, WEEK
24 |
25 |
26 | class View(Gtk.ApplicationWindow):
27 | """ The application's GUI. """
28 |
29 | def __init__(self, *args, **kwargs):
30 | super().__init__(*args, **kwargs)
31 | # Run initially maximized
32 | self.maximize()
33 |
34 | # Load CSS
35 | style_provider = Gtk.CssProvider()
36 | style_provider.load_from_data(CSS.encode())
37 | Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(), style_provider,
38 | Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
39 |
40 | # Create dialogs and windows objects for controller access
41 | self.dialogs = self.Dialogs()
42 | self.windows = self.Windows()
43 |
44 | def setCallbacks(self, callbacks):
45 | """ Save the callbacks from controller.
46 |
47 | GUI items can then be connected to them.
48 | """
49 | self.callbacks = callbacks
50 |
51 | def activateMenu(self):
52 | """ Connect main menu options to callbacks """
53 | action = SimpleAction.new('import_xml', None)
54 | action.connect('activate', self.callbacks.onImportXMLMenuOptionSelected)
55 | self.add_action(action)
56 | action = SimpleAction.new('export_xml', None)
57 | action.connect('activate', self.callbacks.onExportXMLMenuOptionSelected)
58 | self.add_action(action)
59 |
60 | def initGUI(self):
61 | """ Initialize GUI components. """
62 | self.activateMenu()
63 |
64 | # Create outer grid
65 | self.outerContainer = Gtk.Grid()
66 | self.add(self.outerContainer)
67 |
68 | # Initialize components that sit on top of the outer grid
69 | self.initSchedule()
70 | self.initZones()
71 | self.initZoneInspector()
72 | self.initPlaylists()
73 |
74 | def initSchedule(self):
75 | """ Initialize Flow Schedule. """
76 | # Weekly Schedule Box
77 | self.scheduleBox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
78 | self.outerContainer.attach(self.scheduleBox, left=0, top=0, width=4, height=6)
79 |
80 | # Weekly Schedule HeaderBar
81 | self.scheduleHeaderBar = Gtk.HeaderBar(title='Flow Schedule',
82 | subtitle='Zones that play on air')
83 | self.removeZoneFromScheduleButton = Gtk.Button.new_from_icon_name(
84 | 'list-remove-symbolic',
85 | Gtk.IconSize(Gtk.IconSize.BUTTON))
86 | self.removeZoneFromScheduleButton.get_style_context().add_class('button')
87 | self.removeZoneFromScheduleButton.get_style_context().add_class('button-minus')
88 | self.removeZoneFromScheduleButton.set_tooltip_markup(
89 | 'Remove selected zone from selected day')
90 | self.removeZoneFromScheduleButton.connect(
91 | 'clicked', self.callbacks.onRemoveZoneFromScheduleButtonClicked)
92 | self.removeZoneFromScheduleButton.set_sensitive(False)
93 | self.scheduleHeaderBar.pack_end(self.removeZoneFromScheduleButton)
94 |
95 | # Add zone to schedule button
96 | self.addZoneToScheduleButton = Gtk.Button.new_from_icon_name(
97 | 'list-add-symbolic', Gtk.IconSize(Gtk.IconSize.BUTTON))
98 | self.addZoneToScheduleButton.get_style_context().add_class('button')
99 | self.addZoneToScheduleButton.get_style_context().add_class('button-plus')
100 | self.addZoneToScheduleButton.set_tooltip_markup(
101 | 'Add selected zone to selected day')
102 | self.addZoneToScheduleButton.connect(
103 | 'clicked', self.callbacks.onAddZoneToScheduleButtonClicked)
104 | self.addZoneToScheduleButton.set_sensitive(False)
105 | self.scheduleHeaderBar.pack_end(self.addZoneToScheduleButton)
106 |
107 | self.scheduleBox.add(self.scheduleHeaderBar)
108 |
109 | # Weekly Schedule View
110 | self.scheduleNotebook = Gtk.Notebook(tab_pos=Gtk.PositionType.TOP)
111 | self.scheduleNotebook.connect('switch-page', self.callbacks.onScheduleDaySelected)
112 | self.schedule = {}
113 | for dayIndex in range(7):
114 | self.schedule[dayIndex] = Gtk.TreeView()
115 | self.schedule[dayIndex].get_selection().connect(
116 | 'changed', self.callbacks.onScheduleRowSelected)
117 | for i, columnTitle in enumerate(['Hour', 'Name']):
118 | renderer = Gtk.CellRendererText(editable=True)
119 | renderer.connect('edited',
120 | self.callbacks.onScheduleRowEdited, dayIndex, i)
121 | renderer.connect('editing-started',
122 | self.callbacks.onScheduleRowEditingStarted, i)
123 | column = Gtk.TreeViewColumn(columnTitle, renderer, text=i)
124 | column.set_sort_column_id(i)
125 | self.schedule[dayIndex].append_column(column)
126 | scrollview = Gtk.ScrolledWindow()
127 | scrollview.set_vexpand(True)
128 | scrollview.add(self.schedule[dayIndex])
129 | self.scheduleNotebook.append_page(scrollview, Gtk.Label(WEEK[dayIndex]))
130 | self.scheduleBox.add(self.scheduleNotebook)
131 |
132 | def initZones(self):
133 | """ Initialize Zones. """
134 | # Zone Box
135 | self.zoneBox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, hexpand=True)
136 | self.outerContainer.attach(self.zoneBox, 4, 0, 8, 6)
137 |
138 | # Zone HeaderBar
139 | self.zoneHeaderBar = Gtk.HeaderBar(title='Zones', subtitle='Their database')
140 | self.removeZoneButton = Gtk.Button. new_from_icon_name(
141 | 'list-remove-symbolic', Gtk.IconSize(Gtk.IconSize.BUTTON))
142 | self.removeZoneButton.get_style_context().add_class('button')
143 | self.removeZoneButton.get_style_context().add_class('button-minus')
144 | self.removeZoneButton.set_tooltip_markup('Remove selected zone from database and schedule')
145 | self.removeZoneButton.connect('clicked', self.callbacks.onRemoveZoneButtonClicked)
146 | self.removeZoneButton.set_sensitive(False)
147 | self.zoneHeaderBar.pack_end(self.removeZoneButton)
148 | button = Gtk.Button. new_from_icon_name('list-add-symbolic',
149 | Gtk.IconSize(Gtk.IconSize.BUTTON))
150 | button.get_style_context().add_class('button')
151 | button.get_style_context().add_class('button-plus')
152 | button.set_tooltip_markup('Add a new zone to database')
153 | button.connect('clicked', self.callbacks.onAddZoneButtonClicked)
154 | self.zoneHeaderBar.pack_end(button)
155 | self.zoneBox.add(self.zoneHeaderBar)
156 |
157 | # Zone View
158 | self.zones = Gtk.TreeView()
159 | self.zones.get_selection().connect('changed', self.callbacks.onZoneRowSelected)
160 | columnTitle = 'Name'
161 | renderer = Gtk.CellRendererText(editable=True)
162 | renderer.connect('edited', self.callbacks.onZoneRowEdited, 0)
163 | column = Gtk.TreeViewColumn(columnTitle, renderer, text=0)
164 | column.set_sort_column_id(0)
165 | self.zones.append_column(column)
166 | for i, columnTitle in enumerate(['Description', 'Maintainers', 'Comments']):
167 | renderer = Gtk.CellRendererText(editable=True)
168 | renderer.connect('edited', self.callbacks.onZoneRowEdited, i+1)
169 | renderer.props.wrap_width = 600
170 | renderer.props.wrap_mode = WrapMode.WORD_CHAR
171 | column = Gtk.TreeViewColumn(columnTitle, renderer, text=i+1)
172 | column.set_sort_column_id(i+1)
173 | column.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
174 | column.set_resizable(True)
175 | self.zones.append_column(column)
176 | scrollview = Gtk.ScrolledWindow()
177 | scrollview.set_vexpand(True)
178 | scrollview.add(self.zones)
179 | self.zoneBox.add(scrollview)
180 |
181 | def initZoneInspector(self):
182 | """ Initialize Zone Inspector. """
183 | # Zone Inspector Box
184 | self.zoneInspectorBox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL,
185 | hexpand=True)
186 | self.outerContainer.attach(self.zoneInspectorBox, 4, 6, 8, 6)
187 |
188 | # Zone Inspector HeaderBar
189 | self.zoneInspectorHeaderBar = Gtk.HeaderBar(title='Zone Inspector',
190 | subtitle="Contents of selected zone")
191 | self.removePlaylistFromZoneButton = Gtk.Button.new_from_icon_name(
192 | 'list-remove-symbolic', Gtk.IconSize(Gtk.IconSize.BUTTON))
193 | self.removePlaylistFromZoneButton.get_style_context().add_class('button')
194 | self.removePlaylistFromZoneButton.get_style_context().add_class('button-minus')
195 | self.removePlaylistFromZoneButton.set_tooltip_markup('Remove selected playlist from selected zone')
196 | self.removePlaylistFromZoneButton.connect(
197 | 'clicked', self.callbacks.onRemovePlaylistFromZoneButtonClicked)
198 | self.removePlaylistFromZoneButton.set_sensitive(False)
199 | self.zoneInspectorHeaderBar.pack_end(self.removePlaylistFromZoneButton)
200 |
201 | # Add playlist to zone button
202 | self.addPlaylistToZoneButton = Gtk.Button.new_from_icon_name(
203 | 'list-add-symbolic', Gtk.IconSize(Gtk.IconSize.BUTTON))
204 | self.addPlaylistToZoneButton.get_style_context().add_class('button')
205 | self.addPlaylistToZoneButton.get_style_context().add_class('button-plus')
206 | self.addPlaylistToZoneButton.set_tooltip_markup('Add selected playlist to selected zone')
207 | self.addPlaylistToZoneButton.connect(
208 | 'clicked', self.callbacks.onAddPlaylistToZoneButtonClicked)
209 | self.addPlaylistToZoneButton.set_sensitive(False)
210 | self.zoneInspectorHeaderBar.pack_end(self.addPlaylistToZoneButton)
211 |
212 | self.zoneInspectorBox.add(self.zoneInspectorHeaderBar)
213 |
214 | # Zone Inspector View
215 | self.zoneInspector = Gtk.TreeView()
216 | self.zoneInspector.get_selection().connect(
217 | 'changed', self.callbacks.onZoneInspectorRowSelected)
218 | columnTitle = 'Name'
219 | renderer = Gtk.CellRendererText(editable=True)
220 | renderer.connect('edited', self.callbacks.onZoneInspectorRowEdited, 0)
221 | renderer.connect('editing-started',
222 | self.callbacks.onZoneInspectorRowEditingStarted, 0)
223 | column = Gtk.TreeViewColumn(columnTitle, renderer, text=0)
224 | column.set_sort_column_id(0)
225 | self.zoneInspector.append_column(column)
226 | columnTitle = 'Type'
227 | renderer = Gtk.CellRendererCombo()
228 | renderer.set_property('editable', True)
229 | playlistTypes = Gtk.ListStore(str)
230 | playlistTypes.append(['Main'])
231 | playlistTypes.append(['Intermediate'])
232 | playlistTypes.append(['Fallback'])
233 | renderer.set_property('model', playlistTypes)
234 | renderer.set_property('text-column', 0)
235 | renderer.set_property('has-entry', False)
236 | renderer.connect('edited', self.callbacks.onPlaylistTypeChanged)
237 | column = Gtk.TreeViewColumn(columnTitle, renderer, text=1)
238 | column.set_sort_column_id(1)
239 | self.zoneInspector.append_column(column)
240 | columnTitle = 'Shuffle'
241 | renderer = Gtk.CellRendererToggle()
242 | renderer.connect('toggled', self.callbacks.onShuffleToggled, 2)
243 | column = Gtk.TreeViewColumn(columnTitle, renderer, active=2)
244 | column.set_sort_column_id(2)
245 | self.zoneInspector.append_column(column)
246 | for i, columnTitle in enumerate([
247 | 'SchedIntervalMins', 'NumSchedItems', 'FadeInSecs', 'FadeOutSecs', 'MinLevel',
248 | 'MaxLevel']):
249 | renderer = Gtk.CellRendererText(editable=True)
250 | renderer.connect('edited', self.callbacks.onZoneInspectorRowEdited, i+3)
251 | column = Gtk.TreeViewColumn(columnTitle, renderer, text=i+3)
252 | column.set_sort_column_id(i+3)
253 | self.zoneInspector.append_column(column)
254 | scrollview = Gtk.ScrolledWindow()
255 | scrollview.set_vexpand(True)
256 | scrollview.add(self.zoneInspector)
257 | self.zoneInspectorBox.add(scrollview)
258 |
259 | def initPlaylists(self):
260 | """ Initialize Playlists. """
261 | # Playlist Box
262 | self.playlistBox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
263 | self.outerContainer.attach(self.playlistBox, 0, 6, 4, 6)
264 |
265 | # Playlist HeaderBar
266 | self.playlistHeaderBar = Gtk.HeaderBar(title='Playlists',
267 | subtitle='Their database')
268 | self.removePlaylistButton = Gtk.Button. new_from_icon_name(
269 | 'list-remove-symbolic', Gtk.IconSize(Gtk.IconSize.BUTTON))
270 | self.removePlaylistButton.get_style_context().add_class('button')
271 | self.removePlaylistButton.get_style_context().add_class('button-minus')
272 | self.removePlaylistButton.set_tooltip_markup(
273 | 'Remove selected playlist from database and schedule')
274 | self.removePlaylistButton.connect('clicked',
275 | self.callbacks.onRemovePlaylistButtonClicked)
276 | self.removePlaylistButton.set_sensitive(False)
277 | self.playlistHeaderBar.pack_end(self.removePlaylistButton)
278 | button = Gtk.Button. new_from_icon_name('list-add-symbolic',
279 | Gtk.IconSize(Gtk.IconSize.BUTTON))
280 | button.get_style_context().add_class('button')
281 | button.get_style_context().add_class('button-plus')
282 | button.set_tooltip_markup('Add a new playlist to database')
283 | button.connect('clicked', self.callbacks.onAddPlaylistButtonClicked)
284 | self.playlistHeaderBar.pack_end(button)
285 | self.playlistBox.add(self.playlistHeaderBar)
286 |
287 | # Playlist View
288 | self.playlists = Gtk.TreeView()
289 | self.playlists.get_selection().connect('changed',
290 | self.callbacks.onPlaylistRowSelected)
291 | for i, columnTitle in enumerate(['Name', 'Path']):
292 | renderer = Gtk.CellRendererText()
293 | column = Gtk.TreeViewColumn(columnTitle, renderer, text=i)
294 | column.set_sort_column_id(i)
295 | self.playlists.append_column(column)
296 | scrollview = Gtk.ScrolledWindow()
297 | scrollview.set_vexpand(True)
298 | scrollview.add(self.playlists)
299 | self.playlistBox.add(scrollview)
300 |
301 |
302 | class Dialogs:
303 | """ All the dialogs that might be displayed. """
304 |
305 | class MessagePopup(Gtk.MessageDialog):
306 |
307 | def __init__(self, parent, type, title, message, details='', consequence=''):
308 | Gtk.MessageDialog.__init__(self, parent=parent, flags=0,
309 | type=type, buttons=Gtk.ButtonsType.OK,
310 | message_format=title)
311 | self.format_secondary_text(message)
312 | messageArea = self.get_message_area()
313 | if details != '':
314 | messageArea.add(Gtk.Label(details))
315 | if consequence != '':
316 | messageArea.add(Gtk.Label(consequence))
317 | messageArea.show_all()
318 |
319 | def show(self):
320 | self.run()
321 | self.destroy()
322 |
323 |
324 | class AddZone(Gtk.Dialog):
325 |
326 | def __init__(self, parent, entry):
327 | Gtk.Dialog.__init__(self, title='Add zone',
328 | transient_for=parent, modal=True)
329 | self.set_default_size(150, 100)
330 | self.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
331 | okButton = self.add_button(Gtk.STOCK_OK, Gtk.ResponseType.OK)
332 | okButton.set_can_default(True)
333 | okButton.grab_default()
334 | label = Gtk.Label('Enter zone\'s name:')
335 | entry.set_activates_default(True)
336 | box = self.get_content_area()
337 | box.add(label)
338 | box.add(entry)
339 | self.show_all()
340 |
341 |
342 | class AddPlaylist(Gtk.FileChooserDialog):
343 |
344 | def __init__(self, parent):
345 | Gtk.FileChooserDialog.__init__(self, title='Choose a playlist file',
346 | transient_for=parent, modal=True,
347 | select_multiple=True,
348 | action=Gtk.FileChooserAction.OPEN)
349 | plsFilter = Gtk.FileFilter()
350 | plsFilter.set_name('Playlist files')
351 | plsFilter.add_pattern('*.pls')
352 | plsFilter.add_pattern('*.m3u')
353 | self.add_filter(plsFilter)
354 | allFilter = Gtk.FileFilter()
355 | allFilter.set_name('All files')
356 | allFilter.add_pattern('*')
357 | self.add_filter(allFilter)
358 | self.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
359 | self.add_button(Gtk.STOCK_OPEN, Gtk.ResponseType.OK)
360 |
361 |
362 | class ImportXML(Gtk.FileChooserDialog):
363 |
364 | def __init__(self, parent):
365 | Gtk.FileChooserDialog.__init__(self, title='Choose an XML file',
366 | transient_for=parent, modal=True,
367 | action=Gtk.FileChooserAction.OPEN)
368 | xmlFilter = Gtk.FileFilter()
369 | xmlFilter.set_name('XML files')
370 | xmlFilter.add_pattern('*.xml')
371 | self.add_filter(xmlFilter)
372 | allFilter = Gtk.FileFilter()
373 | allFilter.set_name('All files')
374 | allFilter.add_pattern('*')
375 | self.add_filter(allFilter)
376 | self.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
377 | self.add_button('Import', Gtk.ResponseType.OK)
378 |
379 |
380 | class ExportXML(Gtk.FileChooserDialog):
381 |
382 | def __init__(self, parent):
383 | Gtk.FileChooserDialog.__init__(
384 | self, title='Choose a file name for the new XML schedule',
385 | transient_for=parent, modal=True, action=Gtk.FileChooserAction.SAVE)
386 | self.set_do_overwrite_confirmation(True)
387 | xmlFilter = Gtk.FileFilter()
388 | xmlFilter.set_name('XML files')
389 | xmlFilter.add_pattern('*.xml')
390 | self.add_filter(xmlFilter)
391 | allFilter = Gtk.FileFilter()
392 | allFilter.set_name('All files')
393 | allFilter.add_pattern('*')
394 | self.add_filter(allFilter)
395 | self.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
396 | self.add_button('Export', Gtk.ResponseType.OK)
397 |
398 |
399 | class Windows:
400 | """ All the windows that might be displayed, apart from the main window. """
401 |
402 | class ProgressBar(Gtk.Window):
403 |
404 | def __init__(self, parent, title):
405 | Gtk.Window.__init__(self, title=title, transient_for=parent,
406 | modal=True, resizable=False,
407 | window_position=Gtk.WindowPosition.CENTER_ON_PARENT)
408 | self.set_border_width(10)
409 | self.set_default_size(300, 40)
410 | self.progressBar = Gtk.ProgressBar(show_text=True)
411 | self.add(self.progressBar)
412 |
413 | # Updates the progress bar value
414 | def update(self):
415 | newValue = self.progressBar.get_fraction() + 0.1
416 | self.progressBar.set_fraction(newValue)
417 |
--------------------------------------------------------------------------------